Area between the peak of the signal
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
Anyone know how to calculate for the area of torque between the peak (triangle label) of the signal?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1035235/image.png)
Can anyone please help me?
Thank you.
4 件のコメント
Star Strider
2022 年 6 月 17 日
How did you identify those specific peaks?
I am having problems reproducing that with findpeaks.
採用された回答
Star Strider
2022 年 6 月 18 日
I had to tweak the code slightly to get the result I needed for the ‘areav’ and ‘absareav’ calculations.
Try this —
% opts = weboptions('ContentType','text');
% W = webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1035225/s.m', opts)
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1035230/signal.csv', 'VariableNamingRule','preserve');
t = T1.('Time [s]');
Fs = 1/t(2);
Torque = T1.('Torque [Nm]');
env = envelope(Torque, 100, 'peak');
Lv = env >= 5;
LastIdx = find(Lv,1,'last');
[pksRT_after,locsRT_after] = findpeaks(Torque,'MinPeakDistance',100,'MinPeakProminence',20,'MinPeakHeight',6);
locsRT_afterv = [locsRT_after; LastIdx];
for k = 1:numel(locsRT_afterv)-1
idxrng = locsRT_afterv(k) : locsRT_afterv(k+1);
t_midrng(k) = median(t(idxrng)); % Used In 'text' Call
areav(k) = trapz(t(idxrng),Torque(idxrng)); % Area
absareav(k) = trapz(t(idxrng),abs(Torque(idxrng))); % Absolute Area
end
% buffer(areav,10)
% buffer(absareav,10)
figure
plot(t(Lv), Torque(Lv))
grid
hold on
plot(t(locsRT_after), pksRT_after, '^r')
% plot(t, env, '-r')
hold off
text(t_midrng, pksRT_after/2, compose(' \\leftarrow Area = %.4f',areav), 'Horiz','left', 'Vert','middle', 'Rotation',90, 'FontSize',9)
The loop uses trapz to calculate the areas between the locations denoted by the red triangles. The code then plots and labels them. (It uses the envelope function to define the area of interest in the signal for the plot.)
.
2 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!