Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Zero-crossing detection

  1. Oct 9, 2011 #1
    I want to detect all zero-crossings in a sine wave through matlab. Kindly tell me about a simple code which detects all zero-crossings and stores them in an array. The sine wave is continuous time signal, not discrete...
     
  2. jcsd
  3. Oct 9, 2011 #2

    uart

    User Avatar
    Science Advisor

    Tell us about the "sine" wave. How is it generated, does it have noise or harmonics?
     
  4. Oct 9, 2011 #3
    Its a simple sine wave without any noise or harmonics
     
  5. Oct 9, 2011 #4
    A sine wave is given as the following analytic expression:

    [tex]
    y = A \, \sin{(\omega t - \phi)} + B
    [/tex]

    Do you know the coefficients [itex]A, B, \omega, \phi[/itex] from your example?
     
  6. Oct 9, 2011 #5
    ϕ=0 and w=2*pi*f; f=1000; B=0 and A=1; 0<t<5
     
  7. Oct 9, 2011 #6
    Well, you need to solve the equation:
    [tex]
    \sin{(2 \pi 1000 t)} = 0, 0 < t < 5
    [/tex]
    which means:
    [tex]
    t = \frac{n}{2000}
    [/tex]
    where n is an integer that must be in a particular interval so that the constraints on t are met.
     
  8. Oct 9, 2011 #7
    This is a simple code (but not Matlab) that records all zero crossings (of both signs) in array "xcross" to a timing accuracy of 1 microsecond.

    PROGRAM xcrossing
    DIM xcross(100000,3)
    OPTION NOLET
    f=1000
    w=2*pi*f
    dt=1e-6
    t=-dt/2
    y=sin(w*t)
    N=0
    DO
    t=t+dt
    yold=y
    y=sin(w*t)
    IF yold=0 then yold=1E-12 ! eliminates divide by zero problem
    IF y/yold<0 then
    N=N+1
    xcross(N,1)=N
    xcross(N,2)=t-dt/2
    xcross(N,3)=sgn(y)
    END IF
    LOOP while t<1
    FOR N=1 to 30 ! sample array printout
    PRINT xcross(N,1),xcross(N,2),xcross(N,3)
    NEXT N
    END
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Zero-crossing detection
  1. Detection method (Replies: 3)

  2. Infrared detection (Replies: 0)

  3. IR Detection (Replies: 8)

Loading...