Forums

IIR filter coefficient quantization newbie

Started by Alxpert May 11, 2005
I designing a IIR digital filter with the following parameters (Fs =
500k,fc = 1k,fs = 10k,wc = 1db,ws = 40db} using matlab. And I got the
following coefficient using the following .m file.

      A1        A2        B2        B0        B1
 { -1.9725    0.9733    0.0001    0.0001    0.0001
   -0.9733         0         0    0.0475    0.0475 }

Fs = 500000;
fc = 1000;
fs = 10000;
Rp = 1;
Rs = 40;
Wp = 2*fc/Fs;
Ws = 2*fs/Fs;
[N,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(N,Wn);
[Z,P,K] = tf2zp(b,a);
[sos] = zp2sos(Z,P,K,'DOWN',2);

Those coefficient are working really fine in the simulator
(TMS320C55xx) in a floating point function. But as soon as I try to use
those coefficient in a dsplib function with quantization (Q14) I get
some weird result that as nothing to do with the one I got from the
previous test (float). Since my DSP in fixed point I need to quantized
my coefficient to be able to use them in the dsplib but again I'm not
sure if I do the right thing. My input value can be between 32767 > x <
-32768 and I can offort to have overflow.

I tryed the coefficient with DC and sinus value and it really work the
way I expect it to work but not after quantization.

I'm not sure excatly what I should be doing cause one of my coefficient
as a value that is bigger then the one supported by Q15 (1 > c > -1),
and the dsplib function use Q15 !

Again I'm a newbie in all this!

Anybody as an idea ?

Alex

Alxpert wrote:

> I designing a IIR digital filter with the following parameters (Fs = > 500k,fc = 1k,fs = 10k,wc = 1db,ws = 40db} using matlab. And I got the > following coefficient using the following .m file. > > A1 A2 B2 B0 B1 > { -1.9725 0.9733 0.0001 0.0001 0.0001 > -0.9733 0 0 0.0475 0.0475 } > > Fs = 500000; > fc = 1000; > fs = 10000; > Rp = 1; > Rs = 40; > Wp = 2*fc/Fs; > Ws = 2*fs/Fs; > [N,Wn] = buttord(Wp,Ws,Rp,Rs); > [b,a] = butter(N,Wn); > [Z,P,K] = tf2zp(b,a); > [sos] = zp2sos(Z,P,K,'DOWN',2); > > Those coefficient are working really fine in the simulator > (TMS320C55xx) in a floating point function. But as soon as I try to use > those coefficient in a dsplib function with quantization (Q14) I get > some weird result that as nothing to do with the one I got from the > previous test (float). Since my DSP in fixed point I need to quantized > my coefficient to be able to use them in the dsplib but again I'm not > sure if I do the right thing. My input value can be between 32767 > x < > -32768 and I can offort to have overflow. > > I tryed the coefficient with DC and sinus value and it really work the > way I expect it to work but not after quantization. > > I'm not sure excatly what I should be doing cause one of my coefficient > as a value that is bigger then the one supported by Q15 (1 > c > -1), > and the dsplib function use Q15 ! > > Again I'm a newbie in all this! > > Anybody as an idea ? >
Several. 1. You can implement your gain of 1.9725 as (signal + 0.9725 * signal). 2. If your data needs to be good to 16 bits then your intermediate values must be, at the bare minimum, good to an additional -log_2(1 - 0.9733) = 5.2 bits. Round this up to 32-bit intermediate values. 3. If you use one of the direct form filter functions with a difference equation that features of y_n = (1.9725)*y_{n-1} - (0.9733)*y{n-2} you need to have your gains good enough to distinguish 1 - (1 - 0.9733)^2 from 1, or at least 11 bits. You're mostly covered there, although your rolloff will be slightly different than planned. ------------------------------------------- Tim Wescott Wescott Design Services http://www.wescottdesign.com
I think you run into a typical issue related to coefficient
sensitivity. It is caused by a low ratio between your fc, fs to Fs.
Even when you use floating point processing this issue still exist to
some extend.

A good solution is to decimate the incoming data series first then you
apply the filter. Say you decimate the data (you must apply low pass
filter when you decimate them) with a ratio of 1 to 8. Then the
sampling rate was reduced from 500k to 62.5kHz. The problem will be
resolved.

Good luck!