An efficient way of finding sequential points near zero

8 visualizaciones (últimos 30 días)
Bran
Bran el 5 de Ag. de 2015
Comentada: Bran el 5 de Ag. de 2015
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.

Respuesta aceptada

Cedric
Cedric el 5 de Ag. de 2015
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 ) ;

Más respuestas (2)

Matt J
Matt J el 5 de Ag. de 2015
Editada: Matt J el 5 de Ag. de 2015
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 comentarios
Bran
Bran el 5 de Ag. de 2015
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 el 5 de Ag. de 2015
You can interpolate a curve, rather than fit. A simple choice would be
fzero( @(x) interp1(yoursignal,x) , initialGuess);

Iniciar sesión para comentar.


Star Strider
Star Strider el 5 de Ag. de 2015
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.

Community Treasure Hunt

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

Start Hunting!

Translated by