Find peaks/valleys of a noisy signal
Show older comments
I have this signal which is noisy as well as it has too much data samples. When I try to find the peaks or valleys, it gives multiple peaks/valleys around the same point probably because the data is noisy and has too many samples. I did use the 'MinPeakDistance' and also tried using the 'MinPeakHeight' and also the 'Threshold' but all time I get many peaks's around a given time instant. In other words, I would want only one peak at the peak of the signal and one valley at the trough of the signal. I have the data attached to the post too. Thanks in advance.
It is just a two column data and I plot the 2nd column wrt 1st one. I would prefer to measure valleys and I would actually need both.
[pks locs] = findpeaks(data_compact(:,2),'MinPeakHeight',0.992*max(data_compact(:,2)),'MinPeakDistance',5000e-3); % peaks
data_inverted(:,1) = data_compact(:,1);
data_inverted(:,2) = -data_compact(:,2);
%[valley valleys_locs] = findpeaks(data_inverted(:,2),'MinPeakDistance',0.2e-3); % valleys

7 Comments
Paul Hoffrichter
on 18 Dec 2020
I think the .mat file does not match the figure.
Image Analyst
on 18 Dec 2020
Edited: Image Analyst
on 18 Dec 2020
I think he just included a small subset of the data.
s = load('data_compact.mat')
data_compact = s.data_modified;
% Smooth with a savitzky-golay filter
% data_compact(:, 2) = sgolayfilt(data_compact(:, 2), 2, 151);
plot(data_compact(:,1), data_compact(:,2), 'b-');
grid on;
[pks, locs] = findpeaks(data_compact(:,2),'MinPeakHeight',0.992*max(data_compact(:,2)),'MinPeakDistance',5000e-3); % peaks
hold on;
plot(data_compact(locs, 1), pks, 'r.', 'MarkerSize', 10);
% Find Valleys
data_inverted(:,1) = data_compact(:,1);
data_inverted(:,2) = -data_compact(:,2);
% [valleyValues valleysIndexes] = findpeaks(data_inverted(:,2),'MinPeakDistance',0.2e-3); % valleys
% plot(data_inverted(valleysIndexes, 1), -valleyValues, 'r.', 'MarkerSize', 10);

Jay Vaidya
on 18 Dec 2020
Jay Vaidya
on 18 Dec 2020
Walter Roberson
on 18 Dec 2020
The data is part of the question; the question does not make sense without the data.
Jay Vaidya
on 18 Dec 2020
Edited: Jay Vaidya
on 18 Dec 2020
Walter Roberson
on 18 Dec 2020
No-one knows what your data means, or who or what it was created from. It is therefore difficult to "misuse".
Accepted Answer
More Answers (1)
Image Analyst
on 18 Dec 2020
0 votes
If there is noise on your peaks, have you tried sgolayfilt() with order 2 or 3? It's in the Signal Processing Toolbox.
1 Comment
Jay Vaidya
on 18 Dec 2020
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!