Filter löschen
Filter löschen

Area between the peak of the signal

2 Ansichten (letzte 30 Tage)
Yew Jen Chong
Yew Jen Chong am 17 Jun. 2022
Kommentiert: Star Strider am 22 Jun. 2022
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 Kommentare
Star Strider
Star Strider am 17 Jun. 2022
How did you identify those specific peaks?
I am having problems reproducing that with findpeaks.
Yew Jen Chong
Yew Jen Chong am 18 Jun. 2022
Hi, since the time in x-axis increase constantly, therefore the time in the second row will be selected to convert into frequency as the first row is zero. The frequency will be used in the findpeaks with minimum peak distance, minimum peak prominence, and minimum peak height is included to produce the graph above.
The code below is for producing the graph
findpeaks(cm.Torque_Nm_,Fs,'MinPeakDistance',0.016,'MinPeakProminence',5,'MinPeakHeight',6);
The code below is for storing information
[pksRT_after,locsRT_after] = findpeaks(cm.Torque_Nm_,Fs,'MinPeakDistance',0.016,'MinPeakProminence',5,'MinPeakHeight',6);
I hope I answer your question

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 18 Jun. 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 Kommentare
Yew Jen Chong
Yew Jen Chong am 22 Jun. 2022
@Star Strider Thank you for your helping.
Star Strider
Star Strider am 22 Jun. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by