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?

277 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

It’s all about frequency response and filtering.

The scheme you describe is called “pulse width modulation”, and it works how you describe. For a given time period, the signal is pulsed on and off so the average amount of time that it is on is equal to the output value that you want.

Now you need a filter – specifically a low-pass filter. For dimming LEDs, our eyes do it – we interpret the PWM signal as the average value.

In other cases, it is done electronically.

There’s a very popular class of audio amplifier known as “class D” that uses this technique, and it makes light and powerful amplifiers.

Note that there are also a wide range of digital to analog converters that produce true analog output.

Anonymous 0 Comments

It’s all about frequency response and filtering.

The scheme you describe is called “pulse width modulation”, and it works how you describe. For a given time period, the signal is pulsed on and off so the average amount of time that it is on is equal to the output value that you want.

Now you need a filter – specifically a low-pass filter. For dimming LEDs, our eyes do it – we interpret the PWM signal as the average value.

In other cases, it is done electronically.

There’s a very popular class of audio amplifier known as “class D” that uses this technique, and it makes light and powerful amplifiers.

Note that there are also a wide range of digital to analog converters that produce true analog output.

Anonymous 0 Comments

A Pulse Width Modulation (PWM) signal has 2 properties: Frequency of the pulses and the Duty Cycle. The duty cycle is the ratio between *on*-time and *off*-time of the signal.

A duty cycle of 100% means always on, 0% means always off, 50% means half of the time on/off, 25% means 25% on, etc…

Although this is technically not an anlog signal, the average voltage will correspond more or less with the duty cycle. (Where 100% is often 5V or 3,3V, depending on the hardware.)

A sinewave can be represented by changing the duty cycle over time; from 0% to 100% and back to 0%. in each period.
And additional circuit is used (with an opamp) to offset the voltage so 50% duty cycle corresponds with 0 for the sinewave. This means 100% will be the top of the wave and 0% is the bottom of the wave.

In order to create an accurate sine wave, the frequency of the PWM signal must be high enough, you must be able to change the duty cycle fast enough, and the pulsed output should be converted into a true analog signal. (By using a filter.)

Anonymous 0 Comments

A Pulse Width Modulation (PWM) signal has 2 properties: Frequency of the pulses and the Duty Cycle. The duty cycle is the ratio between *on*-time and *off*-time of the signal.

A duty cycle of 100% means always on, 0% means always off, 50% means half of the time on/off, 25% means 25% on, etc…

Although this is technically not an anlog signal, the average voltage will correspond more or less with the duty cycle. (Where 100% is often 5V or 3,3V, depending on the hardware.)

A sinewave can be represented by changing the duty cycle over time; from 0% to 100% and back to 0%. in each period.
And additional circuit is used (with an opamp) to offset the voltage so 50% duty cycle corresponds with 0 for the sinewave. This means 100% will be the top of the wave and 0% is the bottom of the wave.

In order to create an accurate sine wave, the frequency of the PWM signal must be high enough, you must be able to change the duty cycle fast enough, and the pulsed output should be converted into a true analog signal. (By using a filter.)

Anonymous 0 Comments

Wat??? I’m too smooth brain to understand the title *microwaved brain noises*

Anonymous 0 Comments

Wat??? I’m too smooth brain to understand the title *microwaved brain noises*

Anonymous 0 Comments

The pulse is much higher frequency than the sine it represents. At the top of the sine wave, long top pulses and short bottom pulses. In the middle of the sine, equal length tops and bottoms of the pulse. At the bottom of the sine, long bottoms on the pulse and short tops. If you apply a little low-pass filter to smooth it out, it becomes a sine!

Anonymous 0 Comments

The pulse is much higher frequency than the sine it represents. At the top of the sine wave, long top pulses and short bottom pulses. In the middle of the sine, equal length tops and bottoms of the pulse. At the bottom of the sine, long bottoms on the pulse and short tops. If you apply a little low-pass filter to smooth it out, it becomes a sine!

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.

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.