Experiments
Experiments
To write a MATLAB Script to perform generation of various basic signals for the given
sequences.
COMPONENTS REQUIRED:
PC, MATLAB software
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All Programs and click on
MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in
the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window
PROGRAM:
clc;
clear all;
close all;
figure(1);
%COSINE WAVE
n = 0:0.5:10;
s = cos(n);
subplot(3,3,4);
stem(n,s);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('COSINE WAVE');
RESULT:
The generation of various signals are performed by using MATLAB script and the program
results are verified.
VIVA QUESTIONS:
COMPONENTS REQUIRED:
PC, MATLAB software.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All Programs and click
on MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command
window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the graphical output is
displayed in the Figure Window.
LINEAR CONVOLUTION:
1. Enter the sequences (Input x[n] and the Impulse response h[n])
2. Perform the linear convolution between x[k] and h[k] and obtain y[n].
3. Find the FFT of x[n] & h[n].Obtain X and H
4. Multiply X and H to obtain Y
5. Find the IFFT of Y to obtain y’[n]
6. Compute error in time domain e=y[n]-y’[n]
7. Plot the Results
OUTPUT WAVEFORMS
LINEAR CONVOLUTION
Output
Output Waveforms
CIRCULAR CONVOLUTION
1. Enter the sequences (input x[n] and the impulse response h[n])
2. Make the length of the sequences equal by padding zeros to the
smaller length sequence.
3. Perform the circular convolution between x[k] and h[k]and obtain y[n].
4. Find the FFT of x[n] & h[n].Obtain X and H
5. Multiply X and H to obtain Y
6. Find the IFFT of Y to obtain y’[n]
7. Compute error in time domain e=y[n]-y’[n]. Plot the Results
clc;
clear all;
close all;
%Program to perform Linear Convolution
x1=input('Enter the first sequence to be convoluted:');
subplot(3,1,1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
x2=input('Enter the second sequence to be convoluted:');
subplot(3,1,2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
f=conv(x1,x2);
disp('The Linear convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convoluted sequence');
CIRCULAR CONVOLUTION
Output
Columns 6 through 7
16.0000 0.0000
Output Waveforms
SOURCE CODE 2 – CIRCULAR CONVOLUTION
clc;
clear all;
close all;
%Program to perform Circular Convolution
x1=input('Enter the first sequence to be convoluted:');
subplot(3,1,1);
l1=length(x1); stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
x2=input('Enter the second sequence to be convoluted:');
subplot(3,1,2);
l2=length(x2); stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseifl2>l1
l3 = l2-l1;
x1=[x1,zeros(1,l3)];
end
f=cconv(x1,x2);
disp('The Circular convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convoluted sequence');
RESULT:
The linear and circular convolutions of two signals are performed by using MATLAB script and
the program results are verified by manual calculation.
VIVA QUESTIONS:
1. What is convolution?
Convolution is a mathematical operation used to determine the output of an LTI (Linear Time-
Invariant) system when the input and system’s impulse response are known.
COMPONENTS REQUIRED:
PC, MATLAB software
SOURCE CODE:
clc;
clear;
close all;
% Input signal 1
x = input('Enter the first signal (x[n]): ');
% Input signal 2
y = input('Enter the second signal (y[n]): ');
% Compute Auto-correlation of x[n]
auto_corr_x = xcorr(x, x);
% Compute Auto-correlation of y[n]
auto_corr_y = xcorr(y, y);
% Compute Cross-correlation between x[n] and y[n]
cross_corr = xcorr(x, y);
% Display Results
disp('Auto-correlation of x[n]:');
disp(auto_corr_x);
disp('Auto-correlation of y[n]:');
disp(auto_corr_y);
disp('Cross-correlation between x[n] and y[n]:');
disp(cross_corr);
% Plot Results
figure;
% Auto-correlation of x[n]
subplot(3, 1, 1);
stem(-length(x)+1:length(x)-1, auto_corr_x, 'r', 'LineWidth', 1.5);
OUTPUT:
Enter the first signal (x[n]): [1,2,3,4]
Enter the second signal (y[n]): [2,1,0,1]
Auto-correlation of x[n]:
4.0000 11.0000 20.0000 30.0000 20.0000 11.0000 4.0000
Auto-correlation of y[n]:
2 1 2 6 2 1 2
Cross-correlation between x[n] and y[n]:
1.0000 2.0000 4.0000 8.0000 7.0000 10.0000 8.0000
xlabel('Lag');
ylabel('Amplitude');
title('Auto-correlation of x[n]');
grid on;
% Auto-correlation of y[n]
subplot(3, 1, 2);
stem(-length(y)+1:length(y)-1, auto_corr_y, 'b', 'LineWidth', 1.5);
xlabel('Lag');
ylabel('Amplitude');
title('Auto-correlation of y[n]');
grid on;
% Cross-correlation of x[n] and y[n]
subplot(3, 1, 3);
stem(-max(length(x), length(y))+1:max(length(x), length(y))-1, cross_corr, 'g',
'LineWidth', 1.5);
xlabel('Lag');
ylabel('Amplitude');
title('Cross-correlation between x[n] and y[n]');
grid on;
RESULT:
The auto correlation and cross correlation of two signals are performed by using MATLAB
script and the program results are verified by manual calculation.
VIVA QUESTIONS:
1. What is correlation?
Correlation is a measure of similarity between two signals as a function of time-lag
applied to one of them.
2. What is auto-correlation?
Auto-correlation is the correlation of a signal with a delayed version of itself.
3. What is cross-correlation?
Cross-correlation is the correlation between two different signals.
Rxx[n]=Rxx[−n]R_{xx}[n] = R_{xx}[-n]Rxx[n]=Rxx[−n]
COMPONENTS REQUIRED:
PC, MATLAB software
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All
Programs and click on MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the
graphical output is displayed in the Figure Window
Source Code :1
clc;
clear all;
close all;
%Get the sequence from user
disp('The sequence from the user:');
xn=input('Enter the input sequence x(n):');
%code block to plot the FFT of input sequence using inbuilt function
x2=fft(xn);
subplot(3,2,6);
stem(t,x2);
ylabel ('Amplitude');
RESULT:
The program for frequency analysis using DFT/FFT are performed by using MATLAB
script and the program results are verified by manual calculation.
VIVA QUESTIONS:
DFT requires N2N^2N2 operations, while FFT reduces it to Nlog2NN \log_2 NNlog2N.
COMPONENTS REQUIRED:
PC, MATLAB software
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All
Programs and click on MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the
graphical output is displayed in the Figure Window
Steps in DIF-FFT for N=4
1. Input Validation:
o N=4, which is a power of 2.
2. Butterfly Computation (Stage 1):
o Combine elements with sums and differences in groups of 2:
▪ x[0]= x[0]+x[2]
▪ x[1]= x[1]+x[3]
▪ x[2]=x[0]−x[2]
▪ x[3]= x[1]−x[3]
3. Twiddle Factors:
o Twiddle factors are applied in the final stages:
▪ WN=e−j2πkNW_N = e^{-j \frac{2\pi k}{N}}WN=e−jN2πk.
4. Final Combination:
o Combine results using sums and differences again.
Source Code : DIF-FFT
clc;
clear;
close all;
% Input sequence length
N = 4; % Fixed length of the sequence
disp('DIF-FFT for N = 4');
disp('Enter the input sequence (real and imaginary parts):'); % Input sequence
re = zeros(1, N); % Real part
im = zeros(1, N); % Imaginary part
for i = 1:N
re(i) = input(['Real part at index ', num2str(i-1), ': ']);
im(i) = input(['Imaginary part at index ', num2str(i-1), ': ']);
end
% Combine real and imaginary parts into a complex sequence
x = re + 1j * im; % Stage 1: Butterfly computation
x(1:2) = x(1:2) + x(3:4); % Top half: sums
x(3:4) = x(1:2) - 2 * x(3:4); % Bottom half: differences
% Twiddle factor for stage 2
W_N2 = exp(-2j * pi * (0:N/4-1) / N);
% Stage 2: Twiddle factor multiplication for bottom half
x(3) = x(3) * W_N2(1);
x(4) = x(4) * W_N2(1);
% Stage 3: Combine
X = zeros(1, N);
X(1) = x(1) + x(2);
X(2) = x(1) - x(2);
X(3) = x(3) + x(4);
X(4) = x(3) - x(4);
% Extract real and imaginary parts
re_out = real(X);
im_out = imag(X);
% Display the results
disp('Output Real Part:');
disp(re_out);
disp('Output Imaginary Part:');
Input
DIF-FFT for N = 4
Enter the input sequence (real and imaginary parts):
Real part at index 0: 1
Imaginary part at index 0: 0
Real part at index 1: 2
Imaginary part at index 1: 0
Real part at index 2: 3
Imaginary part at index 2: 0
Real part at index 3: 4
Imaginary part at index 3: 0
Output Real Part:
10 -2 -4 0
Output Imaginary Part:
0 0 0 0
disp(im_out);
% Plot results
figure;
subplot(2, 1, 1);
stem(0:N-1, re_out, 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('Output Real Part');
grid on;
subplot(2, 1, 2);
stem(0:N-1, im_out, 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('Output Imaginary Part');
grid on;
Source Code : DIT-FFT
clc;
clear;
close all;
% Length of the sequence
N = 4;
disp('DIT-FFT for N = 4');
disp('Enter the input sequence (real and imaginary parts):');
% Input sequence
re = zeros(1, N); % Real part
im = zeros(1, N); % Imaginary part
for i = 1:N
re(i) = input(['Real part at index ', num2str(i-1), ': ']);
im(i) = input(['Imaginary part at index ', num2str(i-1), ': ']);
end
% Combine real and imaginary parts into a complex sequence
x = re + 1j * im;
% Twiddle factors
W_N4 = exp(-2j * pi * (0:N/2-1) / N); % Twiddle factors for N=4
% Stage 1: Divide into even and odd
x_even = x(1:2:end); % [x0, x2]
x_odd = x(2:2:end); % [x1, x3]
% Apply butterfly operation for stage 1
x_even_out = x_even + x_odd; % Top half: sums
x_odd_out = x_even - x_odd; % Bottom half: differences
% Stage 2: Apply twiddle factors to the odd part
x_odd_out(1) = x_odd_out(1) * W_N4(1); % W0
x_odd_out(2) = x_odd_out(2) * W_N4(2); % W1
% Stage 3: Final output computation
X = zeros(1, N);
X(1) = x_even_out(1) + x_even_out(2);
X(2) = x_even_out(1) - x_even_out(2);
X(3) = x_odd_out(1) + x_odd_out(2);
X(4) = x_odd_out(1) - x_odd_out(2);
% Extract real and imaginary parts of the FFT result
re_out = real(X);
im_out = imag(X);
% Display results
Input
DIT-FFT for N = 4
Enter the input sequence (real and imaginary parts):
Real part at index 0: 1
Imaginary part at index 0: 0
Real part at index 1: 2
Imaginary part at index 1: 0
Real part at index 2: 3
Imaginary part at index 2: 0
Real part at index 3: 4
Imaginary part at index 3: 0
% =============================================================
% Output Results
% =============================================================
% Display Results
disp('DIF-FFT Output (Real and Imaginary Parts):');
disp(real(dif_output));
disp(imag(dif_output));
disp('DIT-FFT Output (Real and Imaginary Parts):');
disp(real(dit_output));
disp(imag(dit_output));
% Plot Results
figure;
% DIF-FFT Real Part
subplot(2, 2, 1);
DIF and DIT FFT for N = 4
Enter the input sequence (real and imaginary parts):
Real part at index 0: 1
Imaginary part at index 0: 0
Real part at index 1: 2
Imaginary part at index 1: 0
Real part at index 2: 3
Imaginary part at index 2: 0
Real part at index 3: 4
Imaginary part at index 3: 0
DIF-FFT Output (Real and Imaginary Parts):
10.0000 -2.0000 -2.0000 -2.0000
0 0 2 -2
DIT-FFT Output (Real and Imaginary Parts):
10.0000 -4.0000 -1.0000 -1.0000
0 0 1 -1
stem(0:N-1, real(dif_output), 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIF-FFT Real Part');
grid on;
% DIF-FFT Imaginary Part
subplot(2, 2, 2);
stem(0:N-1, imag(dif_output), 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIF-FFT Imaginary Part');
grid on;
% DIT-FFT Real Part
subplot(2, 2, 3);
stem(0:N-1, real(dit_output), 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIT-FFT Real Part');
grid on;
% DIT-FFT Imaginary Part
subplot(2, 2, 4);
stem(0:N-1, imag(dit_output), 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIT-FFT Imaginary Part');
grid on;
RESULT:
The program for Fast Fourier Transform using DIT-FFT and DIF-FFT. are performed by
using MATLAB script and the program results are verified by manual calculation.
VIVA QUESTIONS:
1. What is FFT?
FFT (Fast Fourier Transform) is an efficient algorithm to compute the Discrete Fourier Transform (DFT)
and its inverse. Instead of requiring O(N2) computations like DFT, FFT reduces it to O(NlogN)
They are responsible for introducing the frequency-dependent phase shifts in FFT.
COMPONENTS REQUIRED:
PC, MATLAB software
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All
Programs and click on MATLAB) to get into the Command
Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the Command Window.
6. The result is displayed in the Command window and the graphical
output is displayed in the Figure Window.
SOURCE CODE :1
clc;
clear all;
close all;
N=input('Order of the filter:');
wc=input('Cut off frequency:');
h=fir1(N,wc/pi,rect
win(N+1));
freqz(h);
title('FIR Filter - Rectangular Window');
h=fir1(N,wc/pi,tria
ng(N+1)); figure(2)
freqz(h);
title('FIR Filter - Triangular Window');
h=fir1(N,wc/pi,haming(N+1));
OUTPUT: 1
h=fir1(N,wc/pi,han
ning(N+1));
figure(4)
freqz(h);
title('FIR Filter - Hanning Window');
h=fir1(N,wc/pi,blac
kman(N+1));
figure(5)
freqz(h);
title('FIR Filter - Blackman Window');
SOURCE CODE :2
clc;
clear all;
close all;
N=input('Order of the filter:');
wc=input('Cut off frequency:');
b=fir1(N,wc/pi,rectwin(N+1));
[H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,a
bs(H),'k');
hold on
b=fir1(N,wc/pi,triang(N+1));
[H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,abs(H),'--k');
hold on
b=fir1(N,wc/pi,hamming(N+1))
; [H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,abs(H),':k');
hold on
b=fir1(N,wc/pi,hanning(N+1));
[H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,abs(H),'-.k');
hold on
b=fir1(N,wc/pi,blackman(N+1));
[H,w]=freqz(b,1,512); %frequency response
plot(w/pi,abs(H),'.b');
hold on
xlabel('Normalized
Frequency');
ylabel('Magnitude');
legend('Rectangular','Triangular(Barlett)','Hamming','Hanning','Blackman','Locatio
n','Best');
title('Gibbs Phenomenon');
allaxes=findall(a,'Type','axes');
alllines=findall(a,'Type','line');
alltext=findall(a,'Type','text');
set(allaxes,'FontName','Times New
Roaman','FontWeight','Bold','LineWidth',1,... 'FontSize',12);
set(alllines,'Linewidth',1);
set(alltext,'FontName','Times New Roaman','FontWeight','Bold','FontSize',12);
OUTPUT: 2
Order of the filter:51
Cut off frequency:0.4
RESULT:
The given FIR low pass filter was designed using Window method and manually verified
filter co-efficient of the filters.
VIVA QUESTIONS:
7. What inputs are given in the MATLAB code for FIR filter design?
The order of the filter (N) and cutoff frequency (wc) are given as inputs.
COMPONENTS REQUIRED:
PC, MATLAB software
SOURCE CODE:
%30th order LPF using Frequency Sampling method
clc;
clear all; close all;
Fs=1000; %sampling frequency Fn=Fs/2;
%Nyquist frequency f=[ 0 400 400 500]/Fn;
m=[1 1 0 0];
h=fir2(30,f,m); [H,w]=freqz(h,1,256);
plot(f*Fn,m,'-o') hold on
plot (Fn*w/pi, abs(H),'k');grid hold on
legend('Ideal', 'Designed')
xlabel('Frequency (Hz)')
ylabel('Magnitude') title('FIR filter')
%optional code
M=63; Wp=0.5*pi;
%the number of samples and the passband cutoff frequency
m=0:(M+1)/2; Wm=2*pi*m./(M+1);
%the sampling points and the stopband cutoff frequency
mtr=floor(Wp*(M+1)/(2*pi))+2;
%round to negative part,i.e.floor(3.5)=3;floor(-3.2)=-4
Ad=[Wm<=Wp];
Ad(mtr)=0.38;
Hd=Ad.*exp(-j*0.5*M*Wm);
%define frequency-domain sampling vector H(k)
Hd=[Hd conj(fliplr(Hd(2:(M+1)/2)))];
%fliplr is to realize the fliplr of matrix and conj
h=real(ifft(Hd));
% h(n)=IDFT[H(k)
w=linspace(0,pi,1000);
%get1000 row vectors between 0 andpi
H=freqz(h,[1],w);
%the amplitude -frequency characteristic diagram of the filter figure(1)
plot(w/pi,20*log10(abs(H)));
%parameters are respectively the normalized frequency and amplitude
xlabel('the normailzed frequency');
ylabel('gian/dB');
title('The gain response of lowpass filter');
axis([0 1 -50 0.5]); f1=100;f2=300;f3=700;
fs=2000;
%the frequencies of sines signal that needs filtered and the sample frequency
figure(2);
subplot(211)
t=0:1/fs:0.25;%define the time domain and steplength
s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);
%signal before filtering plot(t,s);%plot the diagram before filtering
xlabel('time/s'); ylabel('amplitude');
title('Time-domain diagram before filtering'); subplot(212)
Fs=fft(s,512); AFs=abs(Fs);
%transform to the frequency domain f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));
%plot the frequency domain diagram before filtering xlabel('frequency/Hz');
ylabel('amplitude');
title('Frequency-domain diagram before filtering'); figure(3)
sf=filter(h,1,s);
%use function filter subplot(211)
plot(t,sf)
%plot the diagram after filtering
xlabel('time/s');
ylabel('amplitude');
title('Time-domain diagram after filtering');
axis([0.2 0.25 -2 2]);%set the range of image coordinates subplot(212)
Fsf=fft(sf,512); AFsf=abs(Fsf);%frequency-domain and the amplitude diagram
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');
ylabel('amplitude');
title('Frequency-domain diagram after filtering');
RESULT:
For the given specifications low pass filter was designed using Frequency Sampling Method and
manually verified filter co-efficient of the filters.
VIVA QUESTIONS:
1. What is the fundamental principle of frequency sampling?
COMPONENTS REQUIRED:
PC, MATLAB software
BILINEAR TRANSFORMATION:
DESIGN STEPS:
i. From the given specifications, Find pre-warped analog frequencies using
ii. Using the analog frequencies, find H(s) of the analog filter
iii. Substitute
ALGORITHM/PROCEDURE:
i. Calculate the attenuation in dB for the given design parameters
ii. Design the analog counterpart
iii. Using Impulse Invariant /Bilinear transformation design the digital filter
iv. Display the transfer function. Plot the magnitude response and phase response
/ Butterworth Lowpass Impulse invariant method
Command window:
OUTPUT:
SOURCE CODE:
/ Butterworth Lowpass Impulse invariant method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Butterworth Lowpass filter using Impulse invariant method ');
% Calculation of
ohmp,ohms,Ap,As
Ap=abs(20*log10(1-
Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T; ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');
Butterworth Lowpass Bilinear Transformation Method
Command Window :
OUTPUT:
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
abel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
Chebyshev Lowpass Impulse invariant method
Command Window:
OUTPUT:
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Impulse invariant method ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp)); As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')
Command Window:
OUTPUT:
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');
% Phase Response
Ha=angle(H);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Bilnear transformation method ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss)); ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');
RESULT:
Butterworth and Chebyshev Lowpass filters were designed using Bilinear and Impulse Invariant
transformations, and manually verified the order, cut off frequency and filter co-efficient of the
filters.
VIVA QUESTIONS:
COMPONENTS REQUIRED:
PC, MATLAB software
clc;
clear all;
close all;
h = fir1(128-1,1/3); % Input cutoff as 2*fc, where fc = wc/(2pi) freqz(h,1,512,1)
print -tiff -depsc multi3.eps
RESULT:
The multirate LPF filters (Interpolator and Decimator) are performed by using MATLAB script
and the program results are verified by manual calculation.
VIVA QUESTIONS:
1. What is sampling in digital signal processing?
Sampling is the process of converting a continuous-time signal into a discrete-time signal by
taking values at regular intervals.
6. What is downsampling, and what happens to the signal when we downsample it?
Downsampling reduces the sampling rate by keeping every M-th sample. It compresses the
signal in the time domain but causes spectrum expansion and possible aliasing.