# Can you turn a square wave into a sine wave using a low pass filter?

And if it could, would it make the sound of the square wave thinner than before because of losing its harmonics?

• a single sine wave doesn't have any harmonics. Harmonics would be other sines. – Marcus Müller Jun 16 '16 at 9:26
• If it is OK, I'd recommend removing your second question. A low pass filter is a filter that only lets low frequencies pass. That's all there is to that word. – Marcus Müller Jun 16 '16 at 9:27
• Lets assume that the square wave is bipolar, without a DC, to simplify. – Fat32 Jun 16 '16 at 11:59

To be able to analyze what a low pass filter does first you would need to understand what a Fourier transform is, hence some theory first.

The Fourier transform essentially represents the time-domain information stored in some function (a square wave in your case) in terms of frequencies. A simple example would be a sine wave $$sin(2\pi f_{c} t)$$ which contains just a single frequency, $$f_{c}$$. In the frequency domain, after taking the Fourier transform, it produces 2 frequencies at $$f_{c}$$ and $$-f_{c}$$ (the negative value occurs because of the mathematical representation of the Fourier transform using complex exponentials, but nevertheless the positive frequency $$f_c$$ is what one would expect).

If you are clear with that, then let's move on to what a filter is. A filter modifies the input and generates some output from it and is often represented in the frequency domain => A filter modifies the Fourier transform (aka frequency spectrum) of an input. Basically, it may attenuate some parts of the frequency spectrum and magnify other parts, and may add a "phase change" (frequencies manifest themselves as complex numbers, and phase changes become relevant then)

Now, lets see what exactly a low pass filter does to a square wave.

A low pass filter can be understood as a filter that cuts-off frequencies above a certain threshold when applied to some input. High frequencies which correspond to rapid transformations in the time domain are removed from the input and only the lower frequencies remain.
(source: www.sfu.ca)

In the image attached above, the function on the left is a square wave and the one on the right is the magnitude plot of its corresponding Fourier transform (as mentioned before, the frequencies are actually complex numbers and the entire Fourier transform would be complete only with the addition of a "phase plot" as well).

Observing the magnitude plot, if one were to pick a low pass filter with cut-off frequency between that corresponding to bin #1 (1st harmonic: 100 Hz) and bin #2 (3th harmonic: 500 Hz), the other higher frequencies would get cut out and there would only be 2 frequencies that remain: -100 Hz and 100 Hz which would correspondingly represent a sine wave (as mentioned above).

It is therefore viable to use a low pass filter to create a sine wave out of a square wave. However one is restricted to a sine wave with the frequency the same as the period ($$1/f_o$$) of the input square wave. Higher harmonics cannot be generated (a band-pass filter would be required for the same).

EDIT: Thanks to @Matt for pointing out that the question says square wave and not rectangular function. Edited answer to reflect the same.

• Thanks a lot!! I think I have a much better idea now. The reason why I want to find out about this is because someone told me it is not possible to have clipping on a square wave, there would be no difference? What would be the best way to add distortion or fuzz to a square wave sound wave, e.g. synthesizer – Mark Jun 16 '16 at 10:33
• By clipping if you are referring to amplifier clipping, then I see no reason for why square waves cannot be clipped. Clipping is a result of the amplifier not being able to supply as much power as demanded, so it cuts-off at its peak power. If the square wave to be generated has a higher power than what the amplifier can generate, then it will get cut-off to another square wave with magnitude at its peak power. As for the second part of your question, what exactly do you mean by best way? – Television Jun 16 '16 at 10:59
• Distortion in audio is usually taken to mean some sort of non-linear operation. Clipping, or saturation, is a non-linear operation. Clipping a square wave is a special case, where the signal is only scaled, so you won't introduce any distortion. Another non-linearity, such as the squaring it $x^2$ might be what you want? – Arnfinn Jun 16 '16 at 11:11
• @Mark: Fuzz or distortion (in the music-related sense of the word) really doesn't make sense on a square wave, because all fuzz/overdrive/distortion circuits or algorithms produce some form of (soft) clipping. In this way they add spectral components that were not there before (often at odd multiples of the fundamental frequency). Since a square wave already contains all odd numbered harmonics, fuzz wouldn't add anything. – Matt L. Jun 16 '16 at 11:39
• @NivedRajaraman: By 'square wave' the OP means a periodic function, not a (non-periodic) rectangular function. So I think your answer doesn't apply. A low pass filter will indeed work in that case. – Matt L. Jun 16 '16 at 11:42

In principle you can, in practice you almost can. The square wave consits of sinusoids with frequencies that are at multiples of the fundamental one (the inverse of the length of one high and one low). These are called harmonics, as you already seem to know. The low pass filter can remove all frequencies above the fundamental one, and you are left with only one sinusoid. A practical filter will leave some of the higher frequency components, so it will not be perfect. If it sounds thinner is a matter of subjective opinion. I believe the study of how people perceive sound is called psychoacoustics, so you can possibly find some studies on square waves vs. sinusoids is you search for that.

Think of a low pass filter as trying to shake a dumbbell. If you shake it slowly, you can easily make large motions, if you shake it quickly, it is much harder to make large motions.

• Is it possible to have clipping on a square wave? – Mark Jun 16 '16 at 10:47
• I guess this is a different question, but yes, you can clip a square wave. The result is a square wave with a lower amplitude. The harmonic components are the same, but with smaller magnitudes... – Arnfinn Jun 16 '16 at 11:01