User:LucasVB/Sine from square waves
We know a square wave can be synthesized using sine waves via an infinite series, as seen at the right. But what if we try to do the opposite, that is, synthesize a sine function out of square waves? Well, I decided to give it a shot, and the result is what you see at right. This time, subtractice synthesis was necessary, using only odd harmonics.
I defined my square function using the sign function, as such:
And my approach to the square sine was evaluting the following:
Which is what you see in the second animation. The jump discontinuities of the square waves add up in the zero crossings, and they are unbounded, so it wasn't really too successful. If this was a signal, a simple lowpass filter would pretty much solve all these issues, and the result would be quite close to a sine wave.
The problem is that in theory, you cannot get a smooth, continuous function out of a discontinuous function, as explained by User:Rainwarrior, since you need to approximate any given continuous segment with this function. This cannot be done with the square wave.
He did, however, present an improved method to achieve my original goal, which worked nicely and didn't grew indefinitely in the discontinuities:
As you can see, his results were very nice.
( There is some more discussion that was archived at Wikipedia:Reference_desk_archive/Science/December_2005#Synthesis_of_a_sine_wave_from_square_waves ).
Practical sine wave generation
Is there a Wikipedia article about how practical people generate sine waves? Or would that verge too close to the "No Howtos" rule?
In practice, lots of people want to generate sine waves from digital electronics (which are notorious for only generating square waves).
- Some people drive high-power loads. Some high-power loads like 3-phase motors require something like a sine wave, but the high-power transistors that drive them work best when operated as switches, either switched entirely on or switched entirely off (generating something like a square wave).
- Some people want a sine wave at some particular precise audio frequency -- perhaps to drive DTMF-controlled equipment. Purely analog sine wave generators typically drift too much in frequency, except for crystal oscillators, which aren't available at audio frequencies.
But none of these use any of the techniques we've discussed -- Walsh transforms, sum of square waves at different amplitudes and frequencies, etc.
I've only seen these 3 techniques used to generate sine-wave-shaped voltages:
- analog-to-digital converter (for example, "Digital signals produce pure sine waves" by Ronald Mancini 1997)
- pulse-width modulation (for example, "Generate sine wave modulated PWM with AVR microcontroller"
- "magic sinewaves" (, ).
All of them use a crystal oscillator at some much higher frequency to set the timing, so each of these 3 are a different type of "crystal controlled electronic oscillator".
None of these methods generate a perfect sinewave directly, so all of them require an output "anti-aliasing filter". With adequate filtering, the output of the filter is close enough to perfect sinewave. Typically quite a bit of error (+-5% ?) is "close enough", so often a simple RC or LC filter is more than adequate.
I hope that helps whoever stumbles across this page. Feel free to move this to a more appropriate wiki article. --184.108.40.206 21:34, 26 October 2007 (UTC)