Matlab Filter Design Example
Matlab Filter Design Example
Example session
Design a 1000 Hz 2nd order Butterworth lowpass filter at a 4000 Hz sample rate using all of the
above methods.
Note: type "help command" to get help on matlab commands, i.e., "help butter."
New:
You may also wish to experiment with the new Matlab "Filter design and analysis tool." To run
this, type "fdatool" at the Matlab prompt. Use Analysis->FullView to rescale Y-axis.
matlab
>> [z,p,k]=butter(2,6283,'s')
k =
39476089 (NOTE: this is a constant multiplying the
result)
(==========================)
(<<< BEWARE MATLAB BUG!!!)
(==========================)
Warning: There is an error
in the 5.1.0.421 version
of matlab. There should be no zeroes
in
the returned value of z. To fix this,
you must suppress the zeroes by
entering the command "z=[]" after
In the current version you will get
z=[ 0 0 0.2500 ] which is wrong!
For the new (broken) version, type the following to correct the
problem:
>> z=[]
z =
[]
>> [n,d]=zp2tf(z,p,k)
d =
1.0e+07 * (==========================)
0.0000 0.0009 3.9476 (<<< BEWARE MATLAB BUG!!!)
(==========================)
Warning: There is a bug in some versions
of matlab. Although it looks like
the values are zero, they are not.
The print format is suppressing
the significant digits. To fix this
use:
>> h=tf(n,d)
Transfer function:
3.948e07
-----------------------
s^2 + 8886 s + 3.948e07
>> pzmap(h)
>> [nd,dd]=impinvar(n,d,4000)
nd =
0 6.5549e-01 0
dd =
1.0000e+00 -2.9248e-01 1.0846e-01
top =
0- 4.4428e+03i
0+ 4.4428e+03i
bot =
1.4624e-01+ 2.9508e-01i
1.4624e-01- 2.9508e-01i
-4442 i + 4442 i
--------------------- ---------------------
1- (.146 + .29 i)z^-1 1- (.146 - .29 i)z^-1
>> [top,bot]=residuez(nd,dd)
top =
0 + 1.1107e+00i
0 - 1.1107e+00i
bot =
1.4624e-01 - 2.9508e-01i
1.4624e-01 + 2.9508e-01i
>> [nd,dd]=bilinear(n,d,4000)
nd =
0.2261 0.4523 0.2261
dd =
1.0000 -0.2810 0.1856
nd =
0.2929 0.5858 0.2929
dd =
1.0000 -0.0000 0.1716
>> h=tf(nd,dd)
Transfer function:
0.2929 s^2 + 0.5858 s + 0.2929
------------------------------
s^2 - 3.455e-05 s + 0.1716
>> pzmap(h)
>> zgrid
>> zgrid([],[])
>> quit
127007 flops.