필터 지우기
필터 지우기

full width of a peak

조회 수: 2 (최근 30일)
Mahsa Rm
Mahsa Rm 2021년 8월 7일
댓글: Martina Khunova 2023년 4월 23일
Hi, I have an eog signal which I want to know the duration of its blinks. I want to obtain starting and ending point of a peak , I have used findpeaks function but it gives halfheight width. how can I find full durations?
any help would be appreciated.

채택된 답변

Image Analyst
Image Analyst 2021년 8월 7일
Try this:
% Find both sides of a peak.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
%==================================================================================
% % Mahsa forgot to upload data so I'm forced
% to try to recreate it from the image.
rgbImage = imread('image.png');
imshow(rgbImage)
axis on
grayImage = rgb2gray(rgbImage);
imshow(grayImage);
impixelinfo
mask = grayImage == 255;
props = regionprops(mask, 'BoundingBox');
% Shrink by 8 to get away from tick marks.
bb = props.BoundingBox
bb(1) = bb(1) + 8;
bb(2) = bb(2) + 8;
bb(3) = bb(3) - 16;
bb(4) = bb(4) - 16;
grayImage = imcrop(grayImage, bb);
imshow(grayImage);
[rows, columns] = size(grayImage);
y = zeros(columns, 1);
for col = 1 : columns
t = find(grayImage(:, col) < 255, 1, 'first');
if ~isempty(t)
y(col) = rows - t;
end
end
figure
x = linspace(2.54e5, 2.69e5, length(y));
% Scale y to -50 to +275
y = rescale(y, -50, 275);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
%==================================================================================
% Now we have our data and can begin.
[peakValues, indexesOfPeaks] = findpeaks(y, 'MinPeakHeight', 15);
numPeaks = length(peakValues);
peakLeft = ones(1, numPeaks);
peakRight = ones(1, numPeaks);
% Find valley to the left of the peak
hold on;
for k = 1 : numPeaks
plot(x(indexesOfPeaks(k)), y(indexesOfPeaks(k)), 'r+', 'LineWidth', 2, 'MarkerSize', 20);
for k2 = indexesOfPeaks(k) : -1 : 1
if y(k2) > y(k2+1)
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)-1
if y(k2+1) > y(k2)
break;
end
end
peakRight(k) = k2;
end
% If you want locations in terms of x instead of indexes:
xLeft = x(peakLeft);
xRight = x(peakRight);
% Plot red lines on the left and red lines on the right.
for k = 1 : length(xLeft)
xline(xLeft(k), 'Color', 'g', 'LineWidth', 3);
xline(xRight(k), 'Color', 'r', 'LineWidth', 3);
end
  댓글 수: 1
Martina Khunova
Martina Khunova 2023년 4월 23일
Hello Image Analyst, I have similar issue.
Can you please take a look at this?
Thank you :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 8월 7일
Have you tried just locating the peaks, and then "falling down" the slope on each side until the signal turns around? This would work for smooth peaks but not those that had lots of little tiny "shoulder peaks" on the main peak, but I don't see any of those in your signal.
Attaching your signal in a .mat file would have been helpful, but you forgot.
  댓글 수: 2
Mahsa Rm
Mahsa Rm 2021년 8월 7일
Thanks for responding, I tried to attach my data but it seems to be a problem cause it won't be uploaded in site.
Can you explan more about that falling down the slope untill signal turns round, maybe with an example because I didn't understand how to do it.
Image Analyst
Image Analyst 2021년 8월 7일
편집: Image Analyst 2021년 8월 7일
Enclose your file in a .zip file and attach it with the paperclip icon. Something like (untested)
[peakValues, indexesOfPeaks] = findpeaks(y);
numPeaks = length(peakValues);
peakLeft = ones(1, numPeaks);
peakRight = ones(1, numPeaks);
% Find valley to the left of the peak
for k = 1 : numPeaks
for k2 = indexesOfPeaks(k) : -1 : 1
if y(k2) > y(k2+1)
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
Now you have arrays giving the left and right indexes of the peaks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by