フィルターのクリア

finding zero crossings in a signal

45 ビュー (過去 30 日間)
SSG_newbiecoder
SSG_newbiecoder 2018 年 1 月 6 日
編集済み: Star Strider 2018 年 1 月 9 日
I need to find out the zero crossing points in a signal. How can I achieve this in matlab? I tried the code below but it is not working for my signal.Can anybody help me out?
t = [1:0.01:5]; % Time Vector
y = -2+2.*sin(2*pi*t); % Signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
zx = zci(y); % Approximate Zero-Crossing Indices
figure(1)
plot(t, y, '-r')
hold on
plot(t(zx), y(zx), 'bp')
hold off
grid
legend('Signal', 'Approximate Zero-Crossings')

回答 (2 件)

Star Strider
Star Strider 2018 年 1 月 6 日
編集済み: Star Strider 2018 年 1 月 9 日
The code works correctly. The amplitude of your signal goes from -4 to 0, so the ‘zero-crossings’ in your signal are correctly detected at the highest value of each cycle.
If you want the indices where the signal crosses the -2 value, the ‘zci’ call should be:
zx = zci(y + 2); % Approximate Zero-Crossing Indices
EDIT #1 (08 Jan 2018 at 13:00 UCT)
‘My issue is that my signal need not have an array index with zero as a value so I'm supposed to take the value as close to zero as possible and consider the index of that value as the zero crossing point.’
My code does exactly that!
EDIT #2 (09 Jan 2018 at 00:36 UCT)
If you want to find the midpoint crosses of your waveform, consider using the midcross (link) function.

Birdman
Birdman 2018 年 1 月 6 日
To find their time values, type
t=t(y==0)
To find their values in y vector, type
y=y(y==0)
  2 件のコメント
SSG_newbiecoder
SSG_newbiecoder 2018 年 1 月 8 日
My issue is that my signal need not have an array index with zero as a value so I'm supposed to take the value as close to zero as possible and consider the index of that value as the zero crossing point.
Birdman
Birdman 2018 年 1 月 8 日
Ok, then you may change the condition as following
idx=find(y==0);
y(idx+1)
y(idx-1)
This will result in the closest value to zero in your y vector which is dependent on t vector. The result is(for both):
-0.0039 -0.0039 -0.0039 -0.0039
What if your t vector's increment change? For instance:
t=1:0.001:5;
y=-2+2.*sin(2*pi*t);
Then, when the same procedure applies,
idx=find(y==0);
y(idx+1)
y(idx-1)
The result is:
1.0e-04 *
-0.3948 -0.3948 -0.3948 -0.3948
which is different than before. Hope this helps.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSignal Generation and Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by