An efficient way of finding sequential points near zero

6 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Cedric
Cedric il 5 Ago 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 ) ;

Più risposte (2)

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

Accedi per commentare.


Star Strider
Star Strider il 5 Ago 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