Eli5: So apparently Arduino Uno cannot output analog signals and so it uses pulse width modulation to mimic an analog signal output. So then, how can a square wave with varrying width mimic an analog signal’s sine wave?

286 views

Eli5: So apparently Arduino Uno cannot output analog signals and so it uses pulse width modulation to mimic an analog signal output. So then, how can a square wave with varrying width mimic an analog signal’s sine wave?

In: 34

18 Answers

Anonymous 0 Comments

The trick is that the real world is analog.

If you use PWM on a LED light, the LED will blink really really fast. But your eyes can’t *see* really fast blinking: they will average out all those tiny pulses! A LED which blinks at 25 microseconds on & 75 microseconds off will *look* identical to an analog light which is at 25% brightness. A high-speed camera could see the difference, but your *eyes* can’t.

You can use a similar thing with a speaker. The speaker coil itself has physical mass and takes a while to move, so if your pulses are fast enough it’ll move to the *average* value of them because it simply can’t respond fast enough for each individual pulse.

This principle can also be exploited to convert a PWM signal to a true analog signal: simply use a low-pass filter! In reality there is no such thing as a perfect square wave, and it can also be seen as a sum of sine waves of an [increasingly higher frequency](https://en.wikipedia.org/wiki/Square_wave#Fourier_analysis). If we filter out the higher frequencies, we’ll be left with a good old regular analog signal.

You are viewing 1 out of 18 answers, click here to view all answers.