Clear Filters
Clear Filters

Easy way of finding zero crossing of a function

19 views (last 30 days)
Hi guys, I have tried all my attempts but not succeeding to get the correct output/plot .
I'm trying to find my zero crossings points that are implicitly the intercestion of x axis, in other words I want to find all the zero crossings points of my signal by interpolation method!.
I've searched in the other threads over this forum and find subjects that are related to what Im asking but not exactly what I want or either their answers weren't totally correct!
I have signal called y1, it's vectors of samples, I sampled it on sample frequency 2048KHz .
accordingly to @ Star Strider code:
t = [1:length(y1)]; % Time Vector
y = y1; % Signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
zx = zci(y); % Approximate Zero-Crossing Indices
figure(1)
plot(t, y, '-r')
hold on
plot(t(zx), y(zx), 'bp')
hold off
grid
legend('Signal', 'Approximate Zero-Crossings')
when I do plot , Im not getting zero crossings points that are the intersections of x axis by interpolation method! , here's what I get:
what Im willing to do by method interpolation to find the zero crossings point which gives me like this result:
could anyone please help me how can I find the zero crossings points by interpolation to get like the above plot (zero crossings points like they are the intersections with x axis) ?
the code of my interpolation for finding the zero crossings that Im trying is: (Fs=2048Khz) - thanks to
if size(y1,1) == 1; y1 = y1.'; end %ensure columns of signal
c = size(y1,2);
wl = (0:size(y1,1)-1) / Fs;
Iwl2=360:0.001:740; % interpolating to 0.001-nm resolution
loc_frequ1=0;
for i=1:c
y = y1(:,i);
y2=interp1(wl,y,Iwl2); % interpolating to 0.001-nm resolution
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
zx = zci(y2); % Approximate Zero-Crossing Indices
loczeros1=round(Iwl2(zx));
locfrequ= ismember(Iwl2,loczeros1); % find same data from Iwl2
loc_frequ1=loc_frequ1+double(locfrequ);
end
>> c
c =
1
>> zx
zx =
0×1 empty double column vector
>> size(y1) %size of my signal data
ans =
9001 1
but the problem with this that this code didn't work and don't know what the problem is, zx isn't giving me the zero crossings point at all ..
Could anyone please help me how can I do and find the zero crossings points by interpolation in matlab? I really searched about other threads that are related to this but the answers weren't enough or didn't work for my case.
  4 Comments
Mohamed Jamal
Mohamed Jamal on 16 Jul 2020
thanks alot for your help guys, all fine succeeded !
thanks to you dpb

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!