Sunteți pe pagina 1din 43

JIMMA UNIVERSITY

JIMMA INSTITUTE OF TECHNOLOGY


DEPARTMENT OF ELECTRICAL & COMPUTER
ENGINEERING

MASTER OF SCIENCE PROGRAM CURRICULUM


IN
COMMUNICATION ENGINEERING

Manual for ECEG6210 Advanced Communication Lab II

“WE ARE IN THE COMMUNITY!”


LIST OF EXPERIMENTS

DISCRETE LINEAR CONVOLUTION


1
DISCRETE CIRCULAR CONVOLUTION
2
DISCRETE FOURIER TRANSFORM
3
FAST FOURIER TRANSFORM ALGORITHMS
4

5 DESIGN OF FIR FILTERS


DESIGN OF BUTTERWORTH FILTERS
6
DESIGN OF IIR FILTERS
7
SAMPLING RATE CONVERSION
8
POWER SPECTRUM ESTIMATION USING PERIODOGRAM
9
EX.No:1 DISCRETE LINEAR CONVOLUTION
DATE:

AIM:
Write a MATLAB Script to perform discrete linear convolution for the given two
sequences and also prove by manual calculation.

APPARATUS REQUIRED:
PC, MATLAB software

FLOWCHART:

START

ENTER THE INPUT SEQUENCE


x[n] & SYSTEM RESPONSE h[n]

PERFORM LINEAR CONVOLUTION IN TIME


DOMAIN

PLOT THE WAVEFORMS AND ERROR

STOP

THEORY:
LINEAR CONVOLUTION:
The response y[n] of a LTI system for any arbitrary input x[n] is given by convolution of
impulse response h[n] of the system and the arbitrary input x[n].
 

y[n] = x[n]*h[n] = k
 
x[ k ]h [ n  k ]
or k
 
h[ k ] x[ n  k]

If the input x[n] has N1 samples and impulse response h[n] has N2 samples then the output
sequence y[n] will be a finite duration sequence consisting of (N1 + N2 - 1) samples. The
convolution results in a non periodic sequence called Aperiodic convolution.

STEPS IN LINEAR CONVOLUTION:


The process of computing convolution between x[k] and h[k] involves four steps.
1. Folding: Fold h[k] about k=0 to obtain h[-k]
2. Shifting: Shift h[-k] by ‘n0’to right if ‘n0’ is positive and shift h[-k] by ‘n0’ to the left
if ‘n0’ is negative. Obtain h[n0-k]
3. Multiplication : Multiply x[k] by h[n0-k] to obtain the product sequence
yn0 [k] = x[k] h [n0 –k]
4. Summation: Find the sum of all the values of the product sequence to obtain values of
output at n = n0
Repeat steps 2 to 4 for all possible time shifts ‘n0’ in the range -  <n< 

LIBRARY FUNCTION:

 conv: Convolution and polynomial multiplication.


C = conv (A, B) convolves vectors A and B. The resulting vector C’s length is given by
length(A)+length(B)-1. If A and B are vectors of polynomial coefficients, convolving
them is equivalent to multiplying the two polynomials in frequency domain.

 length: Length of vector.


length(X) returns the length of vector X. It is equivalent to size(X) for non empty arrays
and 0 for empty ones.

 fft: Discrete Fourier transform.


fft(x) is the Discrete Fourier transform (DFT) of vector x. For matrices, the ‘fft’
operation is applied to each column. For N-D arrays, the ‘fft’ operation operates on the
first non-single dimension. fft(x,N) is the N-point FFT, padded with zeros if x has less
than N points and truncated if it has more.

 ifft: Inverse Discrete Fourier transform.


ifft(X) is the Inverse Discrete Fourier transform of X.
ifft(X,N) is the N-point Inverse Discrete Fourier transform of X.

ALGORITHM/PROCEDURE:
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

1. Using Conv function


%Linear convolution of two sequence
x=input('Enter first sequence=');
%Example: [3,11,7,0,-1,4,2];
nx=input('Enter time index for first seq=');
% Time index for x, Example:[-3:3]
Nx=nx(1):1:nx(length(x));
subplot(3,1,1)
stem(Nx,x);
xlabel('n'),ylabel('x');
title('input sequence-1');
h=input('Enter second sequence=');
%Example: [2,3,0,-5,2,1];
nh=input('Enter time index for second seq=');
% Time index for h, Example:[-1:4]
Nh=nh(1):1:nh(length(h));
subplot(3,1,2)
stem(Nh,h);
xlabel('n'),ylabel('h');
title('input sequence-2');
y=conv(x,h);
nyb=nx(1)+nh(1);
nye=nx(length(x))+nh(length(h));
ny=[nyb:1:nye];
subplot(3,1,3)
stem(ny,y);
xlabel('n'),ylabel('y');
title('output sequence');
3. Using DFT and IDFT
RESULT:
The linear convolutions are performed by using MATLAB script and the program results
are verified by manual calculation.
EX.No:2 DISCRETE CIRCULAR CONVOLUTION
DATE:

AIM:
Write a MATLAB Script to perform discrete circular convolution for the given two
sequences and also prove by manual calculation.

APPARATUS REQUIRED:
PC, MATLAB software

FLOWCHART:

START

ENTER THE INPUT SEQUENCE


x[n] & SYSTEM RESPONSE h[n]

PERFORM CIRCULAR CONVOLUTION IN TIME


DOMAIN

PLOT THE WAVEFORMS AND ERROR

STOP
THEORY:
CIRCULAR CONVOLUTION
The convolution of two periodic sequences with period N is called circular convolution
of two signals x1[n] and x2[n] denoted by
N 1 N 1

y[n] = x1[n] * x2[n] =  x1 [(n-k) mod N] x2 (k) or  x 1 (k ) x2 [(n-k) mod N]


k 0 k 0

where x1[(n-k) mod N] is the reflected and circularly translated version of x1[n].
x1[n] * x2[n] = IDFTN { DFTN (x1[n] ) . DFTN (x2[n])}
It can be performed only if both the sequences consist of equal number of samples. If the
sequences are different in length then convert the smaller size sequence to that of larger size by
appending zeros

METHODS FOR CIRCULAR CONVOLUTION:

Matrix Multiplication Method and Concentric Circle Method

ALGORITHM/PROCEDURE:
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]
8. Plot the Results
MATLAB Code
3. Using DFT and IDFT

RESULT:
The circular convolutions are performed by using MATLAB script and the program
results are verified by manual calculation
EX.No:3 DISCRETE FOURIER TRANSFORM
DATE:

AIM:
Write a MATLAB program to perform the Discrete Fourier Transform for the given
sequences.
. APPARATUS REQUIRED:
PC, MATLAB software

FLOWCHART:

START

ENTER THE INPUT SEQUENCE

PERFORM THE DFT USING IN-BUILT FFT AND


USING DIRECT FORMULA ON THE GIVEN
INPUT SEQUENCE

PLOT THE WAVEFORMS AND ERROR

STOP

THEORY:
DISCRETE FOURIER TRANSFORM
Fourier analysis is extremely useful for data analysis, as it breaks down a signal into
constituent sinusoids of different frequencies. For sampled vector data Fourier analysis is
performed using the Discrete Fourier Transform (DFT).
The Discrete Fourier transform computes the values of the Z-transform for evenly spaced
points around the circle for a given sequence.

If the sequence to be represented is of finite duration i.e. it has only a finite number of
non-zero values, the transform used is Discrete Fourier transform.

It finds its application in Digital Signal processing including Linear filtering, Correlation
analysis and Spectrum analysis.

Consider a complex series x [n] with N samples of the form Where


x is a complex number Further, assume that the series outside the range
0, N-1 is extended N-periodic, that is, xk = xk+N for all k. The FT of this series is denoted as X (k)
and has N samples. The forward transform is defined as

N 1
1  j2  n k N
X(k) 
N
 x(n) e , for k  0 ... N  1
n0

The inverse transform is defined as

Although the functions here are described as complex series, setting the imaginary part to
0 can represent real valued series. In general, the transform into the frequency domain will be a
complex valued function, that is, with magnitude and phase.

LIBRARY FUNCTIONS:

 exp: Exponential Function.


exp (X) is the exponential of the elements of X, e to the power X. For complex
Z=X+i*Y, exp (Z) = exp(X)*(COS(Y) +i*SIN(Y)).

 disp: Display array.


disp (X) is called for the object X when the semicolon is not used to terminate a
statement.

 max: Maximum elements of an array


C = max (A, B) returns an array of the same size as A and B with the largest elements
taken from A or B.
 fft: Discrete Fourier transform.
fft(x) is the discrete Fourier transform (DFT) of vector x. For the matrices, the FFT
operation is applied to each column. For N-Dimensional arrays, the FFT operation
operates on the first non-singleton dimension.
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 :
clc;
clear all;
close all;
%Get the sequence from user
disp('The sequence from the user:');
xn=input('Enter the input sequence x(n):');
% To find the length of the sequence
N=length(xn);
%To initilise an array of same size as that of input sequence
Xk=zeros(1,N);
iXk=zeros(1,N);
%code block to find the DFT of the sequence
for k=0:N-1
for n=0:N-1
Xk(k+1)=Xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/N));
end
end
%code block to plot the input sequence
t=0:N-1;
subplot(3,2,1);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('Input Sequence');
%code block to plot the X(k)
disp('The discrete fourier transform of x(n):');
disp(Xk);
t=0:N-1;
subplot(3,2,2);
stem(t,Xk);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('X(k)');
% To find the magnitudes of individual DFT points
magnitude=abs(Xk);
%code block to plot the magnitude response
disp('The magnitude response of X(k):');
disp(magnitude);
t=0:N-1;
subplot(3,2,3);
stem(t,magnitude);
ylabel ('Amplitude');
xlabel ('K');
title ('Magnitude Response');
%To find the phases of individual DFT points
phase=angle(Xk);
%code block to plot the phase response
disp('The phase response of X(k):');
disp(phase);
t=0:N-1;
subplot(3,2,4);
stem(t,phase);
ylabel ('Phase');
xlabel ('K');
title ('Phase Response');
% Code block to find the IDFT of the sequence
for n=0:N-1
for k=0:N-1
iXk(n+1)=iXk(n+1)+(Xk(k+1)*exp(i*2*pi*k*n/N));
end
end
iXk=iXk./N;
%code block to plot the output sequence
t=0:N-1;
subplot(3,2,5);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');
%code block to plot the FFT of input sequence using inbuilt function
x2=fft(xn);
subplot(3,2,6);
stem(t,x2);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('FFT of input sequence');
RESULT:
The program for DFT calculation was performed with library functions and without
library functions. The results were verified by manual calculation.
EX. NO :4 FAST FOURIER TRANSFORM ALGORITHMS

AIM:
Write a MATLAB Script to compute Discrete Fourier Transform and Inverse Discrete
Fourier Transform of the given sequence using FFT algorithms (DIT-FFT & DIF-FFT)

APPARATUS REQUIRED:
PC, MATLAB software

FLOWCHART:

START

ENTER THE INPUT SEQUENCE IN


TIME DOMAIN OR FREQUENCY
DOMAIN

PERFORM DIT/DIF-FFT FOR TIME SAMPLES OR


PERFORM IDIT/IDIT-FFT FOR FREQUENCY SAMPLES

PLOT THE WAVEFORMS

STOP

THEORY:
DFT is a powerful tool for performing frequency analysis of discrete time signal and it is
described as a frequency domain representation of a DT sequence.
The DFT of a finite duration sequence x[n] is given by
N 1
 j 2 πnk/N
X (k) =  x(n)e k=0, 1….N-1
n0
which may conveniently be written in the form
N 1
X (k) =  x(n)w N
nk
k=0, 1….N-1
n0

where WN=e-j2/N which is known as Twiddle or Phase factor.

COMPUTATION OF DFT:
To compute DFT, it requires N2 multiplication and (N-1) N complex addition. Direct
computation of DFT is basically inefficient precisely because it does not exploit the symmetry
and periodicity properties of phase factor WN.

FAST FOURIER TRANSFORM (FFT):


FFT is a method of having computationally efficient algorithms for the execution of
DFT, under the approach of Divide and Conquer. The number of computations can be reduced in
N point DFT for complex multiplications to N/2log2N and for complex addition to N/2log2N.
Types of FFT are,
(i) Decimation In Time (DIT)
(ii) Decimation In Frequency (DIF)
IDFT USING FFT ALGORITHMS:
The inverse DFT of an N point sequence X (k), where k=0,1,2…N-1 is defined as ,

N 1
1  nk
x [n] =
N
 X (k )W N
n0

where, wN=e-j2/N.
Taking conjugate and multiplying by N, we get,
N 1
N x*[n] = 
* nk
X ( k )W N
k 0

The right hand side of the equation is the DFT of the sequence X*(k). Now x[n] can be
found by taking the complex conjugate of the DFT and dividing by N to give,
N 1
1

* nk *
x [n]= [ X (k )W N ]
N
k 0

RADIX-2 DECIMATION IN TIME FFT:


The idea is to successively split the N-point time domain sequence into smaller sub
sequence. Initially the N-point sequence is split into xe[n] and xo[n], which have the even and
odd indexed samples of x[n] respectively. The N/2 point DFT’s of these two sequences are
evaluated and combined to give N-point DFT. Similarly N/2 point sequences are represented
as a combination of two N/4 point DFT’s. This process is continued, until we are left with 2
point DFT.
RADIX-2 DECIMATION IN FREQUENCY FFT:
The output sequence X(k) is divided into smaller sequence.. Initially x[n] is divided
into two sequences x1[n], x2[n] consisting of the first and second N/2 samples of x[n]
respectively. Then we find the N/2 point sequences f[n] and g[n] as
f[n]= x1[n]+x2[n],
g[n]=( x1[n]-x2[n] )wNk
The N/2 point DFT of the 2 sequences gives even and odd numbered output samples. The above
procedure can be used to express each N/2 point DFT as a combination of two N/4 point DFTs.
This process is continued until we are left with 2 point DFT.

LIBRARY FUNCTION:
 fft: Discrete Fourier transform.
fft(x) is the discrete Fourier transform (DFT) of vector x. For matrices, the FFT operation
is applied to each column. For N-Dimensional arrays, the FFT operation operates on the first
non-singleton dimension.
 ditfft: Decimation in time (DIT)fft
ditfft(x) is the discrete Fourier transform (DFT) of vector x in time domain decimation
 diffft: Decimation in frequency (DIF)fft
diffft(x) is the discrete Fourier transform (DFT) of vector x in Frequency domain decimation

ALGORITHM/PROCEDURE:
1. Input the given sequence x[n]
2. Compute the Discrete Fourier Transform using FFT library function (ditfft or diffft) and
obtain X[k]
3. Compute the Inverse Discrete Fourier Transform using FFT library function (ditfft or
diffft) and obtain X[n] by following steps
a. Take conjugate of X [k] and obtain X[k]*
b. Compute the Discrete Fourier Transform using FFT library function (ditfft or
diffft) for X[k]* and obtain N.x[n]*
c. Once again take conjugate for N.x[n]* and divide by N to obtain x[n]
4. Display the results.
SOURCE CODE:(DITFFT)
clc;
clear all;
close all;
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the element:');
end
%% Call Dit_fft function
[re1,im1]= ditfft(re,im,N);
disp(re1);
disp(im1);
figure(1);
subplot(2,2,1);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,2);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');
%%dit_ifft

N=input('Enter the number of elements:');


for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the element:');
end
for i=1:N
re(i)=re(i);
im(i)=-im(i);
end
%% call dit_ifft function
[re1,im1]=ditifft(re,im,N);
for i=1:N
re1(i)=re1(i)/N;
im1(i)=-im1(i)/N;
end
disp(re1);
disp(im1);
%figure(2)
subplot(2,2,3);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,4);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');

Function Table:(DITFFT)
function [ re, im ] = ditfft( re, im, N)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
% Bit reversal sorting
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui-im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
Function Table:(DITIFFT)
function [ re,im] = ditifft(re,im,N)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
%Bit reversal sorting
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=-sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui+im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
end

RESULT:
The DFT and IDFT of the given sequence are computed using FFT algorithm using
DITFFT.
EX.No:5
DESIGN OF FIR FILTERS

AIM:
Write a MATLAB Script to design a low pass FIR filter using Window Method for the
given specifications
. APPARATUS REQUIRED:
PC, MATLAB software

THEORY:
A digital filter is a discrete time LTI system. It is classified based on the length of the
impulse response as
IIR filters:
Where h [n] has infinite number of samples and is recursive type.
FIR filters:
They are non-recursive type and h [n] has finite number of samples.
The transfer function is of the form:
N 1


n
H (z)  hn z
n0

This implies that it has (N-1) zeros located anywhere in the z-plane and (N-1) poles at Z
= h.
THE FIR FILTER CAN BE DESIGNED BY:
 Fourier series method
 Frequency sampling method
 Window method
Most of the FIR design methods are interactive procedures and hence require more
memory and execution time. Also implementation of narrow transition band filter is costly. But
there are certain reasons to go for FIR.
TYPES OF WINDOWS:
1. Rectangular
2. Triangular
3. Hamming
4. Hanning
5. Blackman
6. Kaiser
LIBRARY FUNCTIONS:
fir1 FIR filter design using the Window method.
B = fir1(N,Wn) designs an Nth order low pass FIR digital filter and returns the filter
coefficients of vector B of length (N+1). The cut-off frequency Wn must be between 0 <
Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter B is real and has
linear phase. The normalized gain of the filter at Wn is -6 dB.
B = fir1(N,Wn,'high') designs an Nth order high pass filter. You can also use
B = fir1(N,Wn,'low') to design a low pass filter.
If Wn is a two-element vector, Wn = [W1 W2], fir1 returns an order N band pass filter
with pass band W1 < W < W2.You can also specify B = fir1(N,Wn,'bandpass'). If Wn =
[W1 W2], B = fir1(N,Wn,'stop') will design a band-stop filter.
If Wn is a multi-element vector, Wn = [W1 W2 W3 W4 W5 ... WN], fir1 returns a N-
order multi-band filter with
bands 0 < W < W1, W1 < W < W2, ..., WN < W < 1.
B = fir1(N,Wn,'DC-1') makes the first band a pass band.
B = fir1(N,Wn,'DC-0') makes the first band a stop band.
B = fir1(N,Wn,WIN) designs an N-th order FIR filter using the vector WIN of (N+1)
length to window the impulse response. If empty or omitted, fir1 uses a Hamming
window of length N+1. For a complete list of available windows, see the Help for the
WINDOW function. KAISER and CHEBWIN can be specified with an optional trailing
argument. For example, B = fir1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with
beta=4. B = fir1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window with R
decibels of relative sidelobe attenuation.For filters with a gain other than zero at Fs/2,
e.g., high pass and band stop filters, N must be even. Otherwise, N will be incremented
by one. In this case, the window length should be specified as N+2. By default, the filter
is scaled so the center of the first pass band has magnitude exactly one after
windowing. Use a trailing 'noscale' argument to prevent this scaling, e.g.
B = fir1(N,Wn,'noscale'), B = fir1(N,Wn,'high','noscale'),
B = fir1(N,Wn,wind,'noscale'). You can also specify the scaling explicitly, e.g.
fir1(N,Wn,'scale'), etc.
We can specify windows from the Signal Processing Toolbox, such as boxcar, hamming,
hanning, bartlett, blackman, kaiser or chebwin

w = hamming(n) returns an n-point symmetric Hamming window in the column vector


w. n should be a positive integer.
w = hanning(n) returns an n-point symmetric Hann window in the column vector w. n
must be a positive integer.
w=triang(n) returns an n-point triangular window in the column vector w. The triangular
window is very similar to a Bartlett window. The Bartlett window always ends with zeros
at samples 1 and n, while the triangular window is nonzero at those points. For n odd, the
center (n-2) points of triang(n-2) are equivalent to bartlett(n).
w = rectwin(n) returns a rectangular window of length n in the column vector w. This
function is provided for completeness. A rectangular window is equivalent to no window
at all.

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
%windows technique of Rectangular window using low pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,boxcar(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');
Source code :2
%windows technique of Triangular(Bartlet Window) using High pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,'high',triang(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :3
%windows technique of Hamming using Band pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'bandpass',hamming(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :4
%windows technique of Hanning using Band stop filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'stop',hanning(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');

ylabel('Magnitude');
title('FIR Filter');

Source code :5
%windows technique of Blackman window using low pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,blackman(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

RESULT:
The given low pass filter was designed using Window method and manually verified
filter co-efficient of the filters.
EX.No:6 DESIGN OF BUTTERWORTH FILTERS
DATE:

AIM:
Write a MATLAB Script to design Analog Butterworth filters for the given
specifications.

APPARATUS REQUIRED:
PC, MATLAB software
THEORY:

BUTTERWORTH FILTER:
Low pass Analog Butterworth filters are all pole filters characterised by magnitude
frequency response by

2 1
H ( j ) = 2N
  
1  
 c 

where N is the order of the filter and c is the cut-off frequency.

As N , the low pass filter is said to be normalized. All types of filters namely-Low
pass, High pass, Band pass and Band elimination filters can be derived from the Normalized
Low pass filter.

STEPS IN DESIGNING ANALOG FILTER:


1. Transform the given specification to a Normalized Low pass specification
2. Find the order of the filter N and cut-off frequency c
3. Find the transfer function H(s) of normalized LPF.
4. Use the applicable analog-to-analog transformation to get the transfer function of the
required filter.

LIBRARY FUNCTIONS:

 butter: Butterworth digital and analog filter design.


[B, A] = butter (N,Wn) designs an Nth order Low pass digital Butterworth filter and
returns the filter coefficient vectors B (numerator) and A (denominator) in length N+1.
The coefficients are listed in descending powers of z. The cut-off frequency Wn must be
in the range 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate.
butter (N,Wn,'s'),butter (N,Wn,'low','s'),butter (N,Wn,'high','s'),butter (N,Wn,'pass','s')and
butter (N,Wn,'stop','s')design analog Butterworth filters. In this case, Wn is in [rad/s] and
it can be greater than 1.0.

 buttord: Butterworth filter order selection.


[N, Wn] = buttord (Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Butterworth filter that loses no more than Rp dB in the pass band and has at least Rs dB
of attenuation in the stop band. Wp and Ws are the pass band and stop band edge
frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For
example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
buttord: also returns Wn, the Butterworth natural frequency (or) the "3 dB frequency"
to be used with BUTTER to achieve the specifications.
[N, Wn] = buttord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second. When Rp is chosen as 3 dB, the Wn in
BUTTER is equal to Wp in BUTTORD.

 angle : Phase angle.


Theta=angle (H) returns the phase angles, in radians, of a matrix with complex elements.

 freqs : Laplace-transform (s-domain) frequency response.


H = freqs(B,A,W) returns the complex frequency response vector H of the filter B/A:

B(s) b (1)s nb-1 + b(2)s nb-2 + ... + b(nb)


H(s) = ---- = --------------------------------------------------
A(s) a(1)s na-1 + a(2)s na-2 + ... + a(na)

given the numerator and denominator coefficients in vectors B and A. The frequency
response is evaluated at the points specified in vector W (in rad/s). The magnitude and
phase can be graphed by calling freqs(B,A,W) with no output arguments.

 tf: Transfer function


SYS = tf(NUM,DEN) creates a continuous-time transfer function SYS with
numerator(s) NUM and denominator(s) DEN. The output SYS is a tf object.
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.
Butterworth Filters
SOURCE CODE:1
clc;
clear all;
close all;
%% Butterworth low pass Filter
% Filter Specifications

k1=input('Enter the passband gain in db:');


k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=butter(n,Wc,'low','s');

%Plotting magnitude & phase response

f=linspace(1,512,1000);
h=freqs(b,a,f);

m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth LPF');

% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');

SOURCE CODE:2
clc;
clear all;
close all;
%% Butterworth high pass Filter
% Filter Specifications

k1=input('Enter the passband gain in db:');


k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=butter(n,Wc,'high','s');

%Plotting magnitude & phase response

f=linspace(1,512,1000);
h=freqs(b,a,f);

m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth HPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth HPF');

SOURCE CODE:3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Band pass Filtering


[b,a]=butter(N,Wc,'bandpass','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

SOURCE CODE:4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];
%Band stop Filtering
[b,a]=butter(N,Wc,'stop','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

RESULT:
Analog Butterworth Filter is designed for the given specifications, and manually verified
the order, cut off frequency and filter co-efficient of the filter.
EX.No:7 DESIGN OF IIR FILTERS
DATE:

AIM:
Write a MATLAB Script to design Butterworth and Chebyshev low pass filters using
Bilinear Transformation
Impulse Invariant Transformation
. APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
A digital filter is a linear time invariant discrete time system. The digital filters are
classified into two, based on their lengths of impulse response
1. Finite Impulse response (FIR)
They are of non-recursive type and h [n] has finite number of samples
2. Infinite Impulse response (IIR)
h[n] has finite number of samples. They are of recursive type. Hence, their
transfer function is of the form


n
H (z)  h(n ) z
n0

M 1
k
 bk Z
K 0
H (Z ) 
N 1
 j
1  a jZ
j 1

The digital filters are designed from analog filters. The two widely used methods for
digitizing the analog filters include

1. Bilinear transformation
2. Impulse Invariant transformation

The bilinear transformation maps the s-plane into the z-plane by


1
2 1 Z
H(Z) = H (S ) |s  
1
T 1 Z

This transformation maps the jΩ axis (from Ω = -∞ to +∞) repeatedly around the unit circle (exp
( jw), from w=-π to π ) by

2  
  tan  
T  2 

BILINEAR TRANSFORMATION:
DESIGN STEPS:
1. From the given specifications, Find pre-warped analog frequencies using

2  
  tan  
T  2 

2. Using the analog frequencies, find H(s) of the analog filter


1
2 1 Z
3. Substitute S   in the H(s) of Step:2
1
T 1 Z

LIBRARY FUNCTIONS:

 Bilinear: Bilinear transformation method for analog-to-digital filter conversion. The


bilinear transformation is a mathematical mapping of variables. In digital filtering, it is a
standard method of mapping the s or analog plane into the z or digital plane. It transforms
analog filters, designed using classical filter design

ALGORITHM/PROCEDURE:
1. Calculate the attenuation in dB for the given design parameters
2. Design the analog counterpart
3. Using Bilinear transformation design the digital filter
4. Display the transfer function. Plot the magnitude response and phase response

SOURCE CODE:
/ Butterworth Lowpass Bilinear Transformation Method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,both the ripple gains should have band width( .1 to .3)
disp(' Butterworth Lowpass filter using Bilnear transformation method ');
T=input('Enter the Sampling Frequency in rad/sec: ');
Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');
% 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');

% Low Pass Filtering


[b,a]=butter(n,Wc,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);
% 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 Lowpass filters were designed using Bilinear transformations, and manually verified
the order, cut off frequency and filter co-efficient of the filters
EX.No:8 SAMPLING RATE CONVERSION
DATE:

AIM:
Write a MATLAB Script to perform sampling rate conversion for any given arbitrary
sequence (D.T) or signal (C.T) by interpolation, decimation, upsampling, downsampling and
resampling (i.e. fractional value)
.

APPARATUS REQUIRED:
PC, MATLAB software

THEORY:
SAMPLING PROCESS:
It is a process by which a continuous time signal is converted into discrete time signal.
X[n] is the discrete time signal obtained by taking samples of the analog signal x(t) every T
seconds, where T is the sampling period.
X[n] = x (t) x p (t)
Where p(t) is impulse train; T – period of the train

SAMPLING THEOREM:
It states that the band limited signal x(t) having no frequency components above Fmax Hz
is specified by the samples that are taken at a uniform rate greater than 2 Fmax Hz (Nyquist rate),
or the frequency equal to twice the highest frequency of x(t).
Fs ≥ 2 Fmax

SAMPLING RATE CONVERSION:


Sampling rate conversion is employed to generate a new sequence with a sampling rate
higher or lower than that of a given sequence. If x[n] is a sequence with a sampling rate of F Hz
and it is used to generate another sequence y[n] with desired sampling rate F’ Hz, then the
sampling rate alteration is given by,
F’/F = R
If R > 1, the process is called interpolation and results in a sequence with higher sampling
rate. If R< 1, the process is called decimation and results in a sequence with lower sampling rate.
DOWNSAMPLE AND DECIMATION:
Down sampling operation by an integer factor M (M>1) on a sequence x[n] consists of
keeping every Mth sample of x[n] and removing M-1 in between samples, generating an output
sequence y[n] according to the relation
y [n] = x[nM]
y [n] – sampling rate is 1/M that of x[n]
If we reduce the sampling rate, the resulting signal will be an aliased version of x[n]. To avoid
aliasing, the bandwidth of x[n] must be reduced to Fmax =Fx/2 π or max = π /M. The input
sequence is passed through LPF or an antialiasing filter before down sampling.
x [n] - y[n]
ANTIALIASING M

FILTER H (Z)
UPSAMPLE AND INTERPOLATION:
Upsampling by an integer factor L (L > 1) on a sequence x[n] will insert (L–1)
equidistant samples between an output sequence y[n] according to the relation

x[n/L], n = 0, 1, 2 ….
y[n] = 0, otherwise

The sampling rate of y[n] is L times that of x[n]. The unwanted images in the spectra of sampled
signal must be removed by a LPF called anti-imaging filter. The input sequence is passed
through an anti-imaging filter after up sampling.

x[n] ANTI IMAGING y[n]


L
FILTER H (Z)

SAMPLING RATE CONVERSION BY A RATIONAL FACTOR I/O:


We achieve this conversion, by first performing interpolation by the factor I and then
decimating the output of interpolator by the factor D, interpolation has to be performed before
decimation to obtain the new rational sampling rate.
x[n] ANTI IMAGING ANTI ALIASING DOWN y[n]
FILTER FILTER SAMPLER 
UPSAMPLER 
LIBRARY FUNCTIONS:

 resample: Changes sampling rate by any rational factor.


y = resample (x,p,q) resamples the sequence in vector x at p/q times the original sampling rate,
using a polyphase filter implementation. p and q must be positive integers. The length of y is
equal to ceil (length(x)*p/q).

 interp: Increases sampling rate by an integer factor (interpolation)


y = interp (x,r) increases the sampling rate of x by a factor of r. The interpolated vector y is r
times longer than the original input x. ‘interp’ performs low pass interpolation by inserting zeros
into the original sequence and then applying a special low pass filter.

 upsample: Increases the sampling rate of the input signal


y = upsample(x,n) increases the sampling rate of x by inserting n-1 zeros between samples. The
upsampled y has length(x)*n samples

 decimate: Decreases the sampling rate for a sequence (decimation).


y = decimate (x, r) reduces the sample rate of x by a factor r. The decimated vector y is r times
shorter in length than the input vector x. By default, decimate employs an eighth-order low pass
Chebyshev Type I filter. It filters the input sequence in both the forward and reverse directions to
remove all phase distortion, effectively doubling the filter order.

 downsample: Decreases the sampling rate of the input signal


y = downsample(x,n) decreases the sampling rate of x by keeping every nth sample starting with
the first sample. The downsampled y has length(x)/n samples

ALGORITHM/PROCEDURE:
1. Generate a sinusoidal waveform
2. Using the appropriate library function for interpolation ,decimation ,upsampling ,
downsampling and resampling, perform sampling rate conversion for the sinusoidal
waveform
3. Find the spectrum of all the signals and compare them in frequency domain.
4. Display the resultant waveforms

Source code :
clc;
clear all;
close all;
%continuous sinusoidal signal
a=input('Enter the amplitude:');
f=input('Enter the Timeperiod:');
t=-10:1:20;
x=a*sin(2*pi*f*t);
subplot(2,3,1);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%decimating the signal
d=input('Enter the value by which the signal is to be decimated:');
y1=decimate(x,d);
subplot(2,3,2);
stem(y1);
xlabel('time');
ylabel('Amplitude');
title('Decimated signal');
%interpolating the signal
i=input('Enter the value by which the signal is to be interpolated:');
y2=interp(x,i);
subplot(2,3,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('Interpolated signal');
%resampling the signal
y3=resample(x,3,2);
subplot(2,3,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('Resampled signal');
%downsampling the signal
y4=downsample(x,2);
subplot(2,3,5);
stem(y4);
xlabel('time');
ylabel('Amplitude');
title('Downsampled signal');
%upsampling the signal
y5=upsample(x,3);
subplot(2,3,6);
stem(y5);
xlabel('time');
ylabel('Amplitude');
title('Upsampled signal');

RESULT:
The program written using library functions and the sampling rate conversion process is
studied.
POWER SPECTRUM ESTIMATION USING
EX.No:9
PERIODOGRAM
DATE:
AIM:
Write a MATLAB Script to perform Power spectrum estimation using periodogram

APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

Source code:
%Power spectrum estimate using Periodogram
n=inpue(‘Enter the length of the sequence’);
window=hamming(n);
nfft=input(‘Length of the FFT’);
fs=input(‘Sampling frequency’);
x=cos(2*0.1*pi*n/fs)+sin(2*4*pi*n/fs)+0.01*randn(size(n));
subplot(2,1,1),plot(n,x);
xlabel(‘n’),ylabel(‘x(n)’);
[pxx,f]=peridogram(x,window,nfft,fs);
Subplot(2,1,2);
Plot(f/fs,10*log10(pxx));grid;
Xlabel(‘\omega/\pi’),ylabel(‘Power spectrum’);

S-ar putea să vă placă și