EmbDev.net

Forum: DSP Digtial Butterworth Filter of Nth order


von Jagdish A. (Company: ZF) (xatax)


Attached files:

Rate this post
useful
not useful
I want to design a digital butterworth lowpass filter of nth order, with 
only freedom of choice to user being order of the filter and the cut off 
frequency, i already have a 1st order low pass.

Code:​
1
T = 1/(2*pi*this.fc);
2
            this.A = -1/T;
3
            this.B = 1/T;
4
            this.C = 1;
5
            this.D = 0;
This is a very basic lowpass PT1 filter, i take the state space matrix, 
descrtize it and apply it to my signal. now i want to extend my library 
to butterworth. I am trying to use as many minimal matlab commands as 
possible. So i thought it's better to derive in hand before implementing 
it. i wanted to know how to deal with damping ratio as the order is 
progressed.

When i was searching for answer, i came across wiki of butter worth 
filter:
See attachment. it's the list of polynomials

I can just hard code this, but have they considered damping ratio and 
how do i covert this to state space.

OR

I found another way, where i find zeros and poles based on the order of 
the filter.
1
% Poles are on the unit circle in the left-half plane.
2
n = varargin{1} % order of the filter
3
fc = varargin{2} % cut off frequency
4
Wn = (fc*2)/Fs % Fs is sampling frequency, normalizing the cut off frequency
5
z = [];
6
p = exp(1i*(pi*(1:2:n-1)/(2*n) + pi/2)); %n is the order of the filter
7
p = [p; conj(p)];
8
k = real(prod(-p)); %product of an array element´
9
10
%When we get zpk, we just convert them to state space.
11
12
[a,b,c,d] = zp2ss(z,p,k);
13
14
%Now transforming the abcd matrix to the given cut off frequency
15
[a,b,c,d] = lp2lp(a,b,c,d,Wn);


The only problem is while applying the cut off frequency,
1
[a,b,c,d] = lp2lp(a,b,c,d,Wn);
 should apply normalized one or in rads/sec or just in Hz. Even though i 
tried all of them still would like i to ask where i am going wrong

von rm1 (Guest)


Rate this post
useful
not useful
with SciLab ( a free MatLab clone) you can use:

hz=iir(n,ftype,fdesign,frq,delta)
[p,z,g]=iir(n,ftype,fdesign,frq,delta)

Arguments
n
positive number witn integer value, the filter order.

ftype
string specifying the filter type, the possible values are: 'lp' for 
low-pass,'hp' for high pass,'bp' for band pass and 'sb' for stop band.

fdesign
string specifying the analog filter design, the possible values are: 
'butt', 'cheb1', 'cheb2' and 'ellip'

frq
2-vector of discrete cut-off frequencies (i.e., 0<frq<.5). For 'lp' and 
'hp' filters only frq(1) is used (in this case, frq can be a scalar). 
For 'bp' and 'sb' filters frq(1) is the upper cut-off frequency and 
frq(2) is the lower cut-off frequency.

delta
2-vector of error values for cheb1, cheb2, and ellip filters where only 
delta(1) is used for cheb1 case, only delta(2) is used for cheb2 case, 
and delta(1) and delta(2) are both used for ellip case. 
0<delta(1),delta(2)<1
for cheb1 filters 1-delta(1)<ripple<1 in passband
for cheb2 filters 0<ripple<delta(2) in stopband
for ellip filters 1-delta(1)<ripple<1 in passband and 0<ripple<delta(2) 
in stopband

hz
a single input single output discrete transfer function, the low pass 
filter

p
vector of transformed filter zeros.

z
vector of transformed filter poles.

g
a scalar: transformed filter gain.

Example:
hz=iir(3,'bp','ellip',[.15 .25],[.08 .03]);
[hzm,fr]=frmag(hz,256);
plot2d(fr',hzm')
xtitle('Discrete IIR filter: band pass  0.15 < fr < 0.25 ',' ',' ');

von Jagdish A. (Company: ZF) (xatax)


Rate this post
useful
not useful
Hello,

Thanks for replying. I do not want to use any of the built in commands, 
i want to implement my own methods. Or else it was just as easy as 
'butter' commands in matlab.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.