How do I get a maximum and minimum for a singular wave while ignoring the other local maximums and minimums?
2 views (last 30 days)
Show older comments
Andrew Mosqueda
on 10 Oct 2022
Answered: Star Strider
on 10 Oct 2022
I have wave data from a buoy and am trying to identify the overall crest and trough amplitude for 50 individual waves. However, when using islocalmax/min it identifies all the locals and not the highest absolute value. I tried using minprominence but the amount of data points for each crest and trough is inconsistent. The section of code I'm using is below(original data file is .dat extension so I converted to .txt to upload here).
filedata=load('waves_n_130.dat');
A= filedata(:,4);
for n=1:8191
wmin=islocalmin(A,'MinProminence',0);
wmax=islocalmax(A,'MinProminence',0);
end
0 Comments
Accepted Answer
Star Strider
on 10 Oct 2022
LvPks = islocalmax(y, 'MinProminence',0.01, 'MinSeparation',45); % 'islocalmax'
plocs = find(LvPks);
pks = y(plocs);
[maxpk,ploc] = max(pks)
This returned:
maxpk = 0.2899
ploc = 79
and:
[mintr,tloc] = min(trs)
returned:
mintr = -0.3222
tloc = 77
And this:
Pk_Tr_Amp = pks(1:end-1)-trs;
[maxamp,loc] = max(Pk_Tr_Amp)
returned:
maxamp = 0.5668
loc = 77
Just add those lines (and perhaps others) to my code to get the results you want.
NOTE — There is one more peak than trough, and the vector lengths must be equal in order to compare them.
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Axis Labels 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!