以下代码将找到两个突出峰之间的最低点。
%Smoothing the data
movAvgFiltOrder = 8;
b = filter(ones(1,movAvgFiltOrder)/movAvgFiltOrder,1,sums);
% finding peaks from the smoothed curve
[vals,pos] = findpeaks(b);
idx = find(vals>mean([min(vals),max(vals)])); % removing peaks which are below the average,
%this is helpfull if some lower amplitude peaks are caught at sides of the prominent peaks.
peak_pos1 = pos(idx(1)); % farthest prominent peak on one side of valley
peak_pos2 = pos(idx(end)); % farthest prominent peak on other side of valley
% correcting the peak positions for filter delay (Coarse tuning)
peak_pos1 = peak_pos1 - movAvgFiltOrder/2;
peak_pos2 = peak_pos2 - movAvgFiltOrder/2;
% Looking for any other peaks nearby (Fine Tuning)
tuning_range = min(movAvgFiltOrder,floor(abs((peak_pos2-peak_pos1-1)/2)));
p1 = peak_pos1-tuning_range:peak_pos1+tuning_range;
p2 = peak_pos2-tuning_range:peak_pos2+tuning_range;
[~,r1] = max(sums(p1));
[~,r2] = max(sums(p2));
peak_pos1 = p1(r1);
peak_pos2 = p2(r2);
% Identifying valley
valley = sums(peak_pos1:peak_pos2);
% finding minimum point in valley
[min_val,pos_min_val] = min(valley);
valley_amplitude = min_val; % amplitude of minimum point
valley_position = peak_pos1+pos_min_val-1; % finding the valley point in the entire array
这个 valley_position 将给出主峰之间的最低点的位置。