IIR FM Pre-Emphasis Filter Investigations and A Digital Implementation
IIR FM Pre-Emphasis Filter Investigations and A Digital Implementation
IIR FM Pre-Emphasis Filter Investigations and A Digital Implementation
Initial ramblings.
So, like I was, you're wanting to make a compact digital recursive pre-emphasis filter.
Well, this is how I got on.
A pre-emphasis filter, is a filter that boosts the high frequencies. An IIR implementation
is a infinite impulse response implementation, they are recursive in nature. IIR filters
represent what can be made with electronic components. A digital implementation
approximates some sort of analog design.
First of all you need to know one or two things. The most important being transfer
functions.
A transfer function is a function that relates an input signal with an output signal and is
usually denoted with a H. If you were to multiply H by an input signal you would get
what the filter would output. Here's an example, figure 1 shows a voltage divider
network. The input voltage and the output voltage are related through the function
Vout Vin R1R2R2 . This means the transfer function is equal to H s R1R2R2 . The s in the
equation is a “complex frequency” s i , where is angular frequency in radians
( 2f ) and the rate of exponential change (see
http://en.wikipedia.org/wiki/S_plane or http://www.dspguide.com/CH32.PDF for more
info). As the voltage divider network is not affected by frequency, s has no effect in its
transfer function in this case.
Vin
R1
1k
Vout Vin R2
R1 R2
Vout
R2
1k
Now, my goal was to make a pre-emphasis filter for the wideband FM at 88-108 MHz.
What is the official standard? In all my looking on the Internet I could not find one place
that would give me an official straight answer. All I could find were more like rumors, no
official documents. This really grinds my gears. Why can't there be an easily found a
website that contains all the official standards for all countries of the world. This is what I
found, but as I couldn't find any official documents it is best to take this paragraph with a
pinch of salt. It was very common for people to quote the 3 dB corner which rumor has it
is 75 µs only for the USA and 50 µs for the rest of the world. A few places would also
say that after the 3 dB corner the gain would increase at 6 dB per octave. No one even
mentioned a transfer function. It also leaves a lot of questions unanswered; what does the
gain do between 0 dB and 3 dB, and if the decibel gain with respect to octaves is not
linear at 6 dB per octave everywhere, then how does the gain change when it's not
moving at 6 dB per octave? Also, what is the phase response? Unfortunately this is all I
had to go on. A simple transfer function and its coefficients given would have been all I
needed, and would have told me everything possible about the filter that I was after.
Instead this is what I had to do.
Preliminary investigations.
First I needed some simple transfer function to investigate. This would represent some
analog electronics. The simplest one I could think of was a linear one.
H a s as c (1)
Formula 1 is just such a function. From what we know of pre-emphasis, when we put in 0
Hz we would like to get a linear gain of 1. This gain we define as our 0 dB power mark.
This being the case implies that c 1 .
H a s as 1 (2)
As we are mainly interested in s where 0 we can rewrite formula 2 for this special
case as
Plin H a i a 2 2 1 By formula 3
2
(4)
P
PdB 10 log10 lin By formula 4
Plin 0
PdB 10 log10 a 2 2 1 (5)
With pre-emphasis we have the time constant , which as I said earlier is apparently 75
µs for the US and 50 µs for the rest of the world. As I live in the rest of the world, from
now on I'm treating it as being 50 µs. The so-called pre-emphasis time constant is the
reciprocal of the angular frequency when the power gain is 3 dB. This means the
following.
That solves the unknowns for our transfer function formula 1. However, we haven't
looked into the rate of change of the frequency response; remember, some websites have
said that the rate of change of the gain would increase at 6 dB per octave after the 3 dB
corner. This brings me to another one of my pet peeves, the decibel scale. First we need
to create some sort of octave scale, so let 2 oct . This does the job where oct is the
octave. Increase oct by one and the frequency doubles i.e. an octave.
d
PdB
10 2a 2
d ln 10 a 2 2 1 by formula 5. (8)
d d d
PdB PdB
doct d doct
20
a
2
d oct
ln 10 a 1 doct
2 2
2 by formula 8.
20
a 2
ln 22 oct
ln 10 a 1
2 2
20 ln 2 a 2 2
ln 10 a 2 2 1
(9)
Clearly formula 9 is not linear with respect to frequency. But when 1 / a a 1 ,
we can make an approximation which is the following.
d
PdB
20 ln 2 a 2 2
When 1 / a by formula 9.
doct
ln 10 a 2 2
d 20 ln 2
PdB When 1 / a
doct ln10
d
PdB 6.02 dB / octave When 1 / a (10)
doct
We can also see formula 9 is a monotonic increasing function. This means that this
6.02 dB / octave is the biggest the decibels per octave power gain can have and it
happens at a frequency of infinity. This I presume is where the 6 dB / octave comes from
that some websites mention. Now our transfer function pretty much matches what
websites mention about FM pre-emphasis filters (really this is not hard because they don't
tell us much).
Now let's graph the frequency response and phase response of this transfer function.
So what does the electronic network that represents this transfer function look like? The
answer is figure 3.
X
Y
C
Y X RCs 1
To see that figure 3 is related to formula 2, let X, Y and V be rms voltages at their
respective positions. Calculate the transfer function of each component, the input being
the current through the component and the output being voltage across the component.
For the resistor R this is simply the resistor value as R VR I R . For the capacitor C we
need to calculate the Laplace transformation of the voltage over the capacitor and divide
this by the Laplace transformation of the current through the capacitor. The differential
equation that relates current and voltage with the capacitor is i t C dtd vt . Using the
differentiation property of the Laplace transformation this implies that I C s CsVC s ,
and hence H C s 1 sC . Once again for more details see
http://www.dspguide.com/CH32.PDF.
Then, we can calculate how the voltage Y is related to voltage X through the following.
So far we have not looked into anything more than the points lying on the imaginary axis
of the s-plane. Now let's look over this s-plane more. Figure 4 shows a contour plot of the
magnitude of the transfer function we have derived so far. Think of color as height,
purples and blues are low in height while yellows and reds a high in height. The point at
1 ,0 (purple in color) has a magnitude of zero and is called not surprisingly a “zero”.
The vertical black line is the frequency response of the filter.
s 1
But there's more to life than just zeros. There's something called a pole. A pole is a
beastie that goes up instead of down like a zero as you approach it. In fact mathematically
a pole is just the reciprocal of a zero. This means if you're standing at a pole, you’re at
infinity, and when you go away from it, you'll gain goes down.
So if we were to put a pole slightly to the left of the zero we have in figure 4, as we stand
on the black line at a point with a very high frequency (a long way from both the pole and
the zero), the pole and the zero will seem to be more or less the same distance from us,
and hence will cancel each other out so our gain stops increasing. But, at low frequencies
to zero still be much closer to us than the pole, meaning the zero dominates the frequency
response, and we should still have a reasonably similar frequency response as to that in
figure 2 for low frequencies. That's the idea anyway, let's see what really happens.
Pole dancing.
Adding a pole to the transfer function in formula 2 gives us the new transfer function of
formula 14.
a s 1
H a s (14)
b s 1
This one will work, but lets take it step-by-step first. As before we calculate the decibel
power gain of the filter.
a 2 2 1 i
H a i e
b2 2 1
a2 2 1
PdB 10 log10 2 2 (15)
b 1
Then as before we derive a formula that relates the 3 dB corner and the time constant
together.
2 By formula 15.
b 2 1 1
2
a 2b 2 2 (16)
a 2 1 2 1
PdB 1 10 log 10 2 By formula 15.
b 1 2
1
a 1 1
2 2
a2
10 log10 2
10 log 10
b 2 3 As this is 3 dB less than maximum power.
b 1 2
1
b 2 a 2 1 2 1
10 log10 2 2 3
a b 1 2 1
b 2 a 2 1 1
2
2 2 1/ 2
a b 1 2 1
b 2 a 2 b 2 2
2 2 1 2
a b a 2 2
2b 2 2
a2
2 b2
2b 2 2
2b 2
2 2
By formula 16.
b2
2 4 8 2 2
b (17)
2
2 16 4 4 8 2 2
b As
2
b
2 4 4
4
2
2
2 4 4 4
b
2
b (18)
For the second method equations get kind of messy, but there's nothing really difficult
about them. As in the first transfer function we looked at, we calculate the rate of change
of gain of power in dB with respect to octaves as below.
d
PdB
20 ln 2 b 2 2 2
doct
ln 10 2b 2 2 2 2 1 b 2 2 1
By formula 15. (19)
Differentiate with respect to and set to zero to get the maximum rate of change than
solve for b.
d d
PdB
2 2
4 4
40 ln2 b 2b b 1
2 4 2
d doct
ln10 2b 2 2 2 2 1 b 2 2 1
2 2
d d
PdB 0
d doct
max b 2 2 2b 4
1 / 4
4
2 4 8 max
b (20)
2
The third method is really easy because looking at formula 15 the maximum power is the
following.
a2
PdBMAX 10 log10 2 By formula 15. (21)
b
PdBMAX 10
a 2 b 2 10
b By formula 16. (22)
PdBMAX 10
10 2
Evaluating A and B.
In FM stereo radio, at 19 kHz there is a pilot. Because of this pilot you must limit the
audio frequencies to somewhat less. 15 kHz seems to be a common stopping point. As I
said before for my calculations I'm going to use 50 µs pre-emphasis time constant.
Using the first method described above (formula 17) I need 1 something higher than
the frequencies I'm interested in. This being the case let the frequency be say 20 kHz.
1 2 20000
1 2 20000
7.958 10 6 s / rad
50 10 6 s / rad
b 7.772 10 6 By formula 17.
& a 51.19 10 6 By formula 16.
As formula 18 says, b and the comment just under formula 16 that a . It's always
interesting when things turn out to be so simple.
For the second method we need to choose a frequency where we want the steepest change
of power in dB with respect to octaves to happen. As our first transfer function could do
no better than 6 dB an octave, we will do worse with this transfer function because of the
added pole. So let's select the frequency to be somewhere in the middle, say 8 kHz.
Notice we get more or less the same values using this method as the last.
And finally for the last method we choose the maximum gain that we are prepared to
cope with, let's say 17 dB.
PdBMAX 17 dB
b 7.208 10 6 By formula 22.
& a 51.03 10 6 By formula 16.
So there we have it, three different ways of evaluating these pesky constants. Method one
is probably the most useful because of the approximations that can be made. However,
I'm sure the other two methods have their own merit.
X R1 R2
V
C
YX
C R1 R2 s 1
CR2 s 1
I calculated the transfer function the same way as I did in formulas 11 to 13.
H a s
C R1 R2 s 1 (25)
CR2 s 1
This is formula 14 with a C R1 R2 , and b CR2 . As my main goal is to implement
this transfer function digitally, the analog implementation is not of great concern to me.
However, while we here we might as well model it on the computer.
Choosing the capacitor C 4.7 nF and a and b from the first method described
previously, I get R1 9.2 K and R2 1.6 K . As I know 10 K and 1.5 K resistors exist I'll
use these as approximations. Using the following component values and a general-
purpose audio opamp, I get the plot in figure 6.
C 4.7 nF
R1 10 K
R2 1.5K
This looks reasonably acceptable. Well, enough of this analog stuff let's convert what we
know about this filter into a digital implementation.
Real 1,0
1,
Real
0,0
Relationship between the points are z e sT where T is sample period. What I mean by
the relationship between the two planes, is the following. If we have a time continuous
function in the time domain and perform the Laplace transform on it, we get the points of
the S plane. Now, if we sampled this same time continuous function in the time domain at
intervals T 1 f s and performed the Z transformation on this, we would get the points in
the Z plane. This is what I mean by the points are related by z e sT . This relationship
can be shown by the following. First we calculate the Laplace transform of a sampled
function xt . Once sampled the function becomes T t xt . Where T t is a Dirac
comb that plucks out the sampled values in xt .
T t t nT Dirac comb.
n 0
X s t xt e
st
T dt By definition the Laplace transform of the sampled function.
X s t nT xt e
st
dt By def of Dirac comb.
n 0
X s t nT xt e dt
st
n 0
X s xnT e
snT
Dirac delta plucking out one value.
n 0
X s xn e Defining xn xnT discrete set.
snT
n 0
e sT
n
X s xn
n 0
X z xnz n By definition of the Z transform.
n 0
z e sT
z e sT
T i T
ze e
T
T
&r e
Where is the angle the point z in the Z plane makes with the real axis, and r the
distance from the center of the circle.
The most important line is the imaginary axis line in the S plane and the unit circle in the
Z plane. This line or the circle contain everything you need to know about the frequency
response of the filter. Also note frequencies like f s , 2f s , etc radians get mapped
to the same point in the Z plane.
The idea now is to transform our transfer function from the S plane to the Z plane, then
perform the inverse Z transform to get a discrete function. This is the function that
actually performs the filtering on the computer.
z e sT Known relationship.
z e sT / 2 e sT / 2
e sT / 2
z sT / 2
e
1 sT / 2 ...
z Taylor expansion.
1 sT / 2 ...
1 sT / 2
z First order approximation.
1 sT / 2
z zsT / 2 1 sT / 2
z 1 zsT / 2 sT / 2
z 1 s z 1
2
T
2 z 1
s
T z 1
2 z 1
s : Bilinear transformation (http://en.wikipedia.org/wiki/Bilinear_transform)
T z 1
This approximation is just what we need. It's called the bilinear transform. Firstly it's a
relatively simple approximation of 1 T ln z with nothing but a couple of linear
polynomials. Secondly, clearly any point in the Z plane only comes from one point in the
S plane, unlike s 1 T ln z .
Let's have a look how frequencies now appear in each plane.
iT
For probing frequencies under the Z transform we use e whilst probing frequencies
under the Laplace transform we use i . Now, how does our newly acquired digital filter
respond to a frequency of if given such a signal? Take the point z in the Z plane that
i T
lies on the unit circle and has an angle of T , i.e. e . To determine where this point
came from before the bilinear transformation we do the following.
2 z 1
Let s Making the bilinear transformation approximation.
T z 1
i T
2 e 1
s Evaluating on the unit circle.
T eiT 1
s
2 e 1e
i T i T / 2
T e 1e
iT i T / 2
2
i T / 2 iT / 2
e
s e
T e i T / 2
e
iT / 2
2 2i
i T / 2 iT / 2
e
s e
T e i T / 2
e
iT / 2
2i
2 e 2
iT / 2 iT / 2
e
si
T e iT / 2
e
iT / 2
2i
2 T
si tan
T 2
2 T
a tan As was in the form of probing the analog frequency. (26)
T 2
2 T
tan 1 a
T 2
This means under this transformation the digital filter responds at as the analog filter
responded at a . Because of the tangent function, low frequencies will tend to be fairly
linear but the high frequencies will be compressed and hence distorted and warped. We
can correct for this at frequencies that we can control in the design off the analog filter.
It's called pre-warping. Figure 8 shows in an intuitive way how we do this.
a a
pa
So to select any frequency in our analog filter we do not choose it directly, but use
formula 26 and plug in for our desired frequency and use a in our analog filter
design.
Now we perform the bilinear transform on our transfer function formula 14.
a s 1
H a s From formula 14.
b s 1
2 z 1
a 1
T z 1
H d z Bilinear transform.
2 z 1
b 1
T z 1
2a z 1 T z 1
H d z
2bz 1 T z 1
2az 2a Tz T
H d z
2bz 2b Tz T
H d z
2a T z T 2a
2b T z T 2b
H d z
2a T T 2a z 1 (27)
2b T T 2b z 1
This is our transfer function of our digital filter. Using the Z transform’s timeshifting
property, and definition of the transfer function, we can write the digital filter in a
recursion relation by performing an inverse Z transform.
Y z 2a T T 2a z 1
From formula 27.
X z 2b T T 2b z 1
Y z 2b T z 1Y z T 2b X z 2a T z 1 X z T 2a
y[n]2b T y[n 1]T 2b x[n]2a T x[n 1]T 2a Inverse Z transform.
y[n]
2a T x[n] T 2a x[n 1] 2b T y[n 1] (28)
2b T 2b T 2b T
y[n] a 0 x[n] a1 x[n 1] b1 y[n 1] (29)
a 0 a1 z 1
H d z
1 b1 z 1
Formula 28 (or 29) is the recursion relation that actually does the filtering on the
computer.
T T
P cot Pre-warping .
2 2
T T
P cot Pre-warping .
2 2
P2 P4 8 P2 2
bP
P
By formula 17.
2
& a P 2bP2 P2 By formula 16.
a0
2a P T By formula 28 & 29.
2bP T
& a1
T 2a P By formula 28 & 29.
2bP T
& b1
2bP T By formula 28 & 29.
2bP T
For my implementation on the computer, I will be using a soundcard sampling at 192000
times a second. I think that 1 / corresponding to 20 kHz should be acceptable in my
setup. Plugging in the numbers, table 1 is what I get.
fs 192,000 samples / s
50 10 6 s / rad
7.96 10 6 s / rad
T 5.21 10 6 s / sample
P 49.95 10 6 s / rad
P 7.67 10 6 s / rad
bP 7.50 10 6
aP 51.07 10 6
a0 5.30986
a1 4.79461
b1 0.48475
Table 1: Calculated values for a time constant of 50 µs, a 1 / corresponding to 20 kHz,
and a sample rate of 192,000 samples a second.
Figure 9 shows the gain and phase response of the digital filter.
H d z
Im
Figure 10: Contour plot of the magnitude of the digital transfer function.
All that remains is to write a routine to implement this. Listing 1 shows a C++ program
code snippet for doing the filtering. The update part of the code must be run once a
sample.
Figure 11: Real-life white noise test of the IIR pre-emphasis filter.
All things being equal figure 11 is a relatively good match with figure 9. As always with
an implementation, when actual results correlate well with theoretical models, then, that's
good.
Jonti.
22/4/10