For the last 24 hours, I have been trying to find the indices of the zeros crossing of a simple Sine Function. I should get the indices to be from 0 to 1 and then 9 values inbetween. However I dont start at zero, however i do end up at 1 and I have an extra detected zero crossing in the middle. I just need help fixing my code. Please anyone. I am losing my mind. Here is my code
clear close all clc
x = 1:2000; X = x; J = 1; Fs = 1999; N = J*Fs; t = 0: 1/Fs : J; Fn = 5; % this control the number of cycles/periods deltaJ = 0.0020; deltax = 1;
y_sine_25HZ = sin(Fn*2*pi*t); y = y_sine_25HZ ; plot(x,y, 'k.')
drvY = diff(y)/deltax; % one unit shorter than y
drvY = [drvY , drvY(end)]; % making up for the missing point
%
secondDrvY = diff(drvY)/deltax;secondDrvY = [secondDrvY, secondDrvY(end)];
%% Indices where sign change occurs %sign_Location = sign(secondDrvY) % where sign changes occur for the second derivative indices = [find(secondDrvY(2:end).*secondDrvY(1:end-1)<0) find(abs(secondDrvY)<1e-15)]; t(indices)
this is the result I am getting::
0.0990 0.1991 0.2991 0.3992 0.4992 0.5993 0.6993 0.7994 0.8994 0.9995 1.0000
if you plot it you will clearly see that it should start at 0 and end at 1. However it doesnt start at 0, it ends at 1, but grabs an extra point. 0.9995 should not be there and there should be a zero in the beginning (first point)
Also once I find these zero crossings how do I plot them on the sine function plot to show them across the sine function. Thank you.
need help
Best Answer