フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

ZERO crossing with certain conditions

1 回表示 (過去 30 日間)
Bran
Bran 2015 年 4 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am trying to write an algorithm which will look for zero crossings (or in my case crossing across a specific value) in my data and then keep only those points that are intercepted by values above a certain threshold; Here is the code I have written so far
Crossings=0;
for i=1:(length(X)-1 )
if ((X(i)>=4 && X(i+1)<4) || (X(i)<=4 && X(i+1)>4))
Crossings=1+Crossings;
index(i) = i;
end
end
INDEX = find(index>0);
for i = 1:(length(INDEX)-1)
a = INDEX(i);
b = INDEX(i+1);
for j = a:b
if X(j)>4
INDEX2(i,:) = [INDEX(i) INDEX(i+1)];
end
end
end
However, this code does not seem to be doing what I want it to do. It keep all the points instead of those with points above 4 inbetween. I have checked the dataset by plotting it out and I know that some of the values have values less than four between them. Where am I going wrong?

回答 (1 件)

pfb
pfb 2015 年 4 月 13 日
I'd go like
Y = X-4;
c = Y(1:(end-1)).*Y(2:end);
Now c(i) should be negative whenever X(i) and X(i+1) are "on different sides" of 4.
So, to find the crossings, all you need to do is
i = find(c<0);
I'm not sure I understand what you want, though. In your example the threshold is 4?

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by