Closes #1 - Converted Octave code into matlab code.
This commit is contained in:
50
matlab/findFalseDetectedPeaks.m
Normal file
50
matlab/findFalseDetectedPeaks.m
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
%TODO: Find false detected peaks. This could be a not detected or an additional detected peak. Simple algorithm:
|
||||
% 1) Choose smallest diff(peaks) value smallest_peak (e.g. 48, 97, 49, [45], ..)
|
||||
% 2) Divide all diff_peaks values with smallest_peak to get factor_peaks (e.g. 1.1, 1.8, 1.2, 1, ..) and to whole numbers (e.g. 1, [2], 1, 1, ..)
|
||||
% 3) Divide diff_peaks / factor_peaks and split (e.g. 48, [48.5, 48.5], 49, 45, ..) diff_peaks_new
|
||||
% 4) Start at first peak and cumsum the correlation values at the lag positions given by diff_peaks_new to sum_peaks_new and sum_peaks for diff_peaks
|
||||
% 5) If sum_diff_new > sum_diff finish, else remove smallest_peak from diff(peaks) and goto 1)
|
||||
function idx = findFalseDetectedPeaks(idx_orig, lag_orig, corr_orig)
|
||||
|
||||
idx = idx_orig;
|
||||
while 1
|
||||
%1
|
||||
diff_peaks = diff(lag_orig(idx_orig));
|
||||
[smallest_peak, smallest_peak_idx] = min(diff_peaks);
|
||||
|
||||
%2
|
||||
factor_peaks = round(diff_peaks / smallest_peak);
|
||||
|
||||
%3
|
||||
%factor_matrix = [1:length(factor_peaks); factor_peaks]; %we need this since octave doesn't have a repelem only repelemS.
|
||||
%diff_peaks_new = repelems(diff_peaks ./ factor_peaks, factor_matrix);
|
||||
diff_peaks_new = repelem(diff_peaks ./ factor_peaks, factor_peaks);
|
||||
|
||||
%4
|
||||
idx_new = round([idx_orig(1), cumsum(diff_peaks_new) + idx_orig(1)]');
|
||||
sum_peaks_new = sum(corr_orig(idx_new));
|
||||
sum_peaks = sum(corr_orig(idx_orig));
|
||||
|
||||
%5
|
||||
if(sum_peaks_new < sum_peaks)
|
||||
% TODO: idx + 1 is not always the correct one. if diff is very
|
||||
% small, the false peak could be left or right from the real peak.
|
||||
% Solution: Remove peak with lowest correlation value in
|
||||
% this area
|
||||
if(corr_orig(idx_orig(smallest_peak_idx)) > corr_orig(idx_orig(smallest_peak_idx + 1)))
|
||||
idx_orig(smallest_peak_idx + 1) = [];
|
||||
else
|
||||
idx_orig(smallest_peak_idx) = [];
|
||||
end
|
||||
|
||||
else
|
||||
idx = idx_new;
|
||||
end
|
||||
|
||||
if (sum_peaks_new >= sum_peaks || length(idx_orig) <= 1)
|
||||
break;
|
||||
end
|
||||
%TODO: Warning: could this be an infinite loop?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user