# Amplifying PWM Audio with an OpAmp

I have an 8 Ω speaker and a Raspberry Pi. To play sound, I can connect the Raspi directly to the speaker, which works, but with very limited volume. I assume this is because of the 3.3 V PWM output by the Raspi which provides up to 20 mA (correct me if I'm wrong).

I therefore decided to test an LM358 OpAmp, which essentially is a voltage multiplier when it operates in closed-loop gain. The Raspi signal is 3.3 V already, so with a 5 V power supply I can at most go to 5 V, corresponding to Vout/Vin = 1/β = 1.5 (therefore R1 = 1 kΩ and R2 = 2 kΩ).

As the LM358 can provide around 20 mA as well, I would expect the loudspeaker to be slightly louder as it is driven with 5 V instead of 3.3 V, and P = U · I.

The result is that the loudspeaker is indeed a bit louder, but mostly quite distorted and noisy. So not the expected output.

simulate this circuit – Schematic created using CircuitLab

Why do I get such bad output audio? Shouldn’t the OpAmp just do a linear transformation of the signal?

(I probably lack some basic understanding of how OpAmps and speakers are supposed to be used. If so, I’d be happy to get some hints or references to read.)

## Edit – WPM measurements

Since knowing the input is important to this question, here some measurements – the first one shows the normal audio waveform, the second one is recorded at higher frequency which shows how the Raspi constructs the waveform. The signal is ± 1 V in these measurements.

I have also found this paper about biasing which provided a nice explanation of scaling and biasing.

• What is WPM in your title? Tip: when using the CircuitLab button on the editor toolbar the editable schematic gets saved inline with your post. No need for screengrab, file upload or background grid. We can also copy and edit in our answers. – Transistor Nov 21 '18 at 15:23
• The LM358 is an opamp and not designed to drive an 8 ohm speaker. It could drive a 600 ohm headphone though. To drive an 8 ohm speaker, use an audio power amplifier like the LM386. Shouldn’t the OpAmp just do a linear transformation of the signal? Yes but you have to understand the LM358's limits, which you violate by connecting an 8 ohm load to ground. Also you biased the input to 0 V DC which simply cannot work with a single 5 V supply. – Bimpelrekkie Nov 21 '18 at 15:45
• PWM audio depends on the speaker filtering out the square waves. If you put more power behind the square wave, you just get more distortion. You need to filter out the square waves first, then amplify the audio using an amplifier meant to drive a speaker. Class D amplifiers get away with driving the speaker directly because they use other means to filter out the square wave. – JRE Nov 21 '18 at 18:22
• @Transistor Pulse-width modulation – I have made some measurements to better see what it looks like, screenshots added in the question. Thanks for the hint, I previously failed at the registration process with pay-to-use. Added the inline circuit. – Simon A. Eugster Nov 22 '18 at 10:15
• @Bimpelrekkie Can I simply calculate the current as usual with I = U / R, and with 600 Ω headphones and 15 V I would get a 25 mA current which the LM358 is designed for, but the 8 Ω speaker would require 200 mA? – Biasing: The OpAmp’s Ground? Is the issue that (+) is on ± 1 V and (−) is on 0…x V which breaks the subtraction in the OpAmp? – Simon A. Eugster Nov 22 '18 at 10:39