# Peak to peak amplitude

15 Ansichten (letzte 30 Tage)
Marc Elmeua am 21 Jan. 2023
Kommentiert: Star Strider am 21 Jan. 2023
I have registered an oscillating angle and I need to calculate the range of movement of such angle. The signal looks like this:
I would like to calculate individually the amplitude between a peak and the following valley, I have tried several functions and transforms (hilbert, fourier...) but I am not sure if it is the ideal solution mathematically speaking. I am looking for a simpler, point-to-point calculation. Also, some peaks are "twin peaks" and I would like to ignore such events without filtering the data. I have attached a sample part of my data.
Any ideas,
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Star Strider am 21 Jan. 2023
Data = LD.MATLAB_question
Data = 17558×2
1.0e+06 * 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000 1.0226 0.0000
x = Data(:,1);
y = Data(:,2);
[pks,plocs] = findpeaks(y, 'MinPeakProminence',8, 'MinPeakDistance',100);
[vys,vlocs] = findpeaks(-y, 'MinPeakProminence',7, 'MinPeakDistance',100);
vlocs = vlocs(vlocs > plocs(1));
P_P = pks - vys;
pvlocs = round(mean([vlocs plocs],2));
figure
plot(x, y, 'DisplayName','Data')
hold on
plot(x(plocs), pks, '^r', 'DisplayName','Peaks')
plot(x(vlocs), -vys, 'vr', 'DisplayName','Valleys')
plot(x(pvlocs), P_P, '.-m', 'DisplayName','P-P')
hold off
grid
legend('Location','best')
xlim([min(x) max(x)])
PksVysPP = table(x(plocs), pks, x(vlocs), vys, P_P, 'VariableNames',{'X Peak Location','Peaks','X Valley Location','Valleys','P-P'})
PksVysPP = 36×5 table
X Peak Location Peaks X Valley Location Valleys P-P _______________ ______ _________________ ________ ______ 1.0228e+06 10.696 1.0229e+06 0.82368 9.8726 1.0232e+06 12.849 1.0234e+06 3.1877 9.6609 1.0237e+06 8.5264 1.0238e+06 2.923 5.6033 1.024e+06 16.024 1.0243e+06 -0.25246 16.276 1.0245e+06 16.536 1.0247e+06 -1.8931 18.429 1.0249e+06 23.716 1.025e+06 -5.1215 28.837 1.0254e+06 19.499 1.0257e+06 -1.8049 21.304 1.0261e+06 17.471 1.0263e+06 -2.7576 20.228 1.0268e+06 17.206 1.027e+06 -0.25246 17.458 1.0275e+06 15.248 1.0276e+06 -3.9748 19.223 1.0281e+06 15.971 1.0283e+06 -2.246 18.217 1.0288e+06 15.424 1.0289e+06 -3.3574 18.782 1.0295e+06 14.613 1.0296e+06 -2.9516 17.564 1.0301e+06 18.123 1.0303e+06 -1.311 19.434 1.0308e+06 12.796 1.0309e+06 1.4941 11.302 1.031e+06 10.749 1.0314e+06 2.3056 8.4436
This may be a bit fragile, since the findpeaks calls require two name-value pair arguments to get the desired results. It appears to work here.
.
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Star Strider am 21 Jan. 2023
As always, my pleasure!
I used the signs of ‘vys’ correctly in the plot and calculations except in the table. My apologies for that overisght. (The table was an afterthought.)
With noisy data that is not filtered, it is necessary to make certain adaptations. For that reason, the code is a bit fragile, so unless other data sets have essentially the same characteristics, the name-value pair argument values may need to be tweaked.
.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Spectral Estimation finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by