필터 지우기
필터 지우기

An efficient way of finding sequential points near zero

조회 수: 3 (최근 30일)
Bran
Bran 2015년 8월 5일
댓글: Bran 2015년 8월 5일
I have an signal that oscillates. I am looking for an efficient way to find all values in it that are near to zero. I would only need to find one per cycle so nearest. I tried using a for loop but it wasn't a very neat way and I was wondering if there are any functions in MATLAB that will do this for me.

채택된 답변

Cedric
Cedric 2015년 8월 5일
What you want to achieve is not completely clear to me. Does that help?
t = 0 : 0.1 : 20 ;
x = sin( t ) + rand( size( t )) ;
figure() ; clf ; hold on ; grid on ;
set( gcf, 'Units', 'normalized', 'Position', [0.1,0.1,0.8,0.8] ) ;
plot( [min(t), max(t)], [0, 0], 'k', 'LineWidth', 2 ) ;
plot( t, x, 'b' ) ;
kerSize = 10 ;
x_smz = conv( x, ones(1, kerSize)/kerSize, 'same' ) ;
plot( t, x_smz, 'r' ) ;
s = sign( x_smz ) ;
tId = find( s(1:end-1) .* s(2:end) < 1 ) ;
tz = t(tId) - x_smz(tId) .* (t(tId+1)-t(tId))./(x_smz(tId+1)-x_smz(tId)) ;
plot( tz, 0, 'go', 'LineWidth', 2 ) ;

추가 답변 (2개)

Matt J
Matt J 2015년 8월 5일
편집: Matt J 2015년 8월 5일
If you're confident that the zeros are spaced apart by some minimum known amount Delta, you can divide your cycle into intervals of width Delta and apply fzero() in each.
If you have no prior knowledge of the spacing between the zeros, then there is no way to find them all non-analytically.
  댓글 수: 2
Bran
Bran 2015년 8월 5일
Thank you so much for the response. I can use Fzero on a real signal? or must I fit a curve to it?
Matt J
Matt J 2015년 8월 5일
You can interpolate a curve, rather than fit. A simple choice would be
fzero( @(x) interp1(yoursignal,x) , initialGuess);

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


Star Strider
Star Strider 2015년 8월 5일
You have to use a for loop to iterate through the different starting estimates (or ranges). You can make this easier and more efficient by using built-in functions to define the approximate zero-crossings first. One possibility is here. See the documentation for circshift for details on using it with your data. I have sometimes found that using a two-index shift (changing -1 to -2) is superior to a one-index shift. It depends on your data, so you will have to experiment.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by