To catch correct jump and store the number

1 次查看(过去 30 天)
Hi I want to record the up and down count of the signal when it satisfies my threshold condition but the code is not working. I need to catch the jumps shown by red in the image. I have attached the image as well as my code so can anyone solve it sooner. Thank you for your help!
phi(1)=0.66702; phi(2)= 0.667003; phidc(1)=0;phidc(2)= 0.00001;
for n=2:10^5 ;
p= 0.5.*rand-0.25; q = 1.*rand -0.5 ;
phi(n+1)= 0.0031+ 1.9676*phi(n) -0.9686*phi(n-1)- 0.0039*cos( 0.5*phidc(n))* sin(phi(n)) + 0.0390* q ;
phidc(n+1)= 1.8873*phidc(n) -0.9686*phidc(n-1)- 0.0079*sin(0.5*phidc(n))* cos(phi(n)) + 4*0.0390* p ;
if phi(n+1)> 4.5 && phi(n)< 4.5 ;
count1= count1+1 ;
UP(count1)= n;
if phi(n+1)< 1.5 && phi(n)> 1.5 ;
count0= count0+1 ;
DOWN(count0)= n;
end
end
end
  4 个评论
Star Strider
Star Strider 2018-2-20
You will likely have to do that in hardware, for example with a Schmitt trigger (link).
It might be possible to do that in real-time. I have no real-time Toolboxes, so I have no experience with that.
suman Dhamala
suman Dhamala 2018-2-20
The code is very simple. I am not getting an idea to use two if loop in a correct way I guess

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by