How much is necessary to "apply a high-pass filter" (aka "remove the DC bias") to a low-pass filtered PWM audio output?
It's good practice to ALWAYS use a "DC blocking" capacitor (high pass filter). Many amplifiers already have a capacitor at the input, but you can't count on it. And, it's bad practice to run DC through speakers or headphones.
I'm afraid to end up damaging my earbuds/headphones/speakers/amplifiers by listening to a filtered PWM-ed audio.
Unfiltered PWM can damage an amplifier and because of the high-frequency energy it could damage a tweeter. It's probably not going to damage headphones or a full-range speaker, and that depends on amplifier power, but it should be filtered. Speakers and headphones have some inductance, so if the PWM frequency is high enough the speaker/headphone itself will provide some filtering.
DVDdoug:
It's good practice to ALWAYS use a "DC blocking" capacitor (high pass filter)
Which value and type of capacitor?
Unfiltered PWM can damage an amplifier and because of the high-frequency energy it could damage a tweeter. It's probably not going to damage headphones or a full-range speaker, and that depends on amplifier power, but it should be filtered.
It depends on the input impedance of the amplifier. The input impedance forms the "R" in your high-pass filter. If you assume an input impedance of 10K Ohms (or higher) a 1uF capacitor will give you a cutoff frequency below 20Hz, which is generally considered the lowest audible frequency.
An RC low-pass filter is enough?
That's not so easy to answer... The higher the PWM frequency the more filtering you'll get. If the PWM frequency is much-much higher than the highest audio frequency you should be able to get away with a simple filter.
I'm not an expert on PWM audio and I'm not sure if you can set the Arduino's PWM frequency high enough for high-quality audio, even with a good filter. And since the default built-in PWM is only 8-bits, you can't get high quality from it anyway.
PWM is more difficult to filter than "normal" PCM audio. With 44.1kHz PCM "CD audio" you can actually get-away with no filtering. The clock noise isn't nearly as bad with PCM as with PWM... I connected the output of a cheap soundcard to an oscilloscope once and I was surprised to see a stair-stepped PCM waveform with no filtering. The sound seemed fine to me! I assume the amplifier and speakers were filtering the sound and of course you can't hear anything at that frequency anyway.
and I'm not sure if you can set the Arduino's PWM frequency high enough for high-quality audio, even with a good filter.
You can.
Basically you need to set the PWM frequency to be at least twice the highest sample frequency. The PWM can be set far higher than that. I tend to use 125KHz. It is well out of the audio range and so no filtering is actually needed. It could be that the energy at this frequency might upset amplifiers down stream so a simple filer is all that is normally needed.
All right then.
I measured the impedance of my earbuds/headphones, and they have something around 13-14 ohms. So in this case, which value of capacitance do I need (to remove the offset)? The type doesn't matter, right?
Grumpy_Mike:
I tend to use 125KHz. It is well out of the audio range and so no filtering is actually needed.
I know that 125 KHz is not audible for a human being. So, at that frequency, do you really need no filtering at all for headphones?
Is the inductance of a headphone (or any passive speaker) actually capable of convert the high-frequency PWM-ed switching signal into a voltage level without any filter?
Yes no filtering required. Mind you 14R is too low to directly connect a ear bud so you either need a seriese resistor of about 100R or an amplifier of some sort.
so you either need a seriese resistor of about 100R or an amplifier of some sort.
Well... to be honest, just the output is so loud that even I ended up using a potentiometer. My RC low-pass filter, built on 200 ohms of resistence and 0.1 uF of capacitance, is the cause of that?
Which value of capacitance do I need to remove the DC offset of the output
Any value of series capacitor will remove a DC offset.
Does matter the capacitor's type?
Only to a secondary degree, there are audiophiles that say a ceramic capacitor will interfere with the frequency response because it is non linear. But then we are talking about an 8 bit system so any effect is lost in the existing poor quality.
No the PWM is not symmetrical arround ground. For it to be so would require a negative rail to the power supply and a totally different design to the processor.
I think you are over thinking how a seriese resistor might affect your signal.
Grumpy_Mike:
No the PWM is not symmetrical arround ground. For it to be so would require a negative rail to the power supply and a totally different design to the processor.
Now I understand what means "PWM symmetrical arround ground". Thank you.
I think you are over thinking how a seriese resistor might affect your signal.
Maybe... you're right. Are you telling me that the ESR (Equivalent Series Resistance) of a capacitor is tiny enough that I wouldn't notice the difference? (in the signal's strength)
Are you telling me that the ESR (Equivalent Series Resistance) of a capacitor is tiny enough that I wouldn't notice the difference? (in the signal's strength)
Yes.
See the table here:-
A value of even the highest hear of 7 Ohms is not going to affect anything.