% Program 4_1
% 4-th Order Analog Butterworth Lowpass Filter Design
%
format long
% Determine zeros and poles
[z,p,k] = buttap(4);
disp('Poles are at');disp(p);
% Determine transfer function coefficients
[pz, pp] = zp2tf(z, p, k);
% Print coefficients in descending powers of s
disp('Numerator polynomial'); disp(pz)
disp('Denominator polynomial'); disp(real(pp))
omega = [0: 0.01: 5];
% Compute and plot frequency response
h = freqs(pz,pp,omega);
plot (omega,20*log10(abs(h)));grid
xlabel('Normalized frequency'); ylabel('Gain, dB');
% Program 4_2
% Program to Design Butterworth Lowpass Filter
%
% Type in the filter order and passband edge frequency
N = input('Type in filter order = ');
Wn = input('3-dB cutoff angular frequency = ');
% Determine the transfer function
[num,den] = butter(N,Wn,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');
% Program 4_3
% Program to Design Type 1 Chebyshev Lowpass Filter
%
% Read in the filter order, passband edge frequency
% and passband ripple in dB
N = input('Order = ');
Fp = input('Passband edge frequency in Hz = ');
Rp = input('Passband ripple in dB = ');
% Determine the coefficients of the transfer function
[num,den] = cheby1(N,Rp,2*pi*Fp,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');
% Program 4_4
% Program to Design Elliptic Lowpass Filter
%
% Read in the filter order, passband edge frequency,
% passband ripple in dB and minimum stopband
% attenuation in dB
N = input('Order = ');
Fp = input('Passband edge frequency in Hz = ');
Rp = input('Passband ripple in dB = ');
Rs = input('Minimum stopband attenuation in dB = ');
% Determine the coefficients of the transfer function
[num,den] = ellip(N,Rp,Rs,2*pi*Fp,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');
No comments:
Post a Comment