Zero Crossing of Signal

7 visualizaciones (últimos 30 días)
Syed Adeel
Syed Adeel el 11 de Abr. de 2020
Comentada: Star Strider el 16 de Abr. de 2020
Hello everyone.
I want to find the zero crossing of my Signals. I used below code but it works incorrectly.
%%%%%%%%%%%Time Domain DA3 %%%%%%%%%%%
da3=da2*tf3;
da3s=ilaplace(da3);
da3t=subs(da3s,{t},{time});
//da3t is signal of which i need zero corssings
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zx = zci(da3t); //to find zero crossings
close all
figure;
plot(time(zx), da3t(zx), 'bp')
plot(time*1e9,da3t ,'-k','LineWidth',2);
xlabel('Time - [ns]');ylabel('Amplitude - [V]');
title('DA Transient Output ');
hold on
grid on
plot(time(zx), da3t(zx), 'bp') // to plot zero crossing

Respuesta aceptada

Star Strider
Star Strider el 11 de Abr. de 2020
The ‘zci’ funciton works correctly, although the latest version of it is:
zci = @(v) find(v(:).*circshift(v(:), 1, 1) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector (>= R2016b)
to work with more recent MATLAB releases. Note that it returns the indices of the approximate zero-crossings. If you want the exact zero-croissings, you need to interpolate to find them.
I cannot run your code, so I cannot correct the errors.
  22 comentarios
Syed Adeel
Syed Adeel el 15 de Abr. de 2020
Yea, you mentioned and I really appreciate that but when i try to read its value it gives NaN though it shows correct on Figure.
May be I am reading it wrong way
Star Strider
Star Strider el 16 de Abr. de 2020
It shows NaN because it is trying to extrapolate, although I am not certain what the reason is for that.
One solution for that is to let it extrapolate, and see what it returns:
t_exact(k) = interp1(da3td(idx(k))+[-1 +1]*1E-5, time(idx(k))*1E9+[-1 +1], 0, 'linear','extrap');
That should solve the extrapolation problem.
Another option (if the data permit it, so that it does not reference indices beyond the vector limits) is:
t_exact(k) = interp1(da3td(idx(k)+[-1 +1])*1E-5, time(idx(k)+[-1 +1])*1E9, 0);
If that needs to extrapolate, add those arguments.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 11 de Abr. de 2020
Did you try to use find() to find out the first index where da3t goes negative?
firstNegIndex = find(da3t <= 0, 1, 'first')
firstNegTime = time(firstNegIndex)
By the way, time is a built-in function so you should not use that as the name of your variable.
  3 comentarios
Image Analyst
Image Analyst el 12 de Abr. de 2020
It only crosses once. Once it's crossed, the values are now below the x axis. So you'll only have one crossing per signal, or possibly more if it later goes from below to above the axis. But you won't have 3 consecutive points where there is a crossing unless the signal has a value of 0 for 3 elements consecutively, which your signals don't do.
Syed Adeel
Syed Adeel el 15 de Abr. de 2020
Thankyou so much for your reply. Your option gives me accrate first zero crossing. Now as I have 3 zero corssings can you please tell me how to extend your method?
Thankyou

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by