Re: PWM -> Audio Output
- From: Ben Bradley <ben_nospam_bradley@xxxxxxxxxxxxxxx>
- Date: Fri, 12 Jun 2009 12:13:00 -0400
On Thu, 11 Jun 2009 08:45:24 -0700, "John Speth" <johnspeth@xxxxxxxxx>
wrote:
I am using a PWM output on my micro to produce audio from headerless WAV
(RAW) files. The audio output works but the quality is not quite there. By
that I mean that there are 'artifacts' which appear in the audio output
from my device which do not appear in the RAW file.... mainly a popping
noise which seems to follow the amplitude.
I've discovered that I can remove these artifacts by changing the PWM
frequency. As I lower the frequency the pops and clicks go away but the
audio does not reproduce as nicely.
My audio playback source code has two parameters which effect the
playback. First, the sample rate which I currently have fixed at 8kHz for
FLASH space savings. Considering that all audio played back will be voice
prompts I thought this was sufficient. Second, the PWM frequency which I
have set to be a multiple of the sample rate. So, if the sample rate is
8kHz and my PWM frequency is 32 times that... I have 32 PWM periods per
sample. I get really nice reproduction at 32 and 64 times the sample rate
but the popping noise is present. I eliminate the popping noise with a
setting of 8 but then the audio is marginal.
My PWM output feeds through a first order RC filter which is set to cut
off at around 8kHz. In practice it's currently around 12kHz because I
didn't have the correct resistor value in my bin at the time I populated
the board. The output of the filter is then fed to a amplifier
(capacitively coupled).
Coincidentally, I just finished an experiment nearly identical to yours. I
know exactly what popping you're talking about. It was an MSP430 running at
4 MHz. The poppiness is an absolutely sonically repeatable sound that can
also be described as a scratchiness.
You may have to post (on a website, and give the URL here, don't
post attachements to Usenet text groups) a recording of this so we can
hear and analyze it. Your description of "poppiness" appears to be
quite different from what I and apparently the rest of us interpret
the word to mean. I think of pops as in LP playback where random ticks
and pops are caused by dust and scratches.
Looking at further posts by the OP, it appears his pops were indeed
caused by interruptions of the PWM waveform due to a software bug.
In my situation, I didn't have any
interrupt problems. I chose to forego the output filter relying on the low
pass characteristics of my stereo instead.
First I picked my PWM rate as 15 KHz and 8 bits. The poppiness was evident.
Then I went to 60 KHz and 6 bits and the poppiness was reduced significantly
but not eliminated. Then I recalled a PWM audio experiment I did with an
STM32 part running at 72 MHz. The STM32 was running PWM at several hundred
KHz with a single pole output filter. There was no poppiness.
Taking all my observations together, I think one needs to consider and
carefully balance desired sound quality, sample rate, sample size, PWM
resolution, PWM rate, and most importantly have a well designed output
filter. I doubt you'll ever be able to completely eliminate the poppiness
because PWM in practice is an imperfect system but you can certainly improve
it to the point of acceptability.
I did 9600Hz PWM going into an analog filter (a twin-T notch at
9600 and two or three poles of low-pass around 3k) to generate DTMF
and 300 baud modem tones, and it worked just fine, the signals met
specs and all.
With PWM you really need a "strong" filter, as the level of the PWM
rectangular wave fundamental is as high as any of the desired signals.
And yes, with sufficient digital horsepower (which I didn't have in my
POTS-powered design from over a decade ago) you CAN upsample, use a
higher PWM frequency and a less aggressive filter on the output which
will more strongly attentuate the much higher frequency PWM
fundamental.
JJS
.
- Follow-Ups:
- Re: PWM -> Audio Output
- From: Tom
- Re: PWM -> Audio Output
- References:
- PWM -> Audio Output
- From: eeboy
- Re: PWM -> Audio Output
- From: John Speth
- PWM -> Audio Output
- Prev by Date: Re: Software Engineering process
- Next by Date: RS458 Cabling
- Previous by thread: Re: PWM -> Audio Output
- Next by thread: Re: PWM -> Audio Output
- Index(es):
Relevant Pages
|