measuring duration of peaks
6 次查看(过去 30 天)
显示 更早的评论
Hello, I have an biological signal which I want to know the duration of its peaks. I have tried detecting the peaks and then running down the slope until it turns around. The problem is that index of left side is equal to peak index (shown in the pictures). Do you have any ideas how to solve this?
Thank you :)
this is my code:
[peakValues, indexesOfPeaks] = findpeaks(y,'MinPeakHeight',1.8e6);
numPeaks = length(peakValues);
peakLeft = ones(1, numPeaks);
peakRight = ones(1, numPeaks);
figure(1);
plot(y(:,1), 'b-', 'LineWidth', 1);
hold on;
scatter(indexesOfPeaks, peakValues, 'or');
grid on;
% Find valley to the left of the peak
hold on;
for k = 1 : numPeaks
for k2 = indexesOfPeaks(k) : -1 :1
if y(k2+1) < y(k2)
break;
end
end
peakLeft(k) = k2;
end
% Find valley to the right of the peak
for k = 1 : numPeaks
for k2 = indexesOfPeaks(k) : length(y)
if y(k2+1) > y(k2)
break;
end
end
peakRight(k) = k2;
end
% Plot red lines on the left and red lines on the right.
for k = 1 : length(peakLeft)
xline(peakRight, 'Color', '#52FFF6', 'LineWidth', 1);
xline(peakLeft, 'Color', '#FFA5A5', 'LineWidth', 1);
end
this is signal filtration I use:
y_bp = bandpass(signal,[10 21],fs);
y2 = y_bp.^2;
Lich_vz=round(100*fs/2200);
b2=fir1(Lich_vz, 3/(fs/2), 'low');
y=filtfilt(b2,a,double(y2));
0 个评论
采纳的回答
Image Analyst
2023-4-23
Try
% Find valley to the left of the peak
hold on;
for k = 1 : numPeaks
% Start just to the left of the peak by one index.
startingIndex = indexesOfPeaks(k) - 1;
for k2 = startingIndex : -1 :1
if y(k2-1) > y(k2)
% The signal turned around and started heading back up.
break;
end
end
peakLeft(k) = k2;
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!