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?
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!