Zero Crossing of Signal

4 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2020-4-11
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 个评论
Syed Adeel
Syed Adeel 2020-4-15
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 2020-4-16
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2020-4-11
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 个评论
Image Analyst
Image Analyst 2020-4-12
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 2020-4-15
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by