Efficient Zero-Crossing Detection Code for Continuous Sine Waves in MATLAB

  • MATLAB
  • Thread starter elecz
  • Start date
  • Tags
    Detection
In summary, the conversation discussed detecting zero-crossings in a continuous sine wave through Matlab. The speaker requested a simple code to detect and store all zero-crossings in an array. The sine wave was described as a simple wave without noise or harmonics, with specific coefficients for A, B, ω, and ϕ provided. The code shared as an example recorded zero-crossings in an array with a timing accuracy of 1 microsecond.
  • #1
elecz
17
0
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...
 
Physics news on Phys.org
  • #2
Tell us about the "sine" wave. How is it generated, does it have noise or harmonics?
 
  • #3
Its a simple sine wave without any noise or harmonics
 
  • #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?
 
  • #5
ϕ=0 and w=2*pi*f; f=1000; B=0 and A=1; 0<t<5
 
  • #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.
 
  • #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
 

What is zero-crossing detection?

Zero-crossing detection is a method used to detect the moment when a signal crosses the zero axis. This is commonly used in signal processing and power systems to determine the frequency and amplitude of a signal.

Why is zero-crossing detection important?

Zero-crossing detection is important because it allows for accurate measurement and analysis of signals. It can also be used for triggering events, such as turning on or off a device at specific points in the signal.

How does zero-crossing detection work?

Zero-crossing detection works by continuously monitoring a signal and detecting the point at which it crosses the zero axis. This is typically done by measuring the voltage or current level and comparing it to a reference value.

What are the applications of zero-crossing detection?

Zero-crossing detection has a wide range of applications, including power systems, audio and video processing, motor control, and telecommunications. It can also be used in data compression and encryption algorithms.

What are the advantages of zero-crossing detection?

The main advantage of zero-crossing detection is its simplicity and low cost. It also provides accurate measurements and can be easily implemented in various electronic devices. Additionally, it can help reduce noise and improve the efficiency of power systems and signal processing.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
742
Replies
6
Views
1K
  • Biology and Medical
Replies
6
Views
412
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Replies
39
Views
472
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top