Ref. #2 - Added detection for false or not detected peaks
This commit is contained in:
38
octave/findFalseDetectedPeaks.m
Normal file
38
octave/findFalseDetectedPeaks.m
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
%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;
|
||||
do
|
||||
%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);
|
||||
|
||||
%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)
|
||||
idx_orig(smallest_peak_idx + 1) = [];
|
||||
else
|
||||
idx = idx_new;
|
||||
endif
|
||||
|
||||
until (sum_peaks_new < sum_peaks || length(idx_orig) > 1)
|
||||
%TODO: Warning: could this be an infinite loop?
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user