measuring duration of peaks

2 ビュー (過去 30 日間)
Martina Khunova
Martina Khunova 2023 年 4 月 23 日
コメント済み: Martina Khunova 2023 年 4 月 24 日
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));

採用された回答

Image Analyst
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
  1 件のコメント
Martina Khunova
Martina Khunova 2023 年 4 月 24 日
This works, thank you so much

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by