Peak to peak amplitude
20 次查看(过去 30 天)
显示 更早的评论
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,
Thanks in advance.
0 个评论
采纳的回答
Star Strider
2023-1-21
LD = load(websave('question_sample','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1270450/question_sample.mat'));
Data = LD.MATLAB_question
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'})
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 个评论
Star Strider
2023-1-21
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.
.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!