You can find locations at which oscillations cross the axis (zero crossings) using the findpeaks()
function in Matlab by setting its MinPeakHeight
property to 0.
Here is an example code that demonstrates how to use findpeaks()
function to find zero crossings:
main.m280 chars13 lines
The findpeaks()
function returns the amplitudes of the peaks as the first output argument. Since we are interested only in the locations of zero crossings, we can ignore the output by using the tilde (~) symbol. The second output argument contains the indexes of the zero crossings.
In the above code, we first define a simple sine wave signal. Then, using findpeaks()
function with MinPeakHeight
property set to zero, we find the locations of zero crossings. Finally, we plot the signal and show the locations of zero crossings as red dots.
gistlibby LogSnag