DSP LAB Digital Signal Processing Laboratory Manual
DSP LAB Digital Signal Processing Laboratory Manual
PREPARED BY
Lab Instructor
AY 2021-22
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
VISION
“To be the centre of excellence in teaching and learning to produce the competent &
socially responsible professionals in the domain of ELECTRONICS &
COMMUNICATION ENGINEERING.”
MISSION
To educate students with core knowledge of Electrical and Electronics
To develop problem solving skills, professional skills and ethical values among
the students for the betterment of mankind.
To prepare technically competent and socially responsible Electrical Engineer to serve
the future needs of the society.
PSO2: Use software/hardware tools for the design, simulation and analysis of
Electrical and Electronics Systems.
ELECTRONICS & COMMUNICATION ENGINEERING
*
Overview
Year / Semester 3rd Year ECE / 6th Semester Academic Year 2021 - 2022
DIGITAL SIGNAL PROCESSING LABORATORY
Laboratory Title
Total Contact Hours 42 Exam Hours 3 Hours
Objectives
To explain the use of MATLAB software in evaluating the DFT and IDFT of given sequence
To verify the convolution property of the DFT
To design and implementation of IIR and FIR filters for given frequency specifications.
To realize IIR and FIR filters.
To help the students in developing software skills
Course Outcomes
Prerequisites
MATLAB programming language.
Basic operation such as creating file, delete, copy, rename etc should be known.
DSP algorithm operation should be understood.
Base Course
Signals and Systems
Digital Signal Processing
Resource Required
MATLAB software.
Page 1
ELECTRONICS & COMMUNICATION ENGINEERING
Introduction
MATLAB Windows:
MATLAB works with through these basic windows
Command Window
This is the main window .it is characterized by MATLAB command prompt >> when you launch
the application program MATLAB puts you in this window all commands including those for
user-written programs ,are typed in this window at the MATLAB prompt
Page 2
ELECTRONICS & COMMUNICATION ENGINEERING
*
Graphics Window
The output of all graphics commands typed in the command window are flushed to the graphics or
figure window, a separate gray window with white background color the user can create as many
windows as the system memory will allow.
Edit Window
This is where you write edit, create and save your own programs in files called M files.
Input-output
MATLAB supports interactive computation taking the input from the screen and flushing, the
output to the screen. In addition it can read input files and write output files.
Data Type
The fundamental data distinct data objects- integers, real numbers, matrices, character strings,
structures and cells. There is no need to declare variables as real or complex, MATLAB
automatically sets the variable to be real.
Dimensioning
Dimensioning is automatic in MAT required for vectors or arrays .we can find the dimensions of
an existing matrix or a vector with the size and length commands.
Page 3
ELECTRONICS & COMMUNICATION ENGINEERING
*
Expt.
Experiment
No.
1 Verification of Sampling Theorem both in time and frequency domains.
2 Evaluation of impulse response of a system.
3 To perform linear convolution of given sequences.
To perform circular convolution of given sequences using (a) the convolution summation
4 formula (b) the matrix method and (c) Linear convolution from circular convolution with
zero padding.
5 Computation of N – point DFT and to plot the magnitude and phase spectrum.
6 Linear and circular convolution by DFT and IDFT method.
7 Solution of a given difference equation.
8 Calculation of DFT and IDFT by FFT
9 Design and implementation of IIR filters to meet given specification (Low pass, high pass,
band pass and band reject Filters)
10 Design and implementation of FIR filters to meet given specification (Low pass, high pass,
band pass and band reject filters) using different window functions
11 Design and implementation of FIR filters to meet given specification (Low pass, high pass,
band pass and band reject filters) using frequency sampling technique.
12 Realization of IIR and FIR filters.
Reference
Proakis & Monalakis, Digital Signal processing Principles Algorithms & Applications, Pearson
Education, Edition, New Delhi, 2007.
Oppenheim & Schaffer, Discrete Time signal Processing, PHI. 2003.
S. K. Mitra, Digital Signal processing, Tata Mc-Graw Hill, 2nd Edition, 2004.
Lee Tan: Digital signal processing, Elsevier publications, 2007.
Practical C++ programming by Oreilly.
Introduction to programming with MATLAB for scientists and Engineers, 2e Broenkow,ML 2007.
MATLAB and introduction with applications 2nd edition- Amos Gillat.
Evaluation Scheme
CIE Marks: 50
Internal Assessment: 15 Marks
Write-up: 02 Marks
Conduction & result: 10 Marks
Viva-voce: 03 Marks
Continues Assessment: 15
Scheme of External Examination
External Exam will be conducted for 35 Marks and obtained marks will be scaled down for
50 Marks by university
Page 6
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 1
1.0 Verification of Sampling Theorem both in time and frequency domains.
1.1 Aim
To verify Sampling theorem for a signal of given frequency.
1.2 Theory
Sampling is a process of converting a continuous time signal (analog signal) x (t) into a discrete time
signal x[n], which is represented as a sequence of numbers. (A/D converter). Converting back x[n]
into analog (resulting in x(t) ) is the process of reconstruction. (D/A converter). For x(t) to be exactly
the same as x (t), sampling theorem in the generation of x(n) from x(t) is used. The sampling
frequency fs determine the spacing between samples. Aliasing-A high frequency signal is converted to
a lower frequency, results due to under sampling. Though it is undesirable in ADCs, it finds practical
applications in stroboscope and sampling oscilloscopes. Sampling theorem: Sampling theorem
includes two definitions.
A band limit of the signal which is having finite energy, whose maximum frequency component is W
Hz can be completely representing into its samples at the rate of 2W samples/sec.
A band limit of the signal which is having finite energy, whose maximum frequency component is W
Hz, can be completely recovered from its samples at the rate of 2W samples/sec.
Nyquist Rate Sampling: The Nyquist rate is the minimum sampling rate required to avoid aliasing,
equal to the highest modulating frequency contained within the signal. In other words, Nyquist rate is
equal to two sided bandwidth of the signal (Upper and lower sidebands) i.e. fs = 2W.To avoid aliasing,
the sampling rate must exceed the Nyquist rate. i. e. fs>fN, where fN =2W.
1.2 Algorithm
Page 7
ELECTRONICS & COMMUNICATION ENGINEERING
*
Step 1: MATLAB can generate only discrete time signals. For an approximate analog signal xt,
choose the spacing between the samples to be very small (≈0), say 50µs = 0.00005. Next choose the
time duration, say xt exists for 0.05seconds. (tfinal in program) (For low frequency say <1000 Hz
choose 0.05 secs, for higher choose 0.01 secs or lesser as appropriate). Now begin with the vector that
represents the time base-
t = 0:0.00005:0.05;
The colon (:) operator in MATLAB creates a vector, in the above case a time vector running from 0 to
0.05 in steps of 0.00005. The semicolon (;) tells MATLAB not to display the result. Given t, the
analog signal xt of frequency f is generated as (cos (ωt) =cos (2πft)):-
xt=cos(2*pi*f*t);
Where pi is recognized as 3.14 by MATLAB.
Step 2: To illustrate oversampling condition, choose sampling frequency fs0=2.2*f. For this sampling
rate T0=1/fs0, generate the time vector as n1 = 0:T0:0.05; & over sampled discrete time signal x1=cos
(2*pi*f*n1);
Step 3: Repeat step 2 for different sampling frequencies, i.e., fs=1.3*f & fs=2*f for under sampling
and Nyquist sampling conditions.
Page 8
ELECTRONICS & COMMUNICATION ENGINEERING
*
clc; figure(2);
close all; plot(f,abs(xk));
clear all; xlabel('frequency');
f1 = input('Enter the first sine wave frequency = '); ylabel('amplitude');
f2= input('Enter the second sine wave frequency = '); title('Nyquist Rate Sampling');
fn = 2*max(f1,f2); grid;
fs = fn/2; fs = 2*fn;
t = [0:1/fs:0.1]; t = [0:1/fs:0.1];
x = cos(2*pi*f1*t)+cos(2*pi*f2*t); x = cos(2*pi*f1*t)+cos(2*pi*f2*t);
xk = fft(x); xk = fft(x);
f = [0:length(xk)-1]*fs/length(xk); f = [0:length(xk)-1]*fs/length(xk);
figure(1);
plot(f,abs(xk)); figure(3);
xlabel('frequency'); plot(f,abs(xk));
ylabel('amplitude'); xlabel('freq');
title('Under Sampling'); ylabel('amplitude');
grid; title('Over Sampling');
fs = fn; grid;
t = [0:1/fs:0.1];
x = cos(2*pi*f1*t)+cos(2*pi*f2*t);
xk = fft(x);
f = [0:length(xk)-1]*fs/length(xk);
1.6 Inference
From the under sampling plot observe the aliasing effect. The analog signal is of 200Hz (T=0.005s).
The reconstructed (from under sampled plot) is of a lower frequency. The alias frequency is
computed as fd-fs1 = 200-1.3*200 = 200-260= -60Hz. This is verified from the plot.
The minus sign results in an 180˚ phase shift.
Sampling at the Nyquist rate results in samples sin(πn) which are identically zero, i.e., we are
sampling at the zero crossing points and hence the signal component is completely missed. This
can be avoided by adding a small phase shift to the sinusoid. The above problem is not seen in
cosine waveforms (except cos (90n)). A simple remedy is to sample the analog signal at a rate
higher than the Nyquist rate. The Fig1.2 shows the result due to a cosine signal
(x1=cos(2*pi*fd*n1);
The over sampled plot shows a reconstructed signal almost similar to that of the analog signal. Using
low pass filtering the wave form can be further smoothened.
Page 9
ELECTRONICS & COMMUNICATION ENGINEERING
*
Frequency Domain
1.8 Results
1.9 Conclusion
Page 10
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 2
2.0 Evaluation of impulse response of a system
2.1 Aim
2.2 Theory
LTI Discrete time system is completely specified by its impulse response i.e. knowing the impulse
response we can compute the output of the system to any arbitrary input. Let h[n] denotes the impulse
response of the LTI discrete time systems. Since discrete time system is time invariant, its response to
[n-1] will be h[n-1] .Likewise the response to [n+2] , [n-4] and [n-6] will be h[n+2], h[n-4] and h[n-
6] .
From the above result arbitrary input sequence x[n] can be expressed as a weighted linear combination
of delayed and advanced unit sample in the form k=+ and k=-x[n] = x[k] h[n-k]
where weight x[k] on the right hand side denotes specifically the k th sample value of the sequence.
The response of the LTI discrete time system to the sequence x[k] [n-k] will be x[k] h [n-k].
As a result, the response y[n] of the discrete time system to x[n] will be given by
y[n] = x[k] h [n-k] …………..(1)
This can be alternately written as
y[n] = x[n-k] h [k]…………(2)
The above equation (1) and (2) is called the convolution sum of the sequences x[n] and h[n] and
represented compactly as y[n] =x[n] * h[n] Where the notation * denotes the convolution sum.
Structure for Realization of Linear Time Invariant systems: Let us consider the first order system
Y(n)=-a 1y(n-1)+b0 x(n) +b1 x(n-1).This realization uses separate delays(memory) for both the input
and output samples and it is called as Direct form one structure. A close approximation reveals that the
two delay elements contain the same input w (n) and hence the same output w(n-1).consequently these
two elements can be merged into one delay. In contrast to the direct form I structure, this new
realization requires only one delay for auxiliary quantity w (n), and it is more efficient in terms of
memory requirements. It is called the direct form II structure and it is used extensively.
2.3 Algorithm
Page 11
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 12
ELECTRONICS & COMMUNICATION ENGINEERING
*
Input:
enter the coefficient of x(n),x(n-1)..= [1 0.5 0.85]
enter the coefficient of y(n),y(n-1)..= [1 -1 -1]
enter the no of samples of imp response=4
Output
1.0000
1.5000
3.3500
4.8500
2.8 Results
2.9 Conclusion
Page 13
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 3
3.1 Aim
To obtain Linear convolution of two finite duration sequences.
3.2 Theory Convolution is an integral concatenation of two signals. It has many applications in
numerous areas of
signal processing. The most popular application is the determination of the output signal of a linear
time-invariant system by convolving the input signal with the impulse response of the system. Note
that convolving two signals is equivalent to multiplying the Fourier transform of the two signals. In
linear systems, convolution is used to describe the relationship between three signals of interest: the
input signal, the impulse response, and the output signal. In linear convolution length of output
sequence is, length(y (n)) = length(x (n)) + length (h (n)) – 1.
Mathematical Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
Where x (n) is the input signal and h (n) is the impulse response of the system.
3.3 Algorithm
The timing information for a sequence is provided by another vector, say n=-3:5; creates a vector with
values from -3 to 5 with an increment of 1. During plotting, the time vector size and the sequence size
should be the same, i.e., the number of elements in the sequence x1 and in its time vector n1 should be
the same. Similarly for x2 and y.
Page 14
ELECTRONICS & COMMUNICATION ENGINEERING
*
3.5 Calculation
On simplification we get,
Z=X1*X2
On Simplification, we get
Page 15
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 16
ELECTRONICS & COMMUNICATION ENGINEERING
*
3.9 Results
3.10 Conclusion
Page 17
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 4
4.0 (a) Circular Convolution of two given sequences using summation formula.
(b) Aim
To write MATLAB program to find circular convolution by matrix method.
(c) Aim
To find linear convolution from circular convolution using MATLAB program with zero
As seen in the last experiment, the output y[n] of a LTI (linear time invariant) system can be obtained
by convolving the input x[n] with the system‟s impulse response h[n]. The above linear
convolution is generally applied to aperiodic sequences. Whereas the Circular Convolution is used
to study the interaction of two signals that are periodic.
n k N implies circular shifting operation and k N implies folding the sequence circularly.
Steps for circular convolution are the same as the usual convolution, except all index calculations are done
"mod N" = "on the wheel".
Plot f [m] and h [−m] as shown in Fig. 4.1. (use f(m) instead of x(k))
Multiply the two sequences
Add to get y[m]
"Spin" h [−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m].
Where x[n] and h[n] can be both finite and infinite duration sequences. If infinite sequences, they
should be periodic, and the N is chosen to be at least equal to the period. If they are finite
Page 18
ELECTRONICS & COMMUNICATION ENGINEERING
*
sequences N is chosen as >= to max (xlength, hlength). Whereas in linear convolution N>=
xlength+hlength-1.
Let x1(n) and x2(n) are finite duration sequences both of length N with DFT‟s X1(k) and
X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the equation,
x3(n) = IDFT[X3(k)]where X3(k) = X1(k) X2(k)
Matrix Method for Convolution: Due to the importance of Discrete Fourier Transform (DFT) in signal
processing application, it is critical to have an efficient method to compute this algorithm. DFT operates on a N
-point sequence of numbers, referred to as x(n) . The value x(n) is presented in time domain data and usually
can be taught as a uniformly sampled version of a finite period of a continuous function f (x) . The DFT of x(n)
sequence is transformed to X(k) in frequency domain representation employing by using Discrete Fourier
Transform. The functions x(n) and X(k) is generally represented in complex signal form, given by
Where x(n) is the input time domain representation and N is the number of input to the DFT. The value
n represents the discrete time-domain index and k is the normalized frequency domain index. The description of
efficient computation is discussed on DFT methods since the IDFT and DFT consumes the same type of
computational algorithm. From the computation of each value of k , it is observed that direct computation of
X(k) involves N complex multiplications ( 4N real multiplications) and N −1 complex additions ( 4N − 2 real
additions). Eventually, to compute all N values of the DFT requires N2 complex multiplications and N2 − N
complex additions. The multiplication of two discrete time signals in discrete Fourier transform is equivalent to
the circular convolution of their sequences in time domain. For x(n) and h(n) signal convolution is express as:
Here the term h(m-n)N indicates the circular convolution. The convolution in time domain of two
signal x and h is perform by multiplying its discrete fourier transform and the converting it in time domain by
inverse discrete fourier transform. The equation of DFT is the summation of discrete signal multiplied by
Page 19
ELECTRONICS & COMMUNICATION ENGINEERING
*
4.3 Algorithm
Page 20
ELECTRONICS & COMMUNICATION ENGINEERING
*
MATLAB recognizes index 1 to be positive maximum. Index 0 is not recognized. Hence in the below
program wherever y, x and h sequences are accessed, the index is added with +1. the modulo index
calculation for circular convolution is carried out using the function - MOD Modulus (signed
remainder after division). MOD(x, y) is x - y.*floor(x./y) if y ~= 0. By convention, MOD(x, 0) is x.
The input x and y must be real arrays of the same size, or real scalars. MOD(x, y) has the same sign as
Page 21
ELECTRONICS & COMMUNICATION ENGINEERING
*
y while REM(x, y) has the same sign as x. MOD(x, y) and REM(x, y) are equal if x and y have the
same sign, but differ by y if x and y have different signs.
MATLAB program to find Circular Convolution by matrix multiplication using circshift command or
we can use convmtx command.
A = convmtx (h,n) returns the convolution matrix, A, such that the product of A and a vector, x, is the
convolution of h and x. If h is a column vector of length m, A is (m+n-1)-by-n and the product of A
and a column vector, x, of length n is the convolution of h and x. If h is a row vector of length m, A is
n-by-(m+n-1) and the product of a row vector, x, of length n with A is the convolution of h and x.
Convmtx handles edge conditions by zero padding.
= circshift(A,K) circularly shifts the elements in array A by K positions. If K is an integer, then
circshift shifts along the first dimension of A whose size does not equal 1. If K is a vector of integers,
then each element of K indicates the shift amount in the corresponding dimension of A.
Y = circshift(A,K,dim) circularly shifts the values in array A by K positions along dimension dim.
Inputs K and dim must be scalars.
4.5 Calculation
Page 22
ELECTRONICS & COMMUNICATION ENGINEERING
*
x(n)= [ 1 2 1 2 1 2]
h(n)= [1 2 3 4]
M= length(x) + length(h)-1
=6+4 -1
=9
x(n) = [ 1 2 12 12 0 0 0]
h(n)= [ 1 2 34 0 0 0 0 0]
y(n)= x(n).h(n)
1 0 0 0 2 1 1 2 1 1
2 1 0 0 0 2 2 1 2 2
1 2 1 0 0 0 1 2 1 3
2 1 2 1 0 0 2 1 2 4
y(n)= 1 2 1 2 1 0 0 2 1 . 0
2 1 2 1 2 1 0 0 2 0
0 2 1 2 1 2 0 0 0 0
0 0 2 1 2 1 1 0 0 0
0 0 0 2 1 2 2 1 0 0
y(n)= [ 1 4 8 14 16 14 15 10 8]
Page 23
ELECTRONICS & COMMUNICATION ENGINEERING
*
y(n+1)=y(n+1)+hn(k+1)*xn(i+1);
end;
end;
disp('circular convolution output‟);
disp(y);
subplot(2,2,1);
stem(xn);
xlabel('n');
ylabel('x(n)');
title('plot of h(n)');
subplot(2,2,2);
stem(hn);
xlabel('n');
ylabel('h(n)');
title('plot of h(n)');
subplot(2,1,2);
stem(y);
xlabel('n');
ylabel('y(n)');
title('circular convolution output');
Page 24
ELECTRONICS & COMMUNICATION ENGINEERING
clc;
close all;
clear all;
x1=input('enter the first sequence=');
x2=input('enter the second sequence=');
n=input('enter the no of points of the dft=');
subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');
subplot(3,1,2);
Page 25
ELECTRONICS & COMMUNICATION ENGINEERING
*
stem(x2,'filled');
title('plot of second sequence');
n1=length(x1);
n2=length(x2);
m=n1+n2-1;
x=[x1 zeros(1,n2-1)];
y=[x2 zeros(1,n1-1)];
x_fft=fft(x,m);
y_fft=fft(y,m);
dft_xy=x_fft.*y_fft
y=ifft(dft_xy,m);
disp('the circular convolution result is');
disp(y);
subplot(3,1,3);
stem(y,'filled');
title('plot of circularly convoluted sequence');
Input:
enter the first sequence x(n)=[1 1 2 1]
enter the second sequence h(n)=[1 2 3 4]
Output:
circular convolution output
13 14 11 12
Page 26
ELECTRONICS & COMMUNICATION ENGINEERING
*
4.8 Results
4.9 Conclusion
Page 27
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 5
5.0 Computation of N point DFT of a given sequence and to plot magnitude and phase
spectrum.
5.1 Aim
To compute N-point DFT of a given sequence and to plot magnitude and phase spectrum.
5.2 Theory
Discrete Fourier Transform is a powerful computation tool which allows us to evaluate the Fourier
Transform X (ejw) on a digital computer or specially designed digital hardware. Since X(ej ) is
continuous and periodic, the DFT is obtained by sampling one period of the Fourier Transform at a
finite number of frequency points. Apart from determining the frequency content of a signal, DFT is
used to perform linear filtering operations in the frequency domain.
The sequence of N complex numbersx0... xN−1 is transformed into the sequence of N complex numbers
X0... XN−1 by the DFT according to the formula:
k = 0,1, …. N-1
5.3 Algorithm
MATLAB has an inbuilt function FFT‟ which computes the Discrete Fourier transform. FFT(X) is
the discrete Fourier transform (DFT) of vector X. For length N input vector x, the DFT is a length N
vector X, with elements N. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N
points and truncated if it has more. The magnitude spectrum is computed using the function ABS
Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is
the complex modulus (magnitude) of the elements of X. The phase spectrum is computed using the
function ANGLE Phase angle. ANGLE (H) returns the phase angles, in radians, of a matrix with
complex elements.
Page 28
ELECTRONICS &
COMMUNICATION
ENGINEERING
*
5.5 MATLAB Program: Computation of N point DFT of a given sequence and to plot
magnitude and phase spectrum.
clc;
close all;
clear all;
x=input('enter the sequence= ');
N=input('enter the no of dft points= ');
xk=fft(x,N);
disp('N point DFT of the sequence is=')
disp(xk);
n=0:1:N-1;
figure(1);
stem(n,abs(xk));
disp('magnitude of the sequence is=')
disp(abs(xk));
xlabel('k');
ylabel('|xk|');
title('magnitude spectrum');
figure(2);
stem(angle(xk));
disp('phase value of the sequence is=')
disp(angle(xk));
xlabel('k');
ylabel('angle (xk)');
title('phase spectrum');
figure(3);
n1=0:1:length(x)-1;
stem(n1,x);
xlabel('n');
ylabel('x[n]');
title('original signal');
Page 29
ELECTRONICS & COMMUNICATION ENGINEERING
*
5.6 Calculation
EXAMPLE:
Let us assume the input sequence x[n] = [1 1 0
0] We have,
k = 0,1, …. N-1
For k = 0,
X(1) = 1 – j
For k = 2
Page 30
ELECTRONICS & COMMUNICATION ENGINEERING
*
5.8 Results
5.9 Conclusion
Page 31
ELECTRONICS & COMMUNICATION ENGINEERING
*
Experiment 6
6.1 Aim
To write MATLAB program to verify linear and circular convolution by DFT and IDFT
method. 6.2 Theory
Circular convolution is another way of finding the convolution sum of two input signals. It resembles
the linear convolution, except that the sample values of one of the input signals is folded and right
shifted before the convolution sum is found. Also note that circular convolution could also be found by
taking the DFT of the two input signals and finding the product of the two frequency domain signals.
The Inverse DFT of the product would give the output of the signal in the time domain which is the
circular convolution output. The two input signals could have been of varying sample lengths. But we
take the DFT of higher point, which ever signals levels to. For e.g. If one of the signal is of length 256
and the other spans 51 samples, then we could only take 256 point DFT. So the output of IDFT would
be containing 256 samples instead of 306 samples, which follows N1+N2 – 1 where N1
N2 are the lengths 256 and 51 respectively of the two inputs. Thus the output which should have been
306 samples long is fitted into 256 samples. The 256 points end up being a distorted version of the
correct signal. This process is called circular convolution. Circular convolution is explained using the
following example.
6.3 Algorithm
Give input sequence x[n].
Give impulse response sequence h[n].
Find the Circular Convolution and linear convolution y[n] using the DFT method.
Plot x[n],h[n],y[n].
Page 32
ELECTRONICS & COMMUNICATION ENGINEERING
*
6.4 Calculation
Circular Convolution
x[n]= [1 2 3 4] y[n]= [3 5 2 1]
x(k)=
h(k)=
1
y(n)=
4
y(n)=
Page 33
ELECTRONICS & COMMUNICATION ENGINEERING
*
clc; clc;
close all; close all;
clear all; clear all;
x1=input('enter the first sequence='); x=input('enter input x(n)= ');
x2=input('enter the second sequence='); m=length(x)
n=input('enter the no of points of the dft='); h=input('enter input h(n)= ');
subplot(3,1,1); n=length(h)
stem(x1,'filled'); subplot(3,2,1);
title('plot of first sequence'); stem(x);
subplot(3,1,2); title('input sequence x(n)');
stem(x2,'filled'); xlabel('----->n');
title('plot of second sequence'); ylabel('----->amplitude');
n1=length(x1); grid;
n2=length(x2); subplot(3,1,2);
m=n1+n2-1; stem(h);
x=[x1 zeros(1,n2-1)]; title('input sequence h(n)');
y=[x2 zeros(1,n1-1)]; xlabel('----->n');
x_fft=fft(x,m); ylabel('----->amplitude');
y_fft=fft(y,m); grid;
dft_xy=x_fft.*y_fft disp('circular convolution of x(n) &h(n) ');
y=ifft(dft_xy,m); y1=fft(x,n);
disp('the linear convolution result is'); y2=fft(h,n);
disp(y); y3=y1.*y2;
subplot(3,1,3); y=ifft(y3,n);
stem(y,'filled'); disp(y);
title('plot of linearly convoluted sequence'); subplot(3,1,3);
stem(y);
title('circular convoluted output');
xlabel('----->n');
ylabel('----->amplitude');
grid;
Page 34
ELECTRONICS & COMMUNICATION ENGINEERING
*
6.8 Results
6.9 Conclusion
Page 35
ELECTRONICS & COMMUNICATION ENGINEERING
*
Experiment 7
7.1 Aim
To obtain the impulse response/step response of a system described by the given difference equation.
7.2 Theory
A difference equation with constant coefficients describes a LTI system. For example the difference
equation y[n] + 0.8y[n-2] + 0.6y[n-3] = x[n] + 0.7x[n-1] + 0.5x[n-2] describes a LTI system of
order 3. The coefficients 0.8, 0.7, etc are all constant i.e., they are not functions of time
(n). The difference equation y[n]+0.3ny[n-1]=x[n] describes a time varying system as the
coefficient 0.3n is not constant.
The difference equation can be solved to obtain y[n], the output for a given input x[n] by rearranging
as y[n] = x[n] + 0.7x[n-1]+0.5x[n-2]- 0.8y[n-2]- 0.6y[n-3] and solving.
The output depends on the input x[n]
With x[n]= δ[n], an impulse, the computed output y[n] is the impulse response.
If x[n]=u[n], a step response is obtained.
If x[n] = cos(wn) is a sinusoidal sequence, a steady state response is obtained (wherein y[n] is of the
same frequency as x[n], with only an amplitude gain and phase shift-refer Fig.7.3).
Similarly for any arbitrary sequence of x[n], the corresponding output response y[n] is computed.
The difference equation containing past samples of output, i.e., y[n-1], y[n-2], etc leads to a recursive
system, whose impulse response is of infinite duration (IIR). For such systems the impulse
response is computed for a large value of n, say n=100 (to approximate n=∞). The
MATLAB function filter is used to compute the impulse response/ step response/ response to any
given x[n]. Note: The filter function evaluates the convolution of an infinite sequence (IIR) and
x[n], which is not possible with conv function (remember conv requires both the sequences to be
finite).
The difference equation having only y[n] and present and past samples of input (x[n], x[n-k]),
represents a system whose impulse response is of finite duration (FIR). The response of FIR
systems can be obtained by both the conv‟ and filter‟ functions. The filter function results in a
response whose length is equal to that of the input x[n], whereas the output sequence from conv
function is of a longer length (xlength + hlength-1).
Page 36
ELECTRONICS & COMMUNICATION ENGINEERING
*
7.4 Algorithm
7.5 Calculation
The difference equation is given by
y(n) = x(n)+0.7x(n-1)+0. 5x(n-2)-0.8y(n-2)-0.6y(n-3)
y(z)+0.8z-2+0.6z-3 y(z)=x(z)+0.7z-1 x(z) + 0.5 z-2
x(z) y(z) [1+0.8z-2+0.6z-3=x(z)+(1+0.7z-1+0.5z-2)]
H(z)= y(z)
x(z)
(1+0.7z-1+0.5z-2)
(1+0.8z-1+0.6z-3)
Page 37
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 38
ELECTRONICS & COMMUNICATION ENGINEERING
*
7.8 Result
7.9 Conclusion
Page 39
ELECTRONICS & COMMUNICATION ENGINEERING
*
Experiment 8
8.1 Aim
To write a MATLAB program for computation of DFT and IDFT using Direct and FFT method
8.2 Theory
DFT:
Discrete Fourier Transform (DFT) is used for performing frequency analysis of discrete time signals.
DFT gives a discrete frequency domain representation whereas the other transforms are continuous in
frequency domain. The N point DFT of discrete time signal x[n] is given by the equation.
The inverse DFT allows us to recover the sequence x[n] from the frequency samples
FFT:
A fast Fourier transform (FFT) is an efficient algorithm to compute the discrete Fourier transform
(DFT) and its inverse. FFTs are of great importance to a wide variety of applications, from digital
signal processing and solving partial differential equations to algorithms for quick multiplication of
large integers. Evaluating the sums of DFT directly would take O(N 2) arithmetical operations. An
FFT is an algorithm to compute the same result in only O(N log N) operations. In general, such
algorithms depend upon the factorization of N, but there are FFTs with O(N log N) complexity for all
N, even for prime N. Since the inverse DFT is the same as the DFT, but with the opposite sign in the
exponent and a 1/N factor, any FFT algorithm can easily be adapted for it as well.
8.3 Algorithm
Get the input sequence
Find the DFT of the input sequence using direct equation of DFT.
Find the IDFT using the direct equation.
Find the FFT of the input sequence using MATLAB function.
Find the IFFT of the input sequence using MATLAB function.
Display the above outputs using stem function
Page 40
ELECTRONICS & COMMUNICATION ENGINEERING
*
8.4 Calculation
x(n)=[1 1 1 1 1 1 0 0 ]
this equation is formulated in the matrix form by equation
XN= [Wn] xN
with N=8 x8=[W8]x8
Page 41
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 42
ELECTRONICS & COMMUNICATION ENGINEERING
*
Output:
xf= 6.0000 -0.7071 - 1.7071i 1.0000 - 1.0000i 0.7071 + 0.2929i 0 - 0.0000i
0.7071 - 0.2929i 1.0000 + 1.0000i -0.7071 + 1.7071i
pn = 1.0000 - 0.0000i 1.0000 1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 + 0.0000i
1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
xp = 6.0000 -0.7071 - 1.7071i 1.0000 - 1.0000i 0.7071 + 0.2929i 0
0.7071 - 0.2929i 1.0000 + 1.0000i -0.7071 + 1.7071i
xw = 1 1 1 1 1 1 0 0
8.7 Results
8.8 Conclusion
Page 43
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 9
9.0 Design and implementation of IIR filter to meet given specifications.
9.1 Aim
Design and implementation of IIR filter to meet given specifications.
9.2 Theory
Infinite Impulse Response (IIR) filter: IIR filters are of recursive type, whereby the present output
sample depends on the present input, past input samples and output samples. The impulse response
h(n) for a realizable filter is,h(n) = 0 for n 0. And for stability, it must satisfy the condition,
There are two methods of stating the specifications as illustrated in previous program. In the first
program, the given specifications are directly converted to digital form and the designed filter is also
implemented. In the last two programs the Butterworth and chebyshev filters are designed using
bilinear transformation (for theory verification).
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the IIR filter type
(Butterworth, cheby1, cheby2).
Step 1: Compute the digital cut-off frequency Wc (in the range -π < Wc < π, with π corresponding to
fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz
Wc = 2*π* fc / fs = 2* π * 400/8000 = 0.1* π radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1 corresponds to
fs/2 (i.e., fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is computed as wc = Wc
/π
Step 2: Compute the Impulse Response [b,a] coefficients of the required IIR filter and the response
type (low pass, band pass, etc) using the appropriate butter, cheby1, cheby2 command. For
example given a Butterworth filter, order N=2, and a high pass response, the coefficients [b,a] of
the filter are computed using the MATLAB inbuilt command butter‟ as [b,a] =butter(N, wc ,
'high');
Page 44
ELECTRONICS & COMMUNICATION ENGINEERING
*
Method 2:
Given the pass band (Wp in radians) and Stop band edge (Ws in radians) frequencies, Pass band ripple
Rp and stop band attenuation As.
Step 1: Since the frequencies are in radians divide by π to obtain normalized frequencies to get
Wp=Wp/pi and ws=Ws/pi
If the frequencies are in Hz (note: in this case the sampling frequency should be given), then
obtain normalized frequencies as wp=fp/(fs/2), ws=fstop/(fs/2), where fp, fstop and fs are
the passband, stop band and sampling frequencies in Hz
Step 2: Compute the order and cut off frequency as
[N, wc] = BUTTORD(wp, ws, Rp, Rs)
Step 3: Compute the Impulse Response [b,a] coefficients of the required IIR filter and the response
type as [b,a] =butter(N, wc , 'high');
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,
Low pass: Wp = .1, Ws = .2 High pass: Wp = .2, Ws = .1
Band pass: Wp = [.2 .7], Ws = [.1 .8] Band stop: Wp = [.1 .8], Ws = [.2 .7]
BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB frequency") to use 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.
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 coefficients in length N+1 vectors B
Page 45
ELECTRONICS & COMMUNICATION ENGINEERING
*
(numerator) and A (denominator). The coefficients are listed in descending powers of z. The cutoff
frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. If Wn is a
two-element vector, Wn = [W1 W2], BUTTER returns an order 2N band pass filter with pass band
W1 < W < W2. [B,A] = BUTTER (N, Wn, 'high') designs a high pass filter. [B,A] = BUTTER (N,
Wn, 'stop') is a band stop filter if Wn = [W1 W2]. BUTTER (N, Wn, 's'), BUTTER(N, Wn,
'high','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.
9.4 Algorithm
Get the order of the filter
Find the filter coefficients
Plot the magnitude response
Step 2: T=1
Page 46
ELECTRONICS & COMMUNICATION ENGINEERING
*
Step 5: poles
Step 1:
rad
Page 47
ELECTRONICS & COMMUNICATION ENGINEERING
*
Step 2: T=1
Step 5: poles
Therefore
Page 48
ELECTRONICS & COMMUNICATION ENGINEERING
*
9.6 MATLAB Program: Design and Implementation of IIR filter to meet given
specifications. (Butterworth Filter)
1. Butterworth LPF
%the specifications %system function of the filter
clc; [b,a]=butter(N,Wn)
clear all; w=0:0.01:pi;
close all; [h,om]=freqz(b,a,w,'whole');
alphap=3; m=abs(h);
alphas=15; an=angle(h);
fp=500; subplot(2,1,1);
fs=750; plot(om/pi,20*log(m));
f=2000; grid;
omp=2*fp/f; ylabel('gain in dB');
oms=2*fs/f; xlabel('normalized frequency');
%to find cut off frequency & order of the filter subplot(2,1,2);
[N,Wn]=buttord(omp,oms,alphap,alphas) plot(om/pi,an);
disp('order of the filter n ='); grid;
disp(N); ylabel('phase in radian');
disp('cut off frequency Wn= '); xlabel('normalized frequency');
disp(Wn); % to convert analog filter to digital filter
% using bilinear transformation
[bz,az]=bilinear(b,a,f);
Output:
N=2
Wn = 0.5083
order of the filter n = 2
cut off frequency Wn= 0.5083
Page 49
ELECTRONICS & COMMUNICATION ENGINEERING
*
2. Butterworth HPF
%the specifications %system function of the filter
clc; [b,a]=butter(N,Wn,'high')
clear all; w=0:0.01:pi;
close all; [h,om]=freqz(b,a,w,'whole');
alphap=3; m=abs(h);
alphas=15; an=angle(h);
fp=500; subplot(2,1,1);
fs=750; plot(om/pi,20*log(m));
f=2000; grid;
omp=2*fp/f; ylabel('gain in dB');
oms=2*fs/f; xlabel('normalized frequency');
%to find cut off frequency & order of the filter subplot(2,1,2);
[N,Wn]=buttord(omp,oms,alphap,alphas) plot(om/pi,an);
disp('order of the filter n ='); disp(N); grid;
ylabel('phase in radian');
disp('cut off frequency Wn= '); xlabel('normalized frequency');
disp(Wn); to convert analog filter to digital filter
using bilinear transformation
[bz,az]=bilinear(b,a,f);
Page 50
ELECTRONICS & COMMUNICATION ENGINEERING
*
Output:
N=2
Wn = 0.5083
order of the filter n = 2
cut off frequency Wn= 0.5083
b = 0.2853 -0.5707 0.2853
a = 1.0000 0.0304 0.1717
3. Butterworth BPF
clear all; subplot(2,1,1);
alphap=2; plot(ph/pi,m);
alphas=20; grid;
wp=[0.2*pi,0.4*pi]; ylabel( gain in dB‟);
ws=[0.1*pi,0.5*pi]; xlabel( normalized frequency‟);
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas) subplot(2,1,2);
[b,a]=butter(n,wn) plot(ph/pi,an);
w=0:0.01:pi; grid;
[h,ph]=freqz(b,a,w); ylabel( phase in radian‟);
m=20*log(abs(h)); xlabel( normalized frequency‟);
an=angle(h);
Page 51
ELECTRONICS & COMMUNICATION ENGINEERING
*
Output:
n= 4
wn = 0.1950 0.4082
b= 0.0060 0 -0.0240 0 0.0359 0 -0.0240 0 0.0060
a= 1.0000 -3.8710 7.9699 -10.6417 10.0781 -6.8167 3.2579 -1.0044 0.1670
4. Butterworth BSF
clear all; subplot(2,1,1);
alphap=2; plot(ph/pi,m);
alphas=20; grid;
wp=[0.2*pi,0.4*pi]; ylabel( gain in dB‟);
ws=[0.1*pi,0.5*pi]; xlabel( normalized frequency‟);
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas) subplot(2,1,2);
[b,a]=butter(n,wn,‟stop‟) plot(ph/pi,an);
w=0:0.01:pi; grid;
[h,ph]=freqz(b,a,w); ylabel( phase in radian‟);
m=20*log(abs(h)); xlabel( normalized frequency‟);
an=angle(h);
Output:
n= 4
wn = 0.1950 0.4082
b= 0.4086 -2.0201 5.3798 -9.1468 10.8962 -9.1468 5.3798 -2.0201 0.4086
a= 1.0000 -3.8710 7.9699 -10.6417 10.0781 -6.8167 3.2579 -1.0044 0.1670
Page 52
ELECTRONICS & COMMUNICATION ENGINEERING
*
9.7 MATLAB Program: Design and Implementation of IIR filter to meet given
specifications. (Chebyshev Filter)
Output:
N=2
Wn = 0.5083
order of the filter n = 2
cut off frequency Wn= 0.5083
b = 0.2853 -0.5707 0.2853
a = 1.0000 0.0304 0.1717
n=2
wn = 0.0500
b = 0.0038 0.0076 0.0038
a = 1.0000 -1.8625 0.8816
Page 53
ELECTRONICS & COMMUNICATION ENGINEERING
*
Output:
N=2
Wn = 0.5083
order of the filter n = 2
cut off frequency Wn= 0.5083
b = 0.2853 -0.5707 0.2853
a = 1.0000 0.0304 0.1717
n=2
wn = 0.0500
b = 0.0038 0.0076 0.0038
a = 1.0000 -1.8625 0.8816
n=2
wn = 0.2500
b = 0.1047 -0.1024 0.1047
a = 1.0000 -1.5055 0.6125
n=2
wn = 0.2500
b = 0.3502 -0.5897 0.3502
a = 1.0000 -0.0917 0.1984
Page 54
ELECTRONICS & COMMUNICATION
ENGINEERING
Electrical & Electronics Engineering .
Output:
n= 4
wn = 0.1950 0.4082
b= 0.0017 0 -0.0067 0 0.0101
0 -0.0067 0 0.0017
a= 1.0000 -4.3974 10.5070 -16.3549
18.1728 -14.5121 8.2671 -3.0636 0.6200
Page 55
ELECTRONICS & COMMUNICATION ENGINEERING
*
Output:
n= 3
wn = 0.1000 0.5000
b= 0.2537 -0.8969 1.6246 -1.9332 1.6246
-0.8969 0.2537
a= 1.0000 -2.1790 1.8039 -1.1676 0.9185
-0.3803 0.0343
9.10 Results
9.11 Conclusion
Page 56
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 10
10.0 Design and implementation of FIR filter to meet given specifications (using different
window techniques).
10.1 Aim
Design and implementation of FIR filter to meet given specifications (low pass filter using
hamming window).
10.2 Theory
There are two types of systems – Digital filters (perform signal filtering in time domain) and spectrum
analyzers (provide signal representation in the frequency domain). The design of a digital filter is
carried out in 3 steps- specifications, approximations and implementation.
DESIGNING AN FIR FILTER (using window method):
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the window.
Step 1: Compute the digital cut-off frequency Wc (in the range -π < Wc < π, with π corresponding
to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz Wc = 2*π* fc / fs = 2* π *
400/8000 = 0.1* π radians. For MATLAB the Normalized cut-off frequency is in the range 0
and 1, where 1 corresponds to fs/2 (i.e., fmax)). Hence to use the MATLAB commands. wc =
fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is computed as wc = Wc / π
Step 2: Compute the Impulse Response h(n) of the required FIR filter using the given Window
type and the response type (low pass, band pass, etc). For example given a rectangular window,
order N=20, and a high pass response, the coefficients (i.e., h[n] samples) of the filter are
computed using the MATLAB inbuilt command fir1‟ as h =fir1(N, wc , 'high', boxcar(N+1));
Note: In theory we would have calculated h[n]=hd[n]×w[n], where hd[n] is the desired impulse
response (low pass/ high pass, etc given by the sinc function) and w[n] is the window
coefficients. We can also plot the window shape as stem(boxcar(N)). Plot the frequency
response of the designed filter h(n) using the freqz function and observe the type of
response (low pass / high pass /band pass).
Given the pass band (wp in radians) and Stop band edge (ws in radians) frequencies, Pass band
ripple Rp and stopband attenuation As.
Step 1: Select the window depending on the stopband attenuation required. Generally if As>40 dB,
choose Hamming window. (Refer table )
Step 2: Compute the order N based on the edge frequencies as
Transition bandwidth = tb=ws-wp;
Page 57
ELECTRONICS & COMMUNICATION ENGINEERING
*
N=ceil (6.6*pi/tb);
Step 3: Compute the digital cut-off frequency Wc as
Wc=(wp+ws)/2
Now compute the normalized frequency in the range 0 to 1 for MATLAB as
wc=Wc/pi;
Note: In step 2 if frequencies are in Hz, then obtain radian frequencies (for computation of tb and N)
as wp=2*pi*fp/fs, ws=2*pi*fstop/fs, where fp, fstop and fs are the passband, stop band and sampling
frequencies in Hz
Step 4: Compute the Impulse Response h(n) of the required FIR filter using N, selected window,
type of response(low/high,etc) using fir1‟ as in step 2 of method 1.
IMPLEMENTATION OF THE FIR FILTER
Once the coefficients of the FIR filter h[n] are obtained, the next step is to simulate an input
sequence x[n], say input of 100, 200 & 400 Hz (with sampling frequency of fs), each of 20/30
points. Choose the frequencies such that they are >, < and = to fc.
Convolve input sequence x[n] with Impulse Response, i.e., x (n)*h (n) to obtain the output of the
filter y[n]. We can also use the filter‟ command.
Infer the working of the filter (low pass/ high pass, etc).
10.3 Algorithm
Get the sampling frequency
Get the pass band frequency
Get the stop band frequency
Get the pass band ripple and stop band attenuation
Select the window suitable for stop band attenuation
Calculate the order N based on transition width
Find the N window coefficients
Find the impulse response of h[n]
Verify the frequency response of h[n]
B = FIR1(N, Wn) designs an Nth order low pass FIR digital filter and returns the filter coefficients in
length N+1 vector B. 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, i.e., even symmetric
coefficients obeying B (k) = B(N+2-k), k = 1,2,...,N+1.
Page 58
ELECTRONICS & COMMUNICATION ENGINEERING
*
If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N band pass filter with pass
band W1 < W < W2. B = FIR1 (N, Wn, 'high') designs a high pass filter. B = FIR1 (N, Wn, 'stop') is a
band stop filter if Wn = [W1 W2]. If Wn is a multi-element vector,
Wn = [W1 W2 W3 W4 W5 ... WN], FIR1 returns an order N multiband filter with bands
0<W<W1,W1<W<W2...WN<W<1.
FREQZ Digital filters frequency response. [H, W] = FREQZ (B, A, N) returns the N-point complex
frequency response vector H and the N-point frequency vector W in radians/sample of the filter whose
numerator and denominator coefficients are in vectors B and A. The frequency response is evaluated
at N points equally spaced around the upper half of the unit circle. If N isn't specified, it defaults to
512. For FIR filter enter A=1 and B = h[n] coefficients. Appropriately choose N as 128, 256, etc
Page 59
ELECTRONICS & COMMUNICATION ENGINEERING
*
10.6 MATLAB Program: Design and Implementation of FIR filter using windows
Techniques.
1. To plot frequency response of band pass filter using Hamming window
clc;
close all;
clear all;
wc1=.4*pi;
wc2=.65*pi;
N=7;
hd=zeros(1,N);
a=(N-1)/2;
hna=(wc2-wc1)/pi;
k=1 : 1 : ((N-1)/2);
n=k-1-((N-1)/2);
w_han(k)=.5-.5*cos(2*pi*(k-1)/(N-1));
hd(k)=(sin(wc2*n)-sin(wc1*n))./(pi*n);
for m=1:1:a
Hw3= hn(m)*((exp(j*w*(1-m)))+ (exp(-j*w*(1-m+2*a))));
Hw2=Hw2+Hw3;
end
Hw=Hw2+Hw1;
H_mag=abs(Hw)
plot(w/pi,H_mag,'k');
grid;
title('Magnitude Response','fontweight','b');
xlabel('Normalised frequency,\omega/\pi','fontweight','b');
ylabel('Magnitude','fontweight','b');
Page 60
ELECTRONICS & COMMUNICATION ENGINEERING
*
Output:
1. Frequency response of band pass filter using Hamming window
hn = 0 -0.0556 -0.0143 0.2500
H_mag = 0.1102 0.1192 0.1449 0.1836 0.2297 0.2766 0.3176 0.3471 0.3612 0.3583
0.3396 0.3085 0.2703 0.2313 0.1979 0.1754 0.1675
Page 61
ELECTRONICS & COMMUNICATION ENGINEERING
*
Hw3=hn(m)*((exp(j*w*(1-m)))+(exp(-j*w*(1-m+2*a))));
Hw2=Hw2+Hw3;
end
Hw=Hw2+Hw1
H_mag=abs(Hw)
plot(w/pi,H_mag,'k');
grid;
title('magnitude Response','fontweight','b');
xlabel('Normalised frequency,\omega/\pi','fontweight','b');
ylabel('Magnitude','fontweight','b');
Page 62
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 63
LECTRONICS & COMMUNICATION ENGINEERING
*
Output:
3. To plot frequency response of high pass filter using Hamming window
hn = -0.0081 0.0469 -0.1441 0.2000
H_mag = 0.0104 0.0093 0.0060 0.0005 0.0077 0.0198 0.0383 0.0661 0.1062
0.1605 0.2290 0.3083 0.3923 0.4723 0.5387 0.5827 0.5981
Page 64
ELECTRONICS & COMMUNICATION ENGINEERING
*
for m=1:1:a
Hw3= hn(m)*((exp(j*w*(1-m)))+ (exp(-j*w*(1-m+2*a))));
Hw2=Hw2+Hw3;
end
Hw=Hw2+Hw1;
H_mag=abs(Hw)
plot(w/pi,H_mag,'k');
grid;
title('Magnitude Response','fontweight','b');
xlabel('Normalised frequency,\omega/\pi','fontweight','b');
ylabel('Magnitude','fontweight','b');
Output:
4. To plot frequency response of band stop filter using rectangular window
10.8 Results
10.9 Conclusion
Page 65
ELECTRONICS & COMMUNICATION
ENGINEERING
*
Experiment 11
11.0 Design and implement FIR filter using frequency sampling method.
11.1 Aim
To Design and implement FIR filter using frequency sampling method.
11.2 Theory
A finite impulse response (FIR) filter is discrete linear time invariant system whose output is based on
the weighted summation of a finite number of input. An FIR transversal filter structure can be
obtained directly from the equation for discrete time convolution
y(n)= =0−1 ℎ( − ) 0<n<n-1
In this equation x(k) and y(n) represents the input to & output from the filter at time n h(n-k) is the
transversal filter coefficient at time n these coefficients are generated by using FDS.
FIR filter is a finite impulse response filter order of the filter should be specified Infinite response in
truncated to get finite impulse response placing a window of finite length. This type of available are
rectangular barter, Hamming, Hanning Blackman window etc. This FIR filter is an zero filter.
11.3 Algorithm
Get the sampling frequency
Get the passband & stopband frequency
Get the passband ripple & stopband attenuation
Calculate the order N based on transition width
Find the N window coefficient
Verify the frequency response of h(n)
11.5 Calculation
Design an ideal bandpass filter with a frequency response
Hd=(ejw)= 1 for π/4 <= |w| <= 3π/4
0 otherwise
Find the values of h(n) for N=11 and plot the frequency response .
The ideal frequency response of the filter shown in fig
f
Page 66
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 67
ELECTRONICS & COMMUNICATION ENGINEERING
*
w in
0 20 30 45 60 75 90 105 120 135 150 160 180
degree
jw
(e ) -0.1366 0.012 -0.1817 0.5 0.818 1.05 1.1366 1.05 0.818 0.5 0.1817 0.012 -0.1366
in db -17.3 -38.17 -14.8 -6.02 -1.74 0.4346 1.11 0.4346 -1.74 -6.05 -14.8 -38.17 -17.3
Page 68
ELECTRONICS & COMMUNICATION ENGINEERING
*
11.6 MATLAB Program: To design and implement FIR filter using frequency sampling
method.
11.7 Output
Input:
enter the order of the filter N=7
Output:
hn = -0.1146 0.0793 0.3210 0.4286 0.3210 0.0793 -0.1146
11.8 Results
11.9 Conclusion
Page 69
ELECTRONICS & COMMUNICATION ENGINEERING
*
Experiment 12
12.1 Aim
To obtain realization of IIR & FIR filters.
12.2 Theory
A digital filter transfer can be realized in a variety of ways. There are two types of realization
1. Recursive 2. Non Recursive.
For recursive realization the current output y(n) is a function of past outputs, past & present inputs.
This form corresponds to an Infinite Impulse Response (IIR) digital filter. In this section we discuss
this type of realization.
For non-recursive realization current output sample y(n) is a function of only past and present
inputs. This form corresponds to a Finite Impulse Response (FIR) digital filter.
The structure are implemented using MATLAB inbuilt functions residuez and tf.
12.4 Calculation
Page 70
ELECTRONICS & COMMUNICATION ENGINEERING
*
Here
&
Page 71
ELECTRONICS & COMMUNICATION ENGINEERING
*
Page 72
ELECTRONICS & COMMUNICATION ENGINEERING
*
12.7 Output
12.8 Result
12.9 Conclusion
Page 73