March 23, 2015

MATLAB Code for designing of IIR Butterworth LPF using IIT technique

 IIR Butterworth LPF using IIT technique:
clear all;
clc;

ap = input('Gain at Passband Edge Frequency : ');
as = input('Gain at StopBand Edge Frequency : ');
wp = input('PassBand Edge Frequency(Digital): ');
ws = input('StopBand Edge Frequency(Digital): ');
pef_d = wp*pi;
sef_d = ws*pi;
ts = input('Sampling Time in sec :');
del2 = -20*log10(ap)
del1 = -20*log10(as)
pef_a = pef_d/ts
sef_a = sef_d/ts
[N,wc] = buttord(pef_a,sef_a,del2,del1,'s')

[bn,an] = butter(N,1,'s');
display('Normalized Transfer Function is, ')
Hnorm  = tf(bn,an)

[b,a] = butter(N,wc,'s');
display('Unnormalized Transfer Function is, ')
Hunnorm = tf(b,a)

[bz,az] = impinvar(b,a,1/ts);
display('Digital Transfer Function is, ')
Hz = tf(bz,az,ts)

w = 0:pi/16:pi;
display('Frequency Response is ,')
Hw = freqz(bz,az,w)
display('Magnitude Response is,')
Hw_mag = abs(Hw)
display('Phase Response is,')
Hw_phase = angle(Hw)
%subplot(2,1,1);
figure
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response for Butterworth Low Pass Filter ');
xlabel('Normalized Frequency, \omega/\pi');
ylabel('Magnitude |H(\omega)|');
%subplot(2,1,2);
figure
plot(w/pi,Hw_phase,'k');
grid;
title('Phase Response for Butterworth Low Pass Filter ');
xlabel('Normalized Frequency, \omega/\pi');
ylabel('Magnitude |H(\omega)|');

Use the following inputs:
Gain at Passband Edge Frequency : 0.8
Gain at StopBand Edge Frequency : 0.2
PassBand Edge Frequency(Digital): 0.2
StopBand Edge Frequency(Digital): 0.32

Sampling Time in sec :0.05

Magnitude Response:


Phase Response:

Note: Please comment suggestions.. TY


5 comments:

Unknown said...

KEEP UP THE GOOD WORK....

Unknown said...

Nice 1

Unknown said...

Nice 1

Unknown said...

Works well but how to convert it to an analog filter and what's the difference
Also, I have my filter in khz. Then what're the inputs to be entered for stopband frequency and passband frequency in radians?


Shashwat Sanghavi said...

This is with response to the question posted by anonymous...
The given is an IIR filter algorithm. Implementations can either be in digital or analog domain. For digital domain, we use the transfer function and implement the famous realization architectures such as Direct Form I-II, lattice ladder, and many more. Here, we can use a FPGA and describe the adder multiplier architectures using VHDL or verilog. One can also use microcontrollers or microprocessors.
For analog domain, it is often easier to use Linear IC architectures based on Op-amps. Another approach can be the use of Foster/Cauer Network synthesis for obtained transfer function of the filter.
For your question regarding normalized frequency, please refer to https://en.wikipedia.org/wiki/Normalized_frequency_(unit)

P.S: It is always preferred to allow your identity while posting comments so that you may follow-up on for such inquiry based comments.