DSPRelated.com
Forums

Mysterious gain when designing a butterworth filter in MATLAB

Started by Sam November 25, 2009
For a high order filter, if I make Wn too small, I get an inexplicable
gain term on the resulting filter. I am trying to use zpk form and
then go to second orders sections. It works, but only sometimes.
Here's an example:

% This gives me a filter of gain 100 dB and I have no idea why?
[z,p,k] = butter(n,.1);
[sos,g] = zp2sos(z,p,k);
Hd1 = dfilt.df2sos(sos,g);
fvtool(Hd1)

% But this gives me a gain of 0 dB, as expected
[z,p,k] = butter(n,.2);
[sos,g] = zp2sos(z,p,k);
Hd2 = dfilt.df2sos(sos,g);
fvtool(Hd2)


Does anyone know the reason for this?

thanks,

-Sam
On 26 Nov, 03:09, Sam <samke...@gmail.com> wrote:
> For a high order filter, if I make Wn too small, I get an inexplicable > gain term on the resulting filter.
You don't show all the commands for the design, but there are two possible reasons: 1) Numerical errors 2) Flawed design parameters Since you use matlab you work with double-precision floating point numbers, so one can at the outset disregard numerical errors, and look at the design parameters. In a good design algorithm, all you provide to the algorithm is the filter specification. Everything else is derived throughout the algorithm, so there is no reason for you to mess around with the internal variables to the design procedure. What you need to do, then, is to find out the commands needed to get from the spec to the filter coefficients. All the internal variables can be computed. Rune
On Nov 26, 3:09=A0pm, Sam <samke...@gmail.com> wrote:
> For a high order filter, if I make Wn too small, I get an inexplicable > gain term on the resulting filter. I am trying to use zpk form and > then go to second orders sections. It works, but only sometimes. > Here's an example: > > % This gives me a filter of gain 100 dB and I have no idea why? > [z,p,k] =3D butter(n,.1); > [sos,g] =3D zp2sos(z,p,k); > Hd1 =3D dfilt.df2sos(sos,g); > fvtool(Hd1) > > % But this gives me a gain of 0 dB, as expected > [z,p,k] =3D butter(n,.2); > [sos,g] =3D zp2sos(z,p,k); > Hd2 =3D dfilt.df2sos(sos,g); > fvtool(Hd2) > > Does anyone know the reason for this? > > thanks, > > -Sam
Try multiplying the output by 0.00001
On Nov 25, 9:09=A0pm, Sam <samke...@gmail.com> wrote:
> For a high order filter, if I make Wn too small, I get an inexplicable > gain term on the resulting filter. I am trying to use zpk form and > then go to second orders sections. It works, but only sometimes. > Here's an example: > > % This gives me a filter of gain 100 dB and I have no idea why? > [z,p,k] =3D butter(n,.1); > [sos,g] =3D zp2sos(z,p,k); > Hd1 =3D dfilt.df2sos(sos,g); > fvtool(Hd1) > > % But this gives me a gain of 0 dB, as expected > [z,p,k] =3D butter(n,.2); > [sos,g] =3D zp2sos(z,p,k); > Hd2 =3D dfilt.df2sos(sos,g); > fvtool(Hd2) > > Does anyone know the reason for this? > > thanks, > > -Sam
Sorry, I forgot the order of the filter. If I set n =3D 24; The first filter gives me a gain of 100 dB, the 2nd gives me a gain of zero. I was under the impression all IIR filter designs should have a gain of 0 dB in the passband. Is that not the case? -Sam

Sam wrote:
> On Nov 25, 9:09 pm, Sam <samke...@gmail.com> wrote: > >>For a high order filter, if I make Wn too small, I get an inexplicable >>gain term on the resulting filter. I am trying to use zpk form and >>then go to second orders sections. It works, but only sometimes. >>Here's an example: >> >>% This gives me a filter of gain 100 dB and I have no idea why? >>[z,p,k] = butter(n,.1); >>[sos,g] = zp2sos(z,p,k); >>Hd1 = dfilt.df2sos(sos,g); >>fvtool(Hd1) >> >>% But this gives me a gain of 0 dB, as expected >>[z,p,k] = butter(n,.2); >>[sos,g] = zp2sos(z,p,k); >>Hd2 = dfilt.df2sos(sos,g); >>fvtool(Hd2) >> >>Does anyone know the reason for this? >> >>thanks, >> >>-Sam > > > Sorry, I forgot the order of the filter. If I set > > n = 24; > > The first filter gives me a gain of 100 dB, the 2nd gives me a gain > of zero. I was under the impression all IIR filter designs should have > a gain of 0 dB in the passband. Is that not the case?
Butterworth of the 24th order is ridiculous. You are very likely to run into numeric precision issues. "Matlab does all thinking for us" (TM) VLV
On Nov 26, 10:00=A0am, Vladimir Vassilevsky <nos...@nowhere.com> wrote:
> Sam wrote: > > On Nov 25, 9:09 pm, Sam <samke...@gmail.com> wrote: > > >>For a high order filter, if I make Wn too small, I get an inexplicable > >>gain term on the resulting filter. I am trying to use zpk form and > >>then go to second orders sections. It works, but only sometimes. > >>Here's an example: > > >>% This gives me a filter of gain 100 dB and I have no idea why? > >>[z,p,k] =3D butter(n,.1); > >>[sos,g] =3D zp2sos(z,p,k); > >>Hd1 =3D dfilt.df2sos(sos,g); > >>fvtool(Hd1) > > >>% But this gives me a gain of 0 dB, as expected > >>[z,p,k] =3D butter(n,.2); > >>[sos,g] =3D zp2sos(z,p,k); > >>Hd2 =3D dfilt.df2sos(sos,g); > >>fvtool(Hd2) > > >>Does anyone know the reason for this? > > >>thanks, > > >>-Sam > > > Sorry, I forgot the order of the filter. If I set > > > n =3D 24; > > > The first filter gives me a gain of =A0100 dB, the 2nd gives me a gain > > of zero. I was under the impression all IIR filter designs should have > > a gain of =A00 dB in the passband. Is that not the case? > > Butterworth of the 24th order is ridiculous. You are very likely to run > into numeric precision issues. > > "Matlab does all thinking for us" (TM) > > VLV
Why then can I design a 24th order filter with FDA tool and not have this problem?
On Nov 26, 10:39=A0am, Sam <samke...@gmail.com> wrote:
>... > > Why then can I design a 24th order filter with FDA tool and not have > this problem?
How would you know if you have a problem? Could "100dB" be considered a possible hint? Dale B. Dalrymple
On Nov 26, 4:05=A0pm, dbd <d...@ieee.org> wrote:
> On Nov 26, 10:39=A0am, Sam <samke...@gmail.com> wrote: > > >... > > > Why then can I design a 24th order filter with FDA tool and not have > > this problem? > > How would you know if you have a problem? > > Could "100dB" be considered a possible hint? > > Dale B. Dalrymple
I guess I'm not making myself very clear... I design a filter using the butter function, implement it in second order sections DF2 form. If I do this in MATLAB, I get a filter which inexplicably has a 100 dB gain, even though otherwise its fine. If I design a filter with the same exact specs using FDATOOL, I get the filter I expect without the 100 dB gain. Why can FDATOOL do it if I can't? -Sam
On 27 Nov, 00:16, Sam <samke...@gmail.com> wrote:

> Why can FDATOOL do it if I can't?
Because whoever implemented FDATOOL took the time to read up on, contemplate and investigate the principles, algorithms and procedures used in filter design. Rune
On Nov 26, 7:46=A0pm, Rune Allnor <all...@tele.ntnu.no> wrote:
> On 27 Nov, 00:16, Sam <samke...@gmail.com> wrote: > > > Why can FDATOOL do it if I can't? > > Because whoever implemented FDATOOL took the time to > read up on, contemplate and investigate the principles, > algorithms and procedures used in filter design. > > Rune
So you mean to tell me that if I design a filter with exactly the same specifications in FDATOOL as at the command line, I should simply accept that they give different results for no apparent reason? Because the people who wrote FDATOOL are so much more enlightened than I? The two filters have exactly the same frequency shape, however one has a large gain and the other does not. I would like to understand why, if you cannot help me to do so, you need not be rude. thanks, -Sam