필터 지우기
필터 지우기

Area between the peak of the signal

조회 수: 2 (최근 30일)
Yew Jen Chong
Yew Jen Chong 2022년 6월 17일
댓글: Star Strider 2022년 6월 22일
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
Star Strider 2022년 6월 17일
How did you identify those specific peaks?
I am having problems reproducing that with findpeaks.
Yew Jen Chong
Yew Jen Chong 2022년 6월 18일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
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
Yew Jen Chong
Yew Jen Chong 2022년 6월 22일
@Star Strider Thank you for your helping.
Star Strider
Star Strider 2022년 6월 22일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by