Count Peaks in a Graph
이전 댓글 표시
Hello all,
I'm writing a code in matlab which will count the peaks, by (1) determining the intersection with a threshold and (2) a positive slope of the signal z(n)-z(n-1)>0
but the code isn't working. I'm stuck at counting the intersection points beteween the signal and the threshold.
P.S. I'm trying to avoid MATLAB's Specific functions, and to use basic code. because I'll convert this code to MathScript later on.
Thank you

Here's my code:
clc;
clear all;
rise=0;
%specs
f=1;
Amp1=1;
Amp2=0.5;
ts=1/8000;
T=6;
t=0:ts:T;
%signals
y=Amp1*sin(2*pi*f*t);
x=-Amp2*sin(2*pi*f*t);
%rectification and summation
y(y<0)=0;
x(x<0)=0;
z=x+y;
%thresh
thL=0.1*max(z);
for n=1:(length(z)-1)
if (z == thL) % crossing thresh
rise = rise + 1;
end
end
disp(rise);
plot(z, 'b')
hold
line(xlim, [thL,thL], 'Color', 'r')
legend('Signal', 'Threshold');
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

