Re: PWM -> Audio Output
- From: Rene <a@xxx>
- Date: Fri, 12 Jun 2009 12:29:40 +0200
John Speth schreef:
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. 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.
The most important thing is to understand enough about dsp so that one sees what one can do to make it unnecessary to have a well designed output filter (hint: with decent oversampling a single order filter can be more than sufficient) and why that is so.
And as far as it comes to PWM being in practice an imperfect system, You may come and listen to my cd-player, You won't hear any popping there. PWM is a very good way of da conversion and is used in relatively high-end stuff as well.
Rene
.
- References:
- PWM -> Audio Output
- From: eeboy
- Re: PWM -> Audio Output
- From: John Speth
- PWM -> Audio Output
- Prev by Date: Re: PWM -> Audio Output
- Next by Date: Re: Software Engineering process
- Previous by thread: Re: PWM -> Audio Output
- Next by thread: Re: PWM -> Audio Output
- Index(es):
Relevant Pages
|