Area between the peak of the signal
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yew Jen Chong
le 17 Juin 2022
Commenté : Star Strider
le 22 Juin 2022
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 commentaires
Star Strider
le 17 Juin 2022
How did you identify those specific peaks?
I am having problems reproducing that with findpeaks.
Réponse acceptée
Star Strider
le 18 Juin 2022
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 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!