Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

find the zero crossings in a signal in matlab

Status
Not open for further replies.

tigercotter

New Member
Hi,

i want to find the zero crossing of a signal. But the data that i have gathered doesn't a value at y = 0.

i typed in zero_cross = find(y==0)

but it created a 0 by 1 matrix in that name.
 
find exactly "0" for real data is almost impossible if not impossible.

What I do is look for a change in sign.
For a positive going zero crossing:

start a FOR loop from 1 to the sizeof the array

use this variable (prob i) to index the matrix/array
keep incrementing throught the array until the value at that location is negative.

When it is negative, then start incrementing and wait until the value becomes greater than zero (ie positive).
I have a matlab fn that does this at work, but it is 7pm here now and you will have to wait until tomorrow
 
Code:
%############################################
%# Function to find position of the positive going zero    #
%# crossing of supplied data                #
%############################################
function offset = zero_cross(volts,offset)

swt             = 0;

while ( swt == 0 )
    
    if (offset+1 >= size(volts,1))
        swt = 1;
    else
        offset = offset + 1;
    end
    
    if (offset+1 >size(volts,1) )
        swt = 1;
    end
    
    if( volts(offset)<=0)
        if( volts(offset+1)>=0)
            swt = 1;
        end;
    end
    
end
 
find the zero crossings

I have written some code myself. See the attached file. would it do
 

Attachments

  • zero_cross_736.zip
    17.7 KB · Views: 1,610
use find to easily get zero crossings

found this on another page:

>>To find all of the zeros, use the command Z=find(abs(y)<0.01), and then type n(Z) to see when (in seconds) the zero crossings occurred.
 
problem with that is you cannot distiguish between a positive-going or a negative-going zero crossing
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top