+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Advanced Member level 1
    Points: 3,987, Level: 14

    Join Date
    Nov 2005
    Posts
    440
    Helped
    4 / 4
    Points
    3,987
    Level
    14

    zero crossing matlab

    I found the following code to count the number of zero crossings in a signal. However, I don't understand how it works. Could someone pls explain the following code? Thanks.


    Code:
    % ZC number of zero crossings in x
    % [n] = zc(x) calculates the number of zero crossings in x
    
    function [n] = zc(x)
    s=sign(x);
    t=filter([1 1],1,s);
    n=(length(s)-length(find(t)))/length(s);

    •   Alt21st August 2007, 05:45

      advertising

        
       

  2. #2
    Newbie level 5
    Points: 1,093, Level: 7

    Join Date
    May 2007
    Posts
    8
    Helped
    1 / 1
    Points
    1,093
    Level
    7

    matlab zero crossing

    it looks like does not working to me
    does it?



    •   Alt21st August 2007, 10:27

      advertising

        
       

  3. #3
    Advanced Member level 1
    Points: 3,987, Level: 14

    Join Date
    Nov 2005
    Posts
    440
    Helped
    4 / 4
    Points
    3,987
    Level
    14

    matlab zero crossing detection

    Quote Originally Posted by aspedisca
    it looks like does not working to me
    does it?
    Agree... It works when I replace the commented line with the line as follows:
    Code:
    % n=(length(s)-length(find(t)))/length(s);
    
    n = length(find(t==0));
    By the way, do you know the purpose of the following code:
    Code:
    t=filter([1 1],1,s);



    •   Alt21st August 2007, 16:49

      advertising

        
       

  4. #4
    Newbie level 1
    Points: 840, Level: 6

    Join Date
    Apr 2008
    Posts
    1
    Helped
    0 / 0
    Points
    840
    Level
    6

    Re: Zero-crossing detection using MATLAB

    here better code in case your x signal is not known ( not sine...) :

    %x is nx1 vector

    zeroNb=0;

    for i=1:length(x)-1 %length : get x size

    if ((x(i)>0 && x(i+1)<0) || (x(i)<0 && x(i+1)>0))

    zeroNb=i+zeroNb;

    end

    end



  5. #5
    Newbie level 1
    Points: 318, Level: 3

    Join Date
    Mar 2011
    Location
    Bozeman, MT USA
    Posts
    1
    Helped
    0 / 0
    Points
    318
    Level
    3

    Re: Zero-crossing detection using MATLAB

    This won't quite work: It does not find values where the point is exactly == 0 and we want to add 1 to the total crossings not i. Try this:

    zeroNb=0;
    for i=1:length(x)-1 %length : get x size
    if ((x(i)>=0 && x(i+1)<0) || (x(i)<=0 && x(i+1)>0))
    zeroNb=1+zeroNb;
    end
    end



  6. #6
    Newbie level 1
    Points: 231, Level: 2

    Join Date
    Sep 2011
    Posts
    1
    Helped
    0 / 0
    Points
    231
    Level
    2

    Re: Zero-crossing detection using MATLAB

    the first code is small & effective, it uses an FIR filter to sum the sign of each sample by previous one which is equivalent by "when sign change" and count this changes
    of course the last line of code shode be corrected as:
    n=length(find(t==0)) + length(find(x==0));



  7. #7
    Junior Member level 2
    Points: 1,510, Level: 8

    Join Date
    Sep 2006
    Location
    IRAN
    Posts
    23
    Helped
    0 / 0
    Points
    1,510
    Level
    8

    Re: Zero-crossing detection using MATLAB

    hi please help me for detect zero crossing in matlab ?i want khnow calculate zero croosing for ECG in matlab have function ?
    for example : step()[COLOR="Silver"]

    I want my account to a signal following properties:
    a. Time characteristic (energy, average magnitude, zero crossing, autocorrelation)
    a. Frequency characteristic (like Fourier analysis)
    b. Computing signal to noise (white or colored) ratio (SNR)
    c. Study on Effect of sampling rate
    d. Signal visualizing (Clean and noisy signals like cross talk noise and echo)
    e. Signal filtering and denoising (group delay and phase delay)
    Signal segmentation (split into meaningful segments
    Last edited by hd_uni_pro; 29th December 2011 at 09:12.



  8. #8
    Newbie level 4
    Points: 176, Level: 2

    Join Date
    Feb 2012
    Posts
    6
    Helped
    0 / 0
    Points
    176
    Level
    2

    Re: Zero-crossing detection using MATLAB

    plz send ur funtion completely



+ Post New Thread
Please login