Filter data series on amplitude as a function of time

Dear,
Along with greeting, I need to filter a time series, specifically I need to obtain the maximum peak (maximum amplitude that is on the vertical axis), and calculate the time difference (plotted on the horizontal axis) between this peak and the previous peak, in addition to obtain the time difference between the maximum peak and the next peak.
Beforehand thank you very much.
I am attaching code that I have in the meantime and file with the data.
close all, clear all, clc
data=load('data.txt');
t=0:10:4*3600;
plot(t,data)
xlabel('Time (s)')
ylabel('Amplitude (m)')
grid on

 Réponse acceptée

Try this —
s = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/632075/data.txt');
t = linspace(0,numel(s),numel(s));
[maxpk,idx] = max(s)
maxpk = 7.7414
idx = 314
[pks,locs] = findpeaks(s, 'MinPeakProminence',0.05);
didx = idx - locs; % Index Difference
dt = t(idx) - t(locs); % Time Difference
figure
plot(t,s)
hold on
plot(t(locs), pks, '^r')
hold off
grid
PeakTable = table(t(locs).',pks(:),locs(:),didx(:),dt(:), 'VariableNames',{'Time','Peak_Amplitude','Location_Indices','Index_Differences','Time_Differences'})
PeakTable = 40×5 table
Time Peak_Amplitude Location_Indices Index_Differences Time_Differences ______ ______________ ________________ _________________ ________________ 143.1 7.1592 144 170 170.12 149.1 7.2444 150 164 164.11 302.21 7.0417 303 11 11.008 313.22 7.7414 314 0 0 320.22 6.4249 321 -7 -7.0049 439.3 0.23134 440 -126 -126.09 451.31 7.2826 452 -138 -138.1 456.32 7.2931 457 -143 -143.1 461.32 6.8597 462 -148 -148.1 468.32 7.6384 469 -155 -155.11 471.33 7.1554 472 -158 -158.11 491.34 7.0425 492 -178 -178.12 506.35 6.2797 507 -193 -193.13 510.35 6.4715 511 -197 -197.14 573.4 -0.52506 574 -260 -260.18 664.46 -1.5985 665 -351 -351.24
.

6 commentaires

ibt
ibt le 27 Mai 2021
@Star Strider Dear, first thank you for your cooperation. Also indicate that the findpeaks function does not work for me, since I have matlab 2014a, what I need to be more specific is to identify the largest peak (the greatest amplitude) and calculate the time difference (time delta) with respect to the previous peak and later, for which I attach an explanatory image. If you could please help me, thanks in advance.
The findpeaks function will work in R2014a, although it may require a different argument list.
This should do what you want —
s = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/632075/data.txt');
t = linspace(0,numel(s),numel(s));
[maxpk,idx] = max(s)
maxpk = 7.7414
idx = 314
[pks,locs] = findpeaks(s, 'MinPeakProminence',5, 'NPeaks',3);
didx = locs - idx; % Index Difference
dt = t(locs) - t(idx); % Time Difference
figure
plot(t,s)
hold on
plot(t(locs), pks, '^r')
hold off
grid
PeakTable = table(t(locs).',pks(:),locs(:),didx(:),dt(:), 'VariableNames',{'Time','Peak_Amplitude','Location_Indices','Index_Differences','Time_Differences'})
PeakTable = 3×5 table
Time Peak_Amplitude Location_Indices Index_Differences Time_Differences ______ ______________ ________________ _________________ ________________ 149.1 7.2444 150 -164 -164.11 313.22 7.7414 314 0 0 468.32 7.6384 469 155 155.11
.
ibt
ibt le 27 Mai 2021
Dear the part that throws me an error is 'MinPeak Prominence', it is not recognized by matlab, I am attaching a message.
I was in the process of respoinding to this when my desktop computer crashed to update some software. I have no idea why it could instead just notify me and allow me to update it later.
That aside, since the onlline documentation no longer includes R2014a, I do not have access to that version of findpeaks, so I suggest instead using 'MinPeakDistance' and 'MinPeakHeight'.
s = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/632075/data.txt');
t = linspace(0,numel(s),numel(s));
[maxpk,idx] = max(s)
maxpk = 7.7414
idx = 314
[pks,locs] = findpeaks(s, 'MinPeakDistance',100, 'MinPeakHeight',4.5, 'NPeaks',3);
didx = locs - idx; % Index Difference
dt = t(locs) - t(idx); % Time Difference
figure
plot(t,s)
hold on
plot(t(locs), pks, '^r')
hold off
grid
PeakTable = table(t(locs).',pks(:),locs(:),didx(:),dt(:), 'VariableNames',{'Time','Peak_Amplitude','Location_Indices','Index_Differences','Time_Differences'})
PeakTable = 3×5 table
Time Peak_Amplitude Location_Indices Index_Differences Time_Differences ______ ______________ ________________ _________________ ________________ 149.1 7.2444 150 -164 -164.11 313.22 7.7414 314 0 0 468.32 7.6384 469 155 155.11
Without access to the R2014a documentation, this is the best I can do. It may be necessary to experiment if these options also fail.
.
ibt
ibt le 28 Mai 2021
Dear, thank you, this code works for me. My query, how can I always make sure that among the 3 selected peaks, the one with the highest peak is in the center of the 3, since I have to vary the data, and I am interested that the maximum amplitude is always the central value, I stay tuned Regards.
‘... how can I always make sure that among the 3 selected peaks, the one with the highest peak is in the center of the 3 ...’
I am not certain that is possible. However I do not know what you are doing, so it may not be a problem.
In any event, if the three highest peaks are in roughly the same positions, it might be best to consider (or simply define) the centre peak the reference regardless of its relative amplitude, and just use it that way.
.

Connectez-vous pour commenter.

Plus de réponses (1)

ibt
ibt le 28 Mai 2021

0 votes

"... it would be better to consider (or just define) the central peak as a reference, regardless of its relative amplitude, and use it that way."
This as it would be programmed, or as it would look like in a code to be able to execute it, thanks.

1 commentaire

Either way.
If the centre peak is always the highest, use it as such. If it as not, use it as the reference anyway.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Measurements and Feature Extraction dans Centre d'aide et File Exchange

Produits

Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by