Go Down

### Topic: How PWM produces sound (Read 3725 times)previous topic - next topic

#### silverface

##### Aug 27, 2013, 09:07 pmLast Edit: Aug 27, 2013, 09:26 pm by silverface Reason: 1
Do speakers automatically average the PWM signal? If so, why does it produce a sound when you run analogWrite(x)? If you provide a single, constant voltage, then the speakers don't have an actually frequency, they just remain at that one voltage.

If they don't average the PWM signal, then I'm not sure how the same analogWrite call produces sound, since the signal is clipped (i.e. does not go below 0V) and the signal doesn't resemble a true waveform. The signal alternates between two states, and I thought you need a continuous signal to produce the pressure gradient that results in sound. Also I thought you need the negative part of the signal to produce the rarefactions.

Additionally, I see the term "AC current" thrown in a lot in discussions of sound. In this case does AC describe the voltage being negative at points?

#1
##### Aug 27, 2013, 10:04 pm
analogWrite() is not a single constant voltage - it is a ~490Hz 0V to 5V square wave, with the 0 time varying in width to the 5V time, but the time from rising edge to rising always the same - about 2mS.
The signal does a resemble a true waveform.
If you download Visual Analyzer from here
http://www.sillanumsoft.org/prod01.htm
you can see the waveform, and further see how it is impacted by the inductor that is the voicecoil of the speaker.
You can drive a speaker directly is you put a 150 ohm resistor in series with the speaker.
If you run the signal thru an amp (say a powered computer speaker) then you will want to use a voltage divider so the amp in the speaker sees a smaller signal, like 1V.

AC can refer to current flowing From the Arduino pin when high, and into the Arduino pin when low - when high, a transistor turns on to connect to 5V, and when low a complementary transistor turns on to connect to Gnd.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### DVDdoug

#2
##### Aug 28, 2013, 01:11 am
Quote
Also I thought you need the negative part of the signal to produce the rarefactions.

Additionally, I see the term "AC current" thrown in a lot in discussions of sound. In this case does AC describe the voltage being negative at points?
The room/space cannot support constant pressure ("DC"), and if the speaker is not sealed, it cannot support constant pressure.  In effect you have a high-pass filter (actually a band-pass filter) so the acoustic wave contains both rarefaction and compression, although the electrical signal does not have a negative component.

If you pick-up the sound with a microphone, the waveform will swing positive & negative.

You can get the same effect by putting a capacitor in series with the speaker... It creates a high-pass filter, and the speaker will move both forward & backward (from it's neutral position).

If you hook-up a battery (true DC) to a speaker, you'll hear a click when you connect it, and another click when you disconnect it.   That's the filtering effects of the speaker and the air.

Even if there were a DC/constant pressure component, you wouldn't hear it because we can't hear down to zero-hertz, and the pressure wouldn't be enough to feel.

#### silverface

#3
##### Sep 03, 2013, 08:11 am
Why does a high-pass filter cause the speaker cone to move forwards and backwards from its neutral position? Isn't the position determined by the electric signal (i.e. voltage corresponds to positive relative to neutral)? If the electric signal is never negative, then how would the speaker cone move backwards behind the neutral position?

How is DC produced and how/why does it affect signals?

Thanks for the help.

#### janost

#4
##### Sep 03, 2013, 08:38 am
The capacitor in the HPF removes the DC Component in the signal.
So when stationary it is 0v and goes positive or negative depending on the change direction.

#5
##### Sep 03, 2013, 09:29 pm
silverface,
When current flows in a wire, it creates a magnetic field. Lets say the current is flowing in one direction, say out of an arduino high output pin X, thru a speaker voice coil, and into an arduino low output pin Y. If the two pins change state, now pin Y is high and X is low, then the current changes direction - it is negative with respect to  how it started.
Further, when current flows in a wire, it creates a magnetic field. If that wire is near another magnet which has its own field, the two magnetic fields can interact and push against each other, or pull towards each other. Going another step, if the original wire is attached to something, and the other magnet is fixed in place,  then when the current flows and the magnetic fields push & pull on each other, the wire and whatever is attached to it will move - if the "whatever" is a speaker cone, than sound can be created.
Now, if the speaker cone has some springiness to it, it will return to a neutral position when current stops flowing. Then, if current is only flowing in one direction, from an Arduino high pin to Gnd, the wire pushing against the fixed magnet pushes the cone one direction - and when the current stops flowing, the cone springs back to where it was.
You would get more volume by having the speaker driven back with "negative current", but its not needed for low volume sound.

Does that clarify things?

If you had DC current, the wire would push one direction and stay there. If the current was high enough, heat would be generated  due to the resistance of the wire, and could cause damage. Power is current x current x resistance. Thus 1 amp of current in an 8 ohm speaker would dissipate about 8 watts of power. (The 8 ohms is actually a measure of impedance, which is frequency related, so if you use a multimeter to measure a speaker, that's a DC measurement, and you actually see a smaller than 8 ohm number). If there was some small AC on top of the DC signal, the speaker would push to some non-neutral position and vibrate ther, vs vibrating around the neutral position as  intended.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### silverface

#6
##### Sep 04, 2013, 05:38 am
Great, thank you for the help.

Go Up