Find peaks in data without using signal processing tool

104 views (last 30 days)
Hello Guys,
I am working on a set of data, attached.
I am using MatlabR2021b, I don't have signal processing tool. Therefore can't use peak function.
I need to find:
  1. Total number of peaks in data
  2. What are the corresponding values of eack peak
Would appreciate if anyone can suggest a solution.
Please let me know if my question is not clear.
Thanks

Accepted Answer

Star Strider
Star Strider on 8 Jul 2022
The findpeaks function is in the Signal Processing Toolbox, and since you do not have access to it, use the core MATLAB islocalmax function instead (introduced in R2017b) —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1059360/peaktest.xlsx', 'VariableNamingRule','preserve');
Time = T1.Time;
spike2 = T1.spike2;
Lv = islocalmax(spike2, 'MinProminence',1); % Choose The Name-Value Pair Arguments To Return The Peaks You Want
TotalNrOfPeaks = nnz(Lv)
TotalNrOfPeaks = 8
PeakTable = table(Time(Lv),spike2(Lv), 'VariableNames',{'Spike2Time','Spike2Amplitude'})
PeakTable = 8×2 table
Spike2Time Spike2Amplitude __________ _______________ 8 105 11 111 16 111 23 120 38 133 46 111 92 105 96 106
figure
plot(Time, spike2)
hold on
plot(Time(Lv), spike2(Lv), '^r')
hold off
grid
.

More Answers (1)

Sam Chak
Sam Chak on 8 Jul 2022
If the data is not too large, you can test features of the findpeaks() function in this forum.
Else, you can find some peakfinder algorithms in FileExchange.
[data] = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1059360/peaktest.xlsx');
plot(data.Time, data.spike2)
[pks, locs] = findpeaks(data.spike2)
pks = 8×1
105 111 111 120 133 111 105 106
locs = 8×1
8 11 16 23 38 46 92 96
num_of_pks = length(pks)
num_of_pks = 8
  1 Comment
Harsimran Singh
Harsimran Singh on 11 Jul 2022
Thanks Sam, for sugesstion, Peak function/signal processing tool does not works for MatlabR2021b..

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!