brad wrote:You've got me quite interested - why would you use a notch filter for the PWM frequency? (i'm guessing a notch filter is still the same as a band stop filter)
More or less, but the notch ideally has an infinite attenuation at the one narrow frequency (not
band of frequencies) of interest. It doesn't have as much phase shift as a sharp, many-order (5th-order, 8th-order, etc.) filter of other types which may have many
hundreds of degrees of phase shift in the end of the passband even at frequencies where the amplitude has not started to drop off yet. The sharp low-pass filter is commonly called a "brick-wall" filter, because of its ideal frequency-response graph looking like ─┐.
To back up a bit-- I'm sure you're familiar with the concept of the
Nyquist frequency and aliasing. If your PWM (or other D/A) output has a sampling rate that's well below twice the highest frequency you can hear, images of the desired output frequencies wil be audible at higher frequencies as well, adding something unwanted. This is most obvious in cheap talking toys. Although you can understand them, they sound really bad. (This is slightly different from the aliasing problems in digital
recording, ie, going the other direction, with an analog-to-digital converter; but in both cases it is often desirable to have a brick-wall filter whose cutoff frequency is just below the Nyquist frequency. For an interesting tid bit, there are a few applications where you can legitimately get away with deliberate
undersampling as long as all the signals fall between harmonics of the Nyquist frequency, for example signals in the range of 205-215kHz sampled at 40ksps, since the Nyquist frequency is 20kHz, and 200kHz and 220kHz are harmonics of it. Note however that the
jitter must still be tight enough for the higher frequency, as if you were sampling at 440ksps or more.)
In the case of what I'm working on, the images from the aliasing from the PWM rates will be too high to hear. However, consider the situation where you feed 80H to a PWM that has 8-bit resolution. Even if you hold it there for sample after sample, meaning that for the moment there's no signal, you still have a maximum-amplitude square wave, at the PWM frequency! This is what I don't want the power amps trying to reproduce, partly as it would waste battery power in this battery-powered hand-held device (which, BTW, has nothing to do with entertainment, but is related to a medical treatment). I also don't want the IM distortion products the amps might produce with the PWM frequency being there so strong (although I must say I haven't measured those distortion products yet). There aren't enough octaves of separation between the desired audio and the PWM frequency to get by with a simple RC filter, and I was thinking that phase variations between channels could be a problem with high-order LP filters if inexpensive parts were used and no calibration were done in production.
This is why I was considering a notch filter. It would get rid of the PWM "carrier" without much effect on phase of the desired signals. The notch filter would not take the PWM
harmonics out, but those would be far enough out to handle with a simpler filter with less phase shift in the desired signal. The square wave as referenced above only has odd harmonics, starting with the 3rd; but the even harmonics, starting with the 2nd, will start showing up when you get away from that 80H input which gives the 50% duty cycle. There are different ways to implement a notch filter.
I have not tried the notch filter yet, but after yesterday's experiments with a 3rd-order (not 5th-order or higher) low-pass filter, I think that will work ok.
And, i've said it before and I'll say it again, you blow my mind with your level of knowledge towards programming, simply amazing!
Thankyou. There are a lot of programming fields where I have no knowledge, but in things that relate to my work where embedded computers are controlling realtime processes in products or on the workbench, I tend to be very resourceful and creative in using existing technologies and tools that I
do have to come up with new (at least new to
me) ways of solving problems.
And, as you can tell, I also get too much enjoyment from writing.