Thread Subject: How to get [b,a] from fdesign

Subject: How to get [b,a] from fdesign

From: CFY30 CFY30

Date: 26 Aug, 2008 20:28:02

Message: 1 of 4

Hi,
  
   Consider,

Hf = fdesign.lowpass('Fp,Fst,Ap,Ast', Fp, Fst, Ap, Ast, Fs);
He = design(Hf,'ellip');

   How can I get the [b,a] from He?


Thanks,
cfy30

Subject: How to get [b,a] from fdesign

From: vincent pellissier

Date: 26 Aug, 2008 21:28:38

Message: 2 of 4

Hi cfy30,

 > How can I get the [b,a] from He?
[b,a] = tf(He);

Notice that it is good practice to always keep an IIR design in
second-order sections and avoid computing the transfer function explicitly.

The reason is that forming the transfer function involves polynomial
multiplication, or equivalently convolution of the polynomial
coefficients. Convolution can introduce significant round-off error even
with double precision floating-point arithmetic. This is mainly due to
additions of large numbers with small numbers (that become negligible
when using finite precision arithmetic).

Of course the effect gets worse as the filter order increases since we
are performing more and more convolutions. For low-order designs, it is
not absolutely necessary to use second-order sections, but there still
may be good reasons to do so from an implementation perspective.

As a rather extreme example consider the following design where forming
the transfer function completely distorts the response of the filter and
even makes the filter unstable:

Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.47,.48,.05,120);
Hc = design(Hf,'cheby1');
[b,a] = tf(Hc);
hfvt = fvtool(Hc,b,a);
legend(hfvt,'Second-order sections','Transfer function')

hth,

-Vincent

---
CFY30 CFY30 wrote:
> Hi,
>
> Consider,
>
> Hf = fdesign.lowpass('Fp,Fst,Ap,Ast', Fp, Fst, Ap, Ast, Fs);
> He = design(Hf,'ellip');
>
> How can I get the [b,a] from He?
>
>
> Thanks,
> cfy30

Subject: How to get [b,a] from fdesign

From: CFY30 CFY30

Date: 26 Aug, 2008 23:52:02

Message: 3 of 4

Thanks Vincent! You must be reading my mind, the problem I
am now running into is, consider the code attached. When I
plot filter1(b1, a1) and filter(b2, a2) separately, they
are fine. But it messed up when I plot the convolution
product. Filter1(b1, a1) is generated by iirlpnorm, I am
trying to find the best fit of a filter measured on bench.
Filter2(b2, a2) is a 5th butterworth. Could you advise how
to make filter1 and filter2 in terms of second order
sections and avoid dealing with their transfer function
explicity?

Thanks,
cfy30

a1 = [ 1
         -6.41419043322137
          17.6015355703759
         -26.7828346053453
          24.4006169931508
         -13.3073107931446
          4.02157413370539
        -0.519390864551612];
        
b1 = [0.000398558959342733
       -0.00141046292089994
        0.00185609288512552
       -0.00107470934235147
       0.00023052105125844];
   
[h1, f1] = freqz(b1, a1, 1024);
figure;
plot(f1, 20*log10(h1), 'r');
hold on;

a2 = [ 1
          -4.6872228997567
          8.79724893069547
         -8.26385275520034
          3.88511080048537
        -0.731276830775834];
               
b2 = [ 2.26420248883308e-007
       1.13210124441654e-006
       2.26420248883308e-006
       2.26420248883308e-006
       1.13210124441654e-006
       2.26420248883308e-007];
             
[h2, f2] = freqz(b2, a2, 1024);
plot(f2, 20*log10(h2), 'b');
grid on;
set(gca ,'xscale', 'log');

a3 = conv(a1, a2);
b3 = conv(b1, b2);

figure;
[h3, f3] = freqz(b3, a3, 1024);
plot(f3, 20*log10(h3), 'b');
grid on;
set(gca ,'xscale', 'log');


Vincent Pellissier <vincentp@mathworks.com> wrote in
message <g91si6$323$1@fred.mathworks.com>...
> Hi cfy30,
>
> > How can I get the [b,a] from He?
> [b,a] = tf(He);
>
> Notice that it is good practice to always keep an IIR
design in
> second-order sections and avoid computing the transfer
function explicitly.
>
> The reason is that forming the transfer function involves
polynomial
> multiplication, or equivalently convolution of the
polynomial
> coefficients. Convolution can introduce significant round-
off error even
> with double precision floating-point arithmetic. This is
mainly due to
> additions of large numbers with small numbers (that
become negligible
> when using finite precision arithmetic).
>
> Of course the effect gets worse as the filter order
increases since we
> are performing more and more convolutions. For low-order
designs, it is
> not absolutely necessary to use second-order sections,
but there still
> may be good reasons to do so from an implementation
perspective.
>
> As a rather extreme example consider the following design
where forming
> the transfer function completely distorts the response of
the filter and
> even makes the filter unstable:
>
> Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.47,.48,.05,120);
> Hc = design(Hf,'cheby1');
> [b,a] = tf(Hc);
> hfvt = fvtool(Hc,b,a);
> legend(hfvt,'Second-order sections','Transfer function')
>
> hth,
>
> -Vincent
>
> ---
> CFY30 CFY30 wrote:
> > Hi,
> >
> > Consider,
> >
> > Hf = fdesign.lowpass('Fp,Fst,Ap,Ast', Fp, Fst, Ap, Ast,
Fs);
> > He = design(Hf,'ellip');
> >
> > How can I get the [b,a] from He?
> >
> >
> > Thanks,
> > cfy30

Subject: How to get [b,a] from fdesign

From: CFY30 CFY30

Date: 27 Aug, 2008 20:07:02

Message: 4 of 4

Hi Vincent,

   I figured it out already. My solution is to use tf2sos
and df2sos to create the objects. Thanks for your help.


cfy30

"CFY30 CFY30" <cfy30@yahoo.com> wrote in message <g924v2$i70
$1@fred.mathworks.com>...
> Thanks Vincent! You must be reading my mind, the problem
I
> am now running into is, consider the code attached. When
I
> plot filter1(b1, a1) and filter(b2, a2) separately, they
> are fine. But it messed up when I plot the convolution
> product. Filter1(b1, a1) is generated by iirlpnorm, I am
> trying to find the best fit of a filter measured on
bench.
> Filter2(b2, a2) is a 5th butterworth. Could you advise
how
> to make filter1 and filter2 in terms of second order
> sections and avoid dealing with their transfer function
> explicity?
>
> Thanks,
> cfy30
>
> a1 = [ 1
> -6.41419043322137
> 17.6015355703759
> -26.7828346053453
> 24.4006169931508
> -13.3073107931446
> 4.02157413370539
> -0.519390864551612];
>
> b1 = [0.000398558959342733
> -0.00141046292089994
> 0.00185609288512552
> -0.00107470934235147
> 0.00023052105125844];
>
> [h1, f1] = freqz(b1, a1, 1024);
> figure;
> plot(f1, 20*log10(h1), 'r');
> hold on;
>
> a2 = [ 1
> -4.6872228997567
> 8.79724893069547
> -8.26385275520034
> 3.88511080048537
> -0.731276830775834];
>
> b2 = [ 2.26420248883308e-007
> 1.13210124441654e-006
> 2.26420248883308e-006
> 2.26420248883308e-006
> 1.13210124441654e-006
> 2.26420248883308e-007];
>
> [h2, f2] = freqz(b2, a2, 1024);
> plot(f2, 20*log10(h2), 'b');
> grid on;
> set(gca ,'xscale', 'log');
>
> a3 = conv(a1, a2);
> b3 = conv(b1, b2);
>
> figure;
> [h3, f3] = freqz(b3, a3, 1024);
> plot(f3, 20*log10(h3), 'b');
> grid on;
> set(gca ,'xscale', 'log');
>
>
> Vincent Pellissier <vincentp@mathworks.com> wrote in
> message <g91si6$323$1@fred.mathworks.com>...
> > Hi cfy30,
> >
> > > How can I get the [b,a] from He?
> > [b,a] = tf(He);
> >
> > Notice that it is good practice to always keep an IIR
> design in
> > second-order sections and avoid computing the transfer
> function explicitly.
> >
> > The reason is that forming the transfer function
involves
> polynomial
> > multiplication, or equivalently convolution of the
> polynomial
> > coefficients. Convolution can introduce significant
round-
> off error even
> > with double precision floating-point arithmetic. This
is
> mainly due to
> > additions of large numbers with small numbers (that
> become negligible
> > when using finite precision arithmetic).
> >
> > Of course the effect gets worse as the filter order
> increases since we
> > are performing more and more convolutions. For low-
order
> designs, it is
> > not absolutely necessary to use second-order sections,
> but there still
> > may be good reasons to do so from an implementation
> perspective.
> >
> > As a rather extreme example consider the following
design
> where forming
> > the transfer function completely distorts the response
of
> the filter and
> > even makes the filter unstable:
> >
> > Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.47,.48,.05,120);
> > Hc = design(Hf,'cheby1');
> > [b,a] = tf(Hc);
> > hfvt = fvtool(Hc,b,a);
> > legend(hfvt,'Second-order sections','Transfer function')
> >
> > hth,
> >
> > -Vincent
> >
> > ---
> > CFY30 CFY30 wrote:
> > > Hi,
> > >
> > > Consider,
> > >
> > > Hf = fdesign.lowpass('Fp,Fst,Ap,Ast', Fp, Fst, Ap,
Ast,
> Fs);
> > > He = design(Hf,'ellip');
> > >
> > > How can I get the [b,a] from He?
> > >
> > >
> > > Thanks,
> > > cfy30
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com