HOME

PDF letter size

IIR digital filter design for low pass filter based on impulse invariance and bilinear transformation methods using butterworth analog filter

Nasser M. Abbasi

May 5, 2010   Compiled on January 30, 2024 at 6:45am

Contents

1 Introduction
1.1 Filter specifications
2 The design steps
2.1 Impulse invariance method
2.2 Bilinear transformation method
2.3 Summary of analytical derivation method
3 Numerical design examples
3.1 Example 1
3.1.1 using impulse invariance method (using T=1)
3.1.2 Bilinear method
3.2 Example 2
3.2.1 using impulse invariance method
3.2.2 Using bilinear
4 IIR design for minimum order filter
4.1 Impulse invariance method
4.2 bilinear transformation method
5 Appendix
5.1 Code listing
5.2 Sample run output
6 References

A low pass digital filter (IIR) is designed based on given specifications. Butterworth analog filter H(s) is designed first, then it is converted to digital filter H(z)

Analytical procedure is illustrated below and simplified to allow one to more easily program the algorithm. Four different numerical examples are used to illustrate the procedure.

1 Introduction

This report derives a symbolic procedure to design a low pass IIR digital filter from an analog Butterworth filter using 2 methods: impulse invariance and bilinear transformation. Two numerical examples are used to illustrate using the symbolic procedure.

There are a total of 13 steps. A Mathematica program with GUI is written to enable one to use this design for different parameters. A Matlab script is written as well.

1.1 Filter specifications

Filter specifications are 5 parameters. The frequency specifications use analog frequencies, while the attenuation for the passband and the stopband are given in db units.

Fs The sampling frequency in Hz
fc The passband cutoff frequency in Hz
fs The stopband corner frequency in Hz
δp The attenuation in db at fc
δs The attenuation in db at fs

This diagram below illustrates these specifications

The frequency specifications are in hz, and they are first converted to digital frequencies ω where 0|ω|π before using the attenuation specifications. The sampling frequency Fs is used to do this conversion where Fs corresponds to 2π on the digital frequency scale.

2 The design steps

  1. Specifications are converted from analog to digital frequencies.
  2. Based on design method (impulse invariance of bilinear) the attenuation criteria is applied to determine Ωc and N (the filter order).
  3. Using Ωc and N the locations of the poles of the butterworth analog filter H(s) are found.
  4. H(z) is determined from H(s). The method of doing this depends if impulse invariance or bilinear is used. This step is much simpler for the bilinear method as it does not require performing partial fractions decomposition on H(s).

The analytical design procedure is given below.

2.1 Impulse invariance method

Analog specifications is converted to digital specifications: Fs2π=fpωp, hence ωp=2πfpFs and ωs=2πfsFs. Next, the criteria relative to the digital normalized scale is found20log|H(ejωp)|δp20log|H(ejωs)|δs

Therefore(A)|H(ejωp)|10δp20T(B)|H(ejωs)|10δs20T

Notice that T scaling factor was added above. The Butterworth analog filter squared magnitude Fourier transform is given by|Ha(jΩ)|2=T21+(jΩjΩc)2N Equations (A) and (B) above are now written in terms of the analog Butterworth amplitude frequency response givingT21+(ΩpΩc)2N(10δp20)2T2T21+(ΩsΩc)2N(10δs20)2T2

Hence11+(ΩpΩc)2N 10δp1011+(ΩsΩc)2N10δs10

For impulse invariance, Ωp=ωpT  and Ωs=ωsT.  Therefore(1)1+(ωp/TΩc)2N10δp10(2)1+(ωs/TΩc)2N10δs10

Changing inequalities to equalities and simplifying gives(ωp/TΩc)2N=10δp101(ωs/TΩc)2N=10δs101

Dividing the above two equations results in(ωpωs)2N=10δp10110δs1012N[log(ωp)log(ωs)]=log(10δp101)log(10δs101)N=12log[10δp101]log[10δs101]log(ωp)log(ωs)

The above is later rounded to the nearest integer using the Ceiling function N= N.

For impulse invariance method, using equation (1) above to solve for Ωc gives(ωp/TΩc)2N=10δp1012N(log10ωp/TΩc)=log10(10δp101)log10ωp/TΩc=12Nlog10(10δp101)ωp/TΩc=10(12Nlog10(10δp101))Ωc=ωp/T10(12Nlog10(10δp101))

Now that N and Ωc are found, next the poles of H(s) are determined. Since the butterworth magnitude square of the transfer function is |Ha(s)|2=T21+(sjΩc)2N Then H(s) poles are found by setting the denominator of the above to zero which gives1+(sjΩc)2N=0(sjΩc)2N=1=ej(π+2πk)     k=0,1,2,2N1sjΩc=ej(π+2πk2N)s=jΩc ej(π+2πk2N)=Ωc ejπ2ej(π+2πk2N)=Ωc ej(π(1+2k+N)2N)

Only the LHS poles needs to be found, and these are located at i=0N1. This is because these are the stable poles. Hence the ith pole is si=Ωc ej(π(1+2i+N)2N) For an, using i=0, N=6 givess0=Ωc ej(π(1+N)2N)=Ωc ej(π712)

Now the analog filter is generated based on the above selected poles, which for impulse invariance gives(3)Ha(s)=T Ki=0N1(ssi) K is found by solving Ha(0)=T which givesk=i=0N1(si)

The poles are written in non-polar form and substituted into (3) which gives

si=Ωc ej(π(1+2i+N)2N)=Ωc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)i=0N1 Therefore(4)Ha(s)=T Ki=0N1(sΩc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)) Where Ωc=ωp/T10(12Nlog10(10δp101)) AndN=12log[10δp101]log[10δs101]log(ωp)log(ωs) Now that H(s) is found, it is converted to H(z). We need to make sure that we multiply poles of complex conjugates with each others to make the result simple to see.

Now that Ha(s) is found, the AD conversion is done. This means to obtain H(z) from the above H(s). When using impulse invariance, partial fraction decomposition is performed on (4) above in order to write H(s) asH(s)=i=0N1Aissi For example, to obtain Aj the result isAj=limssjHa(s)=T ki=0ijN1(ssi) Once the As are found, then H(z) becomesH(z)=i=0N1Ai1exp(si T)z1 This completes the design. The above form of H(z) could also be converted to rational expression as H(z)=N(z)D(z).

2.2 Bilinear transformation method

First step is to convert analog specifications to digital specifications: Fs2π=fpωp, hence ωp=2πfpFs and ωs=2πfsFs

Converting the criteria relative to the digital normalized scale gives20log|H(ejωp)|δp20log|H(ejωs)|δs

Hence (A)|H(ejωp)|10δp20(B)|H(ejωs)|10δs20

Butterworth analog filter squared magnitude Fourier transform is given by|Ha(jΩ)|2=11+(jΩjΩc)2N Equations (A) and (B) above are now written in terms of the analog Butterworth amplitude frequency response and become11+(ΩpΩc)2N(10δp20)2= 10δp1011+(ΩsΩc)2N(10δs20)2=10δs10

Values for Ωp and Ωs are assigned as follows: Ωp=2Ttan(ωp2), Ωs=2Ttan(ωs2). Hence the above becomes

(1)1+(2Ttan(ωp2)Ωc)2N10δp10(2)1+(2Ttan(ωs2)Ωc)2N10δs10

Changing inequalities to equalities and simplifying gives(2Ttan(ωp2)Ωc)2N=10δp101(2Ttan(ωs2)Ωc)2N=10δs101

Dividing the above 2 equations results in(tan(ωp2)tan(ωs2))2N=10δp10110δs1012N[log(tan(ωp2))log(tan(ωs2))]=log(10δp101)log(10δs101)N=12log(10δp101)log(10δs101)log(tan(ωp2))log(tan(ωs2))

The above is rounded to the nearest integer using the Ceiling function. i.e. N= N.

For bilinear transformation equation (2) is used to find Ωc. Solving for Ωc gives1+(2Ttan(ωs2)Ωc)2N=10δs102N(log102Ttan(ωs2)Ωc)=log10(10δs101)log102Ttan(ωs2)Ωc=12Nlog10(10δs101)2Ttan(ωs2)Ωc=10(12Nlog10(10δs101))Ωc=2Ttan(ωs2)10(12Nlog10(10δs101))

Now that N and Ωc are found, the poles of H(s) can be determined. Since for bilinear the magnitude square of the transfer function is|Ha(s)|2=11+(sjΩc)2N Hence H(s) poles are found by setting the denominator of the above to zero 1+(sjΩc)2N=0(sjΩc)2N=1=ej(π+2πk)k=0,1,2,2N1sjΩc=ej(π+2πk2N)s=jΩc ej(π+2πk2N)=Ωc ejπ2ej(π+2πk2N)=Ωc ej(π(1+2k+N)2N)

Only need the LHS poles are needed, which are located at i=0N1, because these are the stable poles. Hence the ith pole is si=Ωc ej(π(1+2i+N)2N) For example for i=0, N=6 the result iss0=Ωc ej(π(1+N)2N)=Ωc ej(π712) For bilinear H(s) is given by(3)Ha(s)=Ki=0N1(ssi) K is found by solving Ha(0)=1 givingk=i=0N1(si) The same expression results for k in both cases. Writing poles in non-polar form and substituting them into (3) givessi=Ωc ej(π(1+2i+N)2N)=Ωc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)      i=0N1 Then(4)Ha(s)= Ki=0N1(sΩc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)) Where Ωc=2Ttan(ωs2)10(12Nlog10(10δs101)) AndN=12log10(10δp101)log10(10δs101)log10(tan(ωp2))log10(tan(ωs2)) Now that H(s) is found, it is converted to H(z). After finding H(s) as shown above then s is replaced by 2T1z11+z1. This is much simpler than the impulse invariance method. Before doing this substitution, we make sure to multiply poles which are complex conjugate of each others in the denominator of H(s). After this, then the above substitution is made.

2.3 Summary of analytical derivation method

Table with the derivation equations is made to follow to design in either bilinear or impulse invariance. Note that the same steps are used in both designs except for step 5,6,8,13. This table make it easier to develop a program for the implementation

.

step Impulse invariance common equation bilinear
1 ωp=2πfpFs
2 ωs=2πfsFs
3 αp=110δp10
4 αs=110δs10
5 Ωp=ωpT 2Ttan(ωp2)
6 Ωs=ωsT 2Ttan(ωs2)
7 N=12log[αp1]log[αs1]log(Ωp)log(Ωs)
8 Ωc=Ωp10(12Nlog10[αp1]) Ωc=Ωs10(12Nlog10[αs1])
9 poles of H(S) si=Ωc ej(π(1+2i+N)2N)i=0N1
10 k=i=0N1(si)
11 Ha(s)=T Ki=0N1(ssi) Ha(s)=Ki=0N1(ssi)
do partial fractions:
12 Ha(s)=i=0N1Aissi
13 H(z)=i=0N1Ai1exp(Tsi)z1 H(z)=Ha(s)|s=2T1z11+z1

3 Numerical design examples

3.1 Example 1

Sampling frequency Fs=20khz, passband frequency fp=2khz, stopband frequency fs=3khz, with δp1db and δstop15db

3.1.1 using impulse invariance method (using T=1)

step Impulse invariance
1 ωp=2πfpFs 2π(2000)200000.2π
2 ωs=2πfsFs2π(3000)200000.3π
3 αp=110δp10110110 1.2589
4 αs=110δs101101510 31.623
5 Ωp=ωpTωp10.2π
6 Ωs=ωsT0.3π10.3π
7 N=12log[αp1]log[αs1]log(Ωp)log(Ωs)12log10(1.25891)log10(31.6231)log10(0.2π)log10(0.3π) 5.88596
8 Ωc=Ωp10(12Nlog10[αp1])0.2π10(12×6log10(1.25891)) 0.70321
9 poles of H(S) si=Ωc ej(π(1+2i+N)2N)si=0.70321 ej(π(7+2i)12)i=05
s0=0.182+j0.67925,s1=0.49724+j0.4972,s2=0.67925+j0.182
s3=0.67925j0.182,s4=0.49724j0.49724,s5= 0.182j0.67925
10 k=i=0N1(si)(0.182j0.67925)(0.49724j0.49724)(0.67925j0.182)
(0.67925+j0.182)(0.49724+j0.49724)(0.182+j0.67925)0.12092
11 Ha(s)=T Ki=0N1(ssi)
1×0.12092(s+0.182j0.67925)(s+0.49724j0.49724)(s+0.67925j0.182)(s+0.67925+j0.182)(s+0.49724+j0.49724)(s+0.182+j0.67925)
multiply complex conjugates0.12092(s2+0.364s+0.4945)(s2+0.99448s+0.49450)(s2+1.3585s+0.4945)
0.12092s6+2.7170s5+3.6910s4+3.1789s3+1.8252s2+0.66438s+0.12092
12 partial fraction Ha(s)=i=0N1Aissi0.14354+j0.24861s+0.182j0.679251.0714j1.1668×105s+0.49724+j0.49724+0.92785j1.6071s+0.67925j0.182
+0.92785+j1.6071s+0.67925+j0.1821.0714+j1.1668×105s+0.49724j0.49724+0.14354j0.24861s+0.182+j0.67925
13 H(z)=i=0N1Ai1exp(Tsi)z10.14354+j0.248611exp(0.182+j0.67925)z1
1.0714j1.1668×1051exp(0.49724j0.49724)z1+0.92785j1.60711exp(0.67925+j0.182)
+0.92785+j1.60711exp(0.67925j0.182)z11.0714+j1.1668×1051exp(0.49724+j0.49724)z1+0.14354j0.248611exp(0.182j0.67925)z1
H(z)=0.14354+j0.248611(0.64858+j0.52368)z1 1.0714j1.1668×1051(0.53455j0.29012)z1+0.92785j1.60711(0.49862+j9.1765×102)z1
+0.92785+j1.60711(0.49862j9.1765×102)z11.0714+j1.1668×1051(0.53455+j0.29012)z1 +0.14354j0.248611(0.64858j0.52368)z1

3.1.2 Bilinear method

Using the above design table, these are the numerical values: T=1Fs=120000

step Bilinear
1 ωp=2πfpFs 2π(2000)200000.2π
2 ωs=2πfsFs2π(3000)200000.3π
3 αp=110δp10110110 1.2589
4 αs=110δs101101510 31.623
5 Ωp=2Ttan(ωp2)2×20000tan(0.2π2)12997
6 Ωs=2Ttan(ωs2)2×20000tan(0.3π2)20381
7 N=12log[αp1]log[αs1]log(Ωp)log(Ωs)12log10(1.25891)log10(31.6231)log10(12997)log10(20381) 5.30486
8 Ωc=Ωs10(12Nlog10[αs1])2038110(12×6log10(31.6231)) 15325.6
9 poles of H(S) si=Ωc ej(π(1+2i+N)2N)si=15325 ej(π(7+2i)12)i=05
s0=3966.4+j14803,s1=10836+j10836.,s2=14803+j3966.4
s3=14803j3966.4,s4=10836j10836.,s5=3966.4j14803
10 k=i=0N1(si)(3966.4j14803)(10836j10836)(14803j3966.4)
(14803+j3966.4)(10836+j10836)(3966.4+j14803)
 multiply complex conjugate terms
(2.3486×108)(2.3484×108) (2.3486×108) 1.2954×1025
11 Ha(s)=Ki=0N1(ssi)
1.2954×1025(s+3966.4j14803)(s+10836j10836)(s+14803j3966.4)(s+14803+j3966.4)(s+10836+j10836)(s+3966.4+j14803)
 multiply complex conjugate
1.2954×1025(s2+7932.8s+2.3486×108)(s2+21672s+234837792)(s2+29606.s+2.3486×108)
=6257.4s1.3558×108s2+7932.8s+2.3486×10846702.s+5.0604×108s2+21672.s+2.3484×108+40445.s+8.7654×108s2+29606.s+2.3486×108
1.2954×1025s6+59211.s5+1.7530×109s4+3.2902×1013s3+4.1169×1017s2+3.2658×1021s+1.2953×1025
12
13 H(z)=Ha(s)|s=2T1z11+z1TODO

3.2 Example 2

Sampling frequency Fs=10khz, passband corner frequency fp=1khz, stopband corner frequency fs=2khz, with criteria δp3db and δstop10db

3.2.1 using impulse invariance method

T=1

step Impulse invariance
1 ωp=2πfpFs 2π(1000)100000.2π
2 ωs=2πfsFs2π(2000)100000.4π
3 αp=110δp10110310 1.9953
4 αs=110δs101101010 10.0
5 Ωp=ωpTωp10.2π
6 Ωs=ωsT0.4π10.4π
7 N=12log[αp1]log[αs1]log(Ωp)log(Ωs)12log10(1.99531)log10(10.01)log10(0.2π)log10(0.4π) 1.5884 2
8 Ωc=Ωp10(12Nlog10[αp1])0.2π10(12×2log10(1.99531)) 0.62906
9 poles of H(S) si=Ωc ej(π(1+2i+N)2N)si=0.62906 ej(π(3+2i)4)  i=01
s0=0.44481+j0.44481,s1=0.44481j0.44481
10 k=i=0N1(si)(0.44481j0.44481)(0.44481+j0.44481)0.39571
11 Ha(s)=T Ki=0N1(ssi)0.39571(s+0.44481j0.44481)(s+0.44481+j0.44481)0.39571s2+0.88962s+0.39571
12 partial fraction Ha(s)=i=0N1Aissi0.44481js+0.44481+0.44481j0.44481js+0.444810.44481j
0.24535zz21.1572z+0.41081
13 H(z)=i=0N1Ai1exp(Tsi)z10.44481i1exp(0.44481j0.44481)z10.44481i1exp(0.44481+j0.44481)z1

3.2.2 Using bilinear

T=110000

step Impulse invariance
1 ωp=2πfpFs 2π(1000)100000.2π
2 ωs=2πfsFs2π(2000)100000.4π
3 αp=110δp10110310 1.9953
4 αs=110δs101101010 10.0
5 Ωp=2Ttan(ωp2)2×10000tan(0.2π2) 6498.4
6 Ωs=2Ttan(ωs2)2×10000tan(0.4π2)14531.
7 N=12log[αp1]log[αs1]log(Ωp)log(Ωs)12log10(1.99531)log10(10.01)log10(6498.4)log10(14531.) 1.3681 2
8 Ωc=Ωs10(12Nlog10[αs1])1453110(12×2log10(10.01)) 8389.5
9 poles of H(S) si=Ωc ej(π(1+2i+N)2N)si=8389.5 ej(π(3+2i)4)  i=01
s0=5932.3+j5932.3,s1=5932.3j5932.3
10 k=i=0N1(si)(5932.3j5932.3)(5932.3+j5932.3)7.0384×107
11 Ha(s)=Ki=0N1(ssi)7.0384×107(s+5932.3i5932.3)(s+5932.3+i5932.3)
12 7.0384×107s2+11865.s+7.0384×107
13 H(z)=Ha(s)|s=2T1z11+z10.099459z2+0.19892z+0.099459z20.93156z+0.32938

Mathematica GUI program is written to implement the above. It can be downloaded from here

Also a Matlab script nma_filter.m.txt was written (no GUI) to implement this design.

This script (written on Matlab 2007a). This script does not handle the conversion from H(s) to H(z) well yet, need to work more on this... of course, one can just use Matlab butter() function for this.

Example output of the above Matlab script is matlab_output.txt

4 IIR design for minimum order filter

This is another small note on IIR design for minimum order filter.

This document describes how to design an IIR digital filter given a specification in which the filter order is specified.

Given the following diagram, the specifications for the design will be

  1. Digital filter order (N)
  2. fpass, the passband corner frequency (or the cutoff frequency) at 3db. This means Apass=3db

4.1 Impulse invariance method

We first convert analog specifications to digital specifications: Fs2π=fpassωp, hence ωp=2πfpassFs

Then the cutoff frequency Ωc=ωpT for impulse invariance.

Next find the poles of H(s). Since the butterworth magnitude square of the transfer function is |Ha(s)|2=T21+(sjΩc)2N Hence H(s) poles are found by setting the denominator of the above to zero1+(sjΩc)2N=0 And as I did in the earlier document, the poles of H(s) are found ats=Ωc ej(π(1+2k+N)2N) We only need to find the LHS poles, which are located at i=0N1, because these are the stable poles. Hence the ith pole is si=Ωc ej(π(1+2i+N)2N) Now we can write the analog filter generated based on the above selected poles, which is, for impulse invariance(3)Ha(s)=T Ki=0N1(ssi) K is found by solving Ha(0)=T  hencek=i=0N1(si) Now we need to write poles in non-polar form and plug them into (3)si=Ωc ej(π(1+2i+N)2N)=Ωc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)i=0N1 Hence, (4)Ha(s)=T Ki=0N1(sΩc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)) Now that we have found H(s) we need to convert it to H(z)

We need to make sure that we multiply poles of complex conjugates with each others to make the result simple to see.

Now that we have Ha(s), we do the AD conversion. I.e. obtain H(z) from the above H(s). When using impulse invariance, we need to perform partial fraction decomposition on (4) above in order to write H(s) in this formH(s)=i=0N1Aissi For example, to obtain Aj, we writeAj=limssjHa(s)=T ki=0ijN1(ssi) Once we find all the As, we now write H(z) as followsH(z)=i=0N1Ai1exp(si T)z1 This completes the design. We can try to convert the above form of H(z) to a rational expression as H(z)=N(z)D(z)

4.2 bilinear transformation method

We first convert analog specifications to digital specifications: Fs2π=fpassωp, hence ωp=2πfpassFs

Now Ωc =2Ttan(ωp2)

Now that we have N and Ωc we find the poles of H(s). Since for bilinear the magnitude square of the transfer function is|Ha(s)|2=11+(sjΩc)2N Hence H(s) poles are found by setting the denominator of the above to zero 1+(sjΩc)2N=0 Which leads to poles at si=Ωc ej(π(1+2i+N)2N). We only need to find the LHS poles, which are located at i=0N1, because these are the stable poles. For bilinear, H(s) is given by(3)Ha(s)=Ki=0N1(ssi) K is found by solving Ha(0)=1, hence we obtaink=i=0N1(si) We see that the same expression results for k for both cases.

Now we need to write poles in non-polar form and plug them into (3)si=Ωc ej(π(1+2i+N)2N)=Ωc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)i=0N1 then(4)Ha(s)= Ki=0N1(sΩc(cosπ(1+2i+N)2N+jsinπ(1+2i+N)2N)) Now that we have found H(s) we need to convert it to H(z). After finding H(s) as shown above, we simply replace s by 2T1z11+z1. This is much simpler than the impulse invariance method. Before doing this substitution, make sure to multiply poles which are complex conjugate of each others in the denominator of H(s). After this, then do the above substitution

5 Appendix

The following is listing of the Matlab script, and a sample run output

5.1 Code listing

source code file

%Simple matlab script to design an IIR low pass filter using 
%butterworth in either impulse inv. or bilinear method. 
 
% 
% EE 420, CSU Fullerton 
% 
% by Nasser M. Abbasi 
% 5/5/201 
 
% Filter SPECIFICATIONS 
clear all; 
close all; 
Fs=10000; 
fp=1000; 
fs=2000; 
dbp=-3; 
dbs=-10; 
BILINEAR=1;  %set this to 0 to do impulse inv. 
 
%%%%%%%%%%%%%%%%%%%% 
 
fprintf('***** STARTING DESIGN *******\n'); 
fprintf('Sampling frequency=%f Hz\n',Fs); 
fprintf('freq at passband=%f Hz\n',fp); 
fprintf('freq at stopband=%f Hz\n',fs); 
fprintf('db at passband=%f \n',dbp); 
fprintf('db at stopband=%f \n',dbs); 
if BILINEAR 
   fprintf('Doing Bilinear method\n'); 
else 
   fprintf('Doing impulse invariance method\n'); 
end 
 
 
 
if BILINEAR 
    T=1/Fs; 
else 
    T=1; 
end 
 
fprintf('T=%f\n',T); 
 
wp=2*pi*fp/Fs; 
ws=2*pi*fs/Fs; 
alphap=1/(10^(dbp/10)); 
alphas=1/(10^(dbs/10)); 
 
if BILINEAR 
    gammap=2/T * tan(wp/2); 
else 
    gammap=wp/T; 
end 
 
if BILINEAR 
    gammas=2/T * tan(ws/2); 
else 
    gammas=ws/T; 
end 
 
oldn=.5*(log10(alphap-1)-log10(alphas-1))/(log10(gammap)-log10(gammas)); 
n=ceil(oldn); 
fprintf('n=%f, rounded to %d\n',oldn,n); 
 
if BILINEAR 
    gammaC=gammas/(10^(1/(2*n)*log10(alphas-1))); 
else 
    gammaC=gammap/(10^(1/(2*n)*log10(alphap-1))); 
end 
 
fprintf('Gamma C =%f\n',gammaC); 
 
poles_of_hs=zeros(n,1); 
for i=0:n-1 
    poles_of_hs(i+1)=gammaC*exp(sqrt(-1)*(pi*(1+2*i+n)/(2*n))); 
end 
 
fprintf('POLES Of H(s)\n'); 
poles_of_hs 
 
k=prod(-poles_of_hs); 
den=poly(poles_of_hs); 
 
fprintf('k=%d\n',k); 
 
fprintf('H(s)=\n',k); 
 
 
if BILINEAR 
    hs=tf(k,den) 
else 
    hs=tf(T*k,den) 
end 
 
 
[r,p,k]=residue(k,den); 
hzp=zeros(n,1); 
for i=1:n 
    hzp(i)=exp(p(i)*T); 
end 
 
fprintf('POLES Of H(z)\n'); 
hzp 
 
[B,A]=residue(r,hzp); 
fprintf('H(z)=\n',k); 
hz=tf(T*B',A')

5.2 Sample run output

text output from run

***** STARTING DESIGN ******* 
Sampling frequency=20000.000000 Hz 
freq at passband=2000.000000 Hz 
freq at stopband=3000.000000 Hz 
db at passband=-1.000000 
db at stopband=-15.000000 
Doing impulse invariance method 
T=1.000000 
n=5.885783, rounded to 6 
Gamma C =0.703205 
POLES Of H(s) 
 
poles_of_hs = 
 
         -0.182002858631059 +     0.679243915533887i 
         -0.497241056902828 +     0.497241056902828i 
         -0.679243915533887 +     0.182002858631059i 
         -0.679243915533887 -     0.182002858631059i 
         -0.497241056902828 -     0.497241056902828i 
         -0.182002858631059 -     0.679243915533887i 
 
k=1.209183e-001 
H(s)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 92 
 
Transfer function: 
 
                            (0.1209-1.041e-016i) 
---------------------------------------------------------------------------- 
s^6 + (2.717-4.441e-016i) s^5 + (3.691-1.998e-015i) s^4 + (3.179 
 
        -2.22e-015i) s^3 + (1.825-1.554e-015i) s^2 + (0.6644-4.996e-016i) s 
 
                                                    + (0.1209-1.041e-016i) 
 
 
POLES Of H(z) 
 
hzp = 
 
          0.534553736986506 +     0.290115961427623i 
          0.534553736986506 -     0.290115961427623i 
          0.648579932539211 +     0.523670977796743i 
          0.648579932539211 -     0.523670977796743i 
          0.498626135868541 -    0.0917668874413562i 
          0.498626135868543 +    0.0917668874413561i 
 
H(z)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 107 
 
Transfer function: 
 
-(0.9938-0.8577i) s^4 - (0.22-0.703i) s^3 + (1.377+1.095i) s^2 - (0.6574 
 
                                              +2.854i) s - (0.9146-1.114i) 
 
-------------------------------------------------------------------------- 
-(0.6979+1.411i) s^4 + (0.6009-0.8998i) s^3 - (0.03618-0.9428i) s^2 
 
                                    + (0.1901+0.7751i) s - (0.6018+0.246i) 
 
 
 
============================================================= 
 
***** STARTING DESIGN ******* 
Sampling frequency=20000.000000 Hz 
freq at passband=2000.000000 Hz 
freq at stopband=3000.000000 Hz 
db at passband=-1.000000 
db at stopband=-15.000000 
Doing Bilinear method 
T=0.000050 
n=5.304446, rounded to 6 
Gamma C =15324.588619 
POLES Of H(s) 
 
poles_of_hs = 
 
          -3966.29539304108 +      14802.4159246557i 
          -10836.1205316146 +      10836.1205316146i 
          -14802.4159246557 +      3966.29539304109i 
          -14802.4159246557 -      3966.29539304109i 
          -10836.1205316146 -      10836.1205316146i 
          -3966.29539304108 -      14802.4159246557i 
 
k=1.295188e+025 
H(s)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 90 
 
Transfer function: 
 
                          (1.295e025-1.288e010i) 
-------------------------------------------------------------------------- 
s^6 + (5.921e004-7.276e-012i) s^5 + (1.753e009-3.576e-007i) s^4 
 
        + (3.29e013-0.01172i) s^3 + (4.117e017-224i) s^2 + (3.265e021 
 
                                    -2.49e006i) s + (1.295e025-1.288e010i) 
 
 
POLES Of H(z) 
 
hzp = 
 
          0.498385402712059 +     0.299971817994199i 
           0.49838540271206 -     0.299971817994199i 
          0.467705977269569 -    0.0939883945094121i 
          0.605559876472429 +     0.553064536118524i 
          0.467705977269569 +    0.0939883945094127i 
           0.60555987647243 -     0.553064536118524i 
 
H(z)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 107 
 
Transfer function: 
 
-(0.5053-1.947i) s^4 + (0.02086-1.348i) s^3 - (0.9771+0.04836i) s^2 
 
                                 + (0.01411+0.02526i) s - (0.3816-0.3931i) 
 
-------------------------------------------------------------------------- 
(0.1988-1.53i) s^4 + (0.6374+0.9373i) s^3 - (1.064+0.2778i) s^2 
 
                                   - (0.7076-0.6148i) s + (0.4667-0.6282i) 
 
 
 
 
 
================================================================= 
 
Sampling frequency=10000.000000 Hz 
freq at passband=1000.000000 Hz 
freq at stopband=2000.000000 Hz 
db at passband=-3.000000 
db at stopband=-10.000000 
Doing impulse invariance method 
T=1.000000 
n=1.588388, rounded to 2 
Gamma C =0.629065 
POLES Of H(s) 
 
poles_of_hs = 
 
         -0.444816082052343 +     0.444816082052343i 
         -0.444816082052343 -     0.444816082052343i 
 
k=3.957227e-001 
H(s)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 92 
 
Transfer function: 
               (0.3957-8.327e-017i) 
--------------------------------------------------- 
s^2 + (0.8896-5.551e-017i) s + (0.3957-8.327e-017i) 
 
POLES Of H(z) 
 
hzp = 
 
          0.578571949761589 +     0.275792192443573i 
          0.578571949761589 -     0.275792192443573i 
 
H(z)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 107 
 
Transfer function: 
(-6.9e-016+1.253i) 
 
====================================== 
 
Sampling frequency=10000.000000 Hz 
freq at passband=1000.000000 Hz 
freq at stopband=2000.000000 Hz 
db at passband=-3.000000 
db at stopband=-10.000000 
Doing Bilinear method 
T=0.000100 
n=1.368163, rounded to 2 
Gamma C =8389.390482 
POLES Of H(s) 
 
poles_of_hs = 
 
          -5932.19490014964 +      5932.19490014964i 
          -5932.19490014964 -      5932.19490014964i 
 
k=7.038187e+007 
H(s)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 90 
 
Transfer function: 
                 (7.038e007-2.235e-008i) 
--------------------------------------------------------- 
s^2 + (1.186e004-9.095e-013i) s + (7.038e007-2.235e-008i) 
 
POLES Of H(z) 
 
hzp = 
 
          0.458140439181504 -     0.308891358305335i 
          0.458140439181504 +     0.308891358305335i 
 
H(z)= 
Warning: Transfer function has complex coefficients. 
> In tf.tf at 246 
  In nma_filter at 107 
 
Transfer function: 
(2.058e-016-1.78i) 
 
EDU>>

6 References

  1. Alan Oppenheim, Ronald Schafer, Digital Signal Processing,  Prentice-Hall, inc. 1975, Chapter 5.
  2. Mostafa Shiva, Electrical engineering department, California state university, Fullerton, Lecture notes, handout H.
  3. John Proakis, Dimitris Manolakis, digital signal processing, 3rd edition, section 8.3.