Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
LAB MANUAL
Digital Signal Processing Lab (10B17EC572)
Department of ECE
Digital Signal Processing Lab (10B17EC572): Lab Experiments
1.
2.
To develop a program for computing Z- transform in factored form, also plot its poles
and zeros, and then determine its ROCs.
3.
4.
Computation of DFT (Discrete Fourier transform) & IDFT using standard formula.
5.
6.
7.
8.
9.
To develop Program for realization (Direct, Cascade and Parallel) of IIR Digital filters.
10.
Design of digital FIR filters (LPF, HPF, BPF, BRF) using Fourier series method.
11.
Design of digital FIR filters (LPF, HPF, BPF, BRF) using frequency sampling method.
12.
PREFACE
This laboratory manual contains laboratory exercises based on MATLAB. The purpose of
these exercises is to help reconcile what is and how to points of view on signals and systems.
MATLAB distributed by The Math Works, Inc., are chosen as the platform for these
exercises because they are widely used by practitioners in the field, and because they are capable of
realizing interesting systems. MATLAB approaches to modeling of signals and systems. MATLAB
is a programming language. In MATLAB, one specifies the sequence of steps that construct a signal
or operate on a signal to produce a new signal.
Be punctual in coming to the lab and be sincere in doing your lab work.
Before starting the lab experiment you must go through the lab manual of that
experiment. Get your doubts clear and then start.
Keep the work area neat and clean; arrange the chairs before leaving the laboratory.
Dont bring your laptop in the lab without permission of the lab OC.
EVEN SEMESTER
Experiment - 1
Objective: Introduction to MATLAB and its various applications.
What is MATLAB?
MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming in an easy-to-use environment where
problems and solutions are expressed in familiar mathematical notation.
Typical uses include Math and computation Algorithm development, Data
acquisition Modeling, simulation, and prototyping Data analysis, exploration, and
visualization Scientific and engineering graphics Application development, including
graphical user interface building.
MATLAB is an interactive system whose basic data element is an array that does
not require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations.
The name MATLAB stands for Matrix Laboratory.
MATLAB
(Programming Language)
User-Written Functions
Graphics
2-D Graphics
3-D Graphics
Color and Lighting
Animation
Audio & Video
Computations
Linear Algebra
Data Analysis
Signal Processing
Polynomials &
Interpolation
Integration
Solutions of ODEs
Toolboxes
Signal Processing
Image Processing
Statistics
Communications
Symbolic Mathematics etc.
External Interfaces
Interface With C, Java,
and Fortran Programmes
EVEN SEMESTER
Theory:
A. MATLAB Basics
1. MATLAB Windows
EVEN SEMESTER
Editor Window - Use the Editor/Debugger to create and debug M-files, which are
programs you write to run MATLAB functions. The Editor/Debugger provides a
graphical user interface for text editing, as well as for M-file debugging. To create
or edit an M-file use File -> New or File -> Open, or use the edit function.
Workspace
Command
Window
Editor
Window
Figure
Window
Command
History
MATLAB
Desktop
Figure 1. The MATLAB environment consists of MATLAB Desktop, a figure
window, and an editor window. The figure window and the editor window appear
only when invoked with appropriate commands.
2. Input-Output
Data Type - There are many different types of data that you can work with in
MATLAB. You can build matrices and arrays of floating-point and integer data,
characters and strings, logical true and false states, etc. You can also develop your
own data types using MATLAB classes. Two of the MATLAB data types,
structures and cell arrays, provide a way to store dissimilar types of data in the
same array.
3
EVEN SEMESTER
There are 15 fundamental data types in MATLAB. Each of these data types is in
the form of a matrix or array. This matrix or array is a minimum of 0-by-0 in size
and can grow to an n-dimensional array of any size.
Case sensitivity Case Sensitive, MATLAB requires an exact match for variable
names. For example, if you have a variable a, you cannot refer to that variable as A.
With respect to functions, filenames, objects, and classes on the search path or in
the current directory, MATLAB prefers an exact match with regard to case.
MATLAB runs a function if you do not enter the function name using the exact
case, but displays a warning the first time you do this.
EVEN SEMESTER
press Enter or Return to run the line. Repeated use of the up arrow key recalls
earlier lines, from the current and previous sessions. Using the up arrow key, you
can recall any line maintained in the Command History window. Similarly, specify
the first few characters of a line you entered previously and press the up arrow key
to recall the previous line.
3. File Types
Mat files - The save command in MATLAB saves the MATLAB arrays currently
in memory to a binary disk file called a MAT-file. The term MAT-file is used
because these files have the extension .mat. The load command performs the
reverse operation. It reads the MATLAB arrays from a MAT-file on disk back into
MATLAB workspace. MAT-files provide a convenient mechanism for moving
your MATLAB data between different platforms and for importing and exporting
your data to other stand-alone MATLAB applications.
Fig files Binary files with a .fig extension that can be opened again in
MATLAB as figures. Such files are created by saving a figure in this format using
save or save as options from File menu of Figure window. This contains all the
information required to recreate the figure. To open use open filename. fig.
P files - You can save a preparsed version of a function or script, called P-code
files, for later MATLAB sessions using the pcode function. If you develop an
application that other people can use but you do not want to give source code, then
you give them the corresponding p- files.
Mex files are MATLAB callable FORTTRAN and C programs, with a .mex
extension to the filenames.
5
EVEN SEMESTER
EVEN SEMESTER
B. Scripts
Scripts are collection of command executed in sequence, written in editor and
saved as M-files (.m extension). A script file is executed by typing its name in at
command prompt. All of the MATLAB examples in this textbook are contained in M-files
that are available at the MathWorks ftp site.
MATLAB requires that the M-file must be stored either in the working directory or in a
directory that is specified in the MATLAB path list. For example, consider using
MATLAB on a PC with a user-defined M-file stored in a directory called
"\MATLAB\MFILES". Then to access that M-file, either change the working directory by
typing cd\matlab\mfiles from within the MATLAB command window or by adding the
directory to the path. Permanent addition to the path is accomplished by editing the
\MATLAB\matlabrc.m file, while temporary modification to the path is accomplished by
typing path(path,'\matlab\mfiles') from within MATLAB.
16-bit char
Other types are also supported: complex, symbolic, 16-bit and 8 bit integers, etc.
First character of variable names must be a LETTER after that, any combination of
letters, numbers and _.
EVEN SEMESTER
a = 10
shows up in workspace
row =
1.0000 2.0000 5.4000 -6.6000
Workspace:
column =
4
2
7
4
Workspace:
EVEN SEMESTER
You can tell the difference between a row and a column vector by:
o Looking in the workspace
o Displaying the variable in the command window
o Using the size function
>> size(row)
>> size(column)
ans =
ans =
>> length(column)
ans =
ans =
Element by element
>> a= [1 2; 3 4]
a=
a = [1 2];
b = [3 4];
c = [5; 6];
d = [a; b];
e = [d c];
f = [[e e] ; [a b a]];
str = ['Hello, I am ' 'John'];
EVEN SEMESTER
Arithmetic operations ( + ,- , *, /)
7/45
(1+i) * (2+i)
1/0
0/0
Exponentiation (^)
4^2
(3+4*j) ^ 2
gives an error
The transpose operators turn a column vector into a row vector and vice versa
a = [1 2 3 4+i]
transpose(a)
a'
a.'
The ' gives the Hermitian-transpose, i.e. transposes and conjugates all complex numbers
For vectors of real numbers .' and ' give same result.
If your expression does not fit on one line, use an ellipsis (three or more periods at the end
of the line) and continue on the next line.
c = 1+2+3+...
5+6+7;
Built-in Functions
MATLAB has an enormous library of built-in functions
Call using parentheses passing parameter to function
10
EVEN SEMESTER
sqrt(2)
log(2), log10(0.23)
cos(1.2), atan(-.8)
exp(2+4*i)
round(1.4), floor(3.3), ceil(4.23)
angle(i); abs(1+i);
Note: Explore these functions using help or doc
MATLAB is based on matrix and vector algebra; even scalars are treated as 1x1 matrices.
Therefore, vector and matrix operations are as simple as common calculator operations.
Addition and Subtraction
Addition and subtraction are element-wise; sizes must match (unless one is a scalar):
The following would give an error
c = row + column
Use the transpose to make sizes compatible
c = row+ column
c = row + column
Can sum up or multiply elements of vector
s = sum (row);
p = prod (row);
Element-Wise Functions
All the functions that work on scalars also work on vectors
t = [1 2 3];
f = exp(t);
is the same as
11
EVEN SEMESTER
Operators: element-wise
To do element-wise operations, use the dot: .(.* , ./ , .^). BOTH dimensions must
match (unless one is scalar)!
a = [1 2 3]; b = [4; 2; 1];
a .* b, a./ b, a. ^ b
all errors
all valid
Operators: standard
Multiplication can be done in a standard way or element-wise
Standard multiplication (*) is either a dot-product or an outer-product
Standard exponentiation (^) can only be done on square matrices or scalars
Left and right division (/ \) is same as multiplying by inverse
Automatic Initialization
Initialize a vector of ones, zeros, or random numbers
o = ones(1,10)
z = zeros(23,1)
r = rand(1,45)
n = nan(1,69)
c = 1:5
To initialize logarithmically spaced values use logspace, similar to linspace, but see help
12
EVEN SEMESTER
Vector Indexing
MATLAB indexing starts with 1, not 0
a(n) returns the nth element.
The index argument can be a vector. In this case, each element is looked up individually,
and returned as a vector of the same size as the index vector.
x = [12 13 5 8];
a = x (2:3);
a = [13 5];
b = x (1: end-1);
b = [12 13 5];
Matrix Indexing
Matrices can be indexed in two ways
o using subscripts(row and column)
o using linear indices(as if matrix is a vector)
Picking submatrices
A = rand(5)
A(1:3,1:2)
12
-2
13
d = c(1, :)
>> e = c(:, 2)
>> c (2, :) = [3 6]
d=
e=
c=
12
12
13
EVEN SEMESTER
To convert between subscripts and indices, use ind2sub, and sub2ind. Use help.
D. Functions
User-defined Functions
Functions look exactly like scripts, but for ONE difference, Functions must have a
function declaration
Function
Declaration
O/Ps
Inputs
Help
Files
14
EVEN SEMESTER
No need for return: MATLAB 'returns' the variables whose names match those in the
function declaration
Variable scope: Any variables created within the function but not returned disappear after
the function stops running
E. Flow Control
Relational Operators < > <= >= == ~=
MATLAB uses mostly standard relational operators
equal ==
notequal ~=
Logical operators
And
elementwise
short-circuit (scalars)
&
&&
Or
||
Not
Xor
xor
All true
all
Any true
any
15
EVEN SEMESTER
Description
If expression1 evaluates as false and expression2 as true, MATLAB executes the one or
more commands denoted here as statements2.
A true expression has either a logical 1 (true) or nonzero value. For nonscalar expressions,
(for example, is matrix A less then matrix B), true means that every element of the
resulting matrix has a true or nonzero value.
16
EVEN SEMESTER
F. Plotting
x = linspace(0,4*pi,10);
y = sin(x);
Plot values against their index
plot(y);
Usually we want to plot y versus x
plot( x , y);
Plot generates dots at each (x, y) pair and then connects the dots with a line
To make plot of a function look smoother, evaluate at more points
x = linspace (0, 4*pi, 1000);
plot(x, sin(x));
x and y vectors must be same size or else youll get an error
plot ([1 2], [1 2 3])
error!
Can change the line color, marker style, and line style by adding a string argument
plot (x, y, k.-);
Can plot without connecting the dots by omitting line style argument
plot (x, y, .)
Look at help plot for a full list of colors, markers, and linestyles
Some Other Useful Commands:
xlabel, ylabel, title, xlim, ylim, grid, axis, hold, stem
Cartesian Plots Commands: plot, semilogx, semilogy, loglog
3D Line Plot Command: plot3, surf, contour, quiver, xlim, ylim, zlim
subplot for Multiple Plots in one Figure
G. Solving Equations
Systems of Linear Equations
Given a system of linear equations
x + 2y - 3z = 5,
-3x y + z = -8,
xy+z=0
EVEN SEMESTER
% r is a vector of length N
% r is a vector length N
Numerical Differentiation
MATLAB can 'differentiate' numerically
x = 0:0.01:2*pi;
18
EVEN SEMESTER
y = sin(x);
dydx = diff(y) ./ diff(x);
Numerical Integration
MATLAB contains common integration methods
Adaptive Simpson's quadrature (input is a function)
Write a function y = myFun(x) where y = cos (exp(x) +x.^2 - 1)
q1 = quad ('myFun', 0, 10);
H. Data Structures
We have used 2D matrices
Every element must be the same type (ex. integers, doubles, characters)
Cell array: it's like an array, but elements don't have to be the same type
Structs: can bundle variable names and values into one structure like object
oriented programming in MATLAB
19
EVEN SEMESTER
I. Symbolics
Symbolic Variables
Symbolic variables are a type, like double or char
To make symbolic variables, use sym
a=sym ('1/3');
b=sym ('4/5');
mat=sym ([1 2;3 4]);
Or use syms
syms x y real
Symbolic Expressions
Multiply, add, divide expressions
d = a*b
% does 1/3*4/5=4/15;
% multiplies out
factor (ans)
matInv = inv(mat)
collect (3*x+4*y-1/3*x^2-x+3/2*y)
% collects terms
% simplifies expressions
% Replaces variables with numbers or expressions.
20
EVEN SEMESTER
a. a = 10
b. b = 2.5 10 23
c. c = 2 + 3i , where i is the imaginary number
d. d = ej 2 /3 , where j is the imaginary number and e is Eulers number (use exp, pi)
2. Vector variables. Make the following variables
21
EVEN SEMESTER
f. Make fMat be a 5x3 matrix of random integers with values on the range -3 to 3 (use
rand and floor or ceil).
4. Common functions and indexing.
22
EVEN SEMESTER
5. Plotting multiple lines and colors. Open a script and name it twoLinePlot.m
To plot a sine wave and a cosine wave over one period
(a) Make a time vector t from 0 to 2 with enough samples to get smooth lines, Plot sin t.
(b) Use hold on.
(c) Plot cos t using a red dashed line.
(d) Add labels to the plot and create a legend to describe the two lines you have plotted by
using legend.
(e) Use xlim to set the x axis to be from 0 to 2 and use ylim to set the y axis to be from 1.4 to 1.4.
6. Plot a circle. Write the function [x, y] = getCircle (center,r) to get the x and y
coordinates of a circle. The circle should be centered at center (2-element vector containing
the x and y values of the center) and have radius r. Return x and y such that plot(x, y) will
plot the circle.
7. Loops and flow control. Make function called loopTest(N) that loops through the
values 1 through N and for each number n it should display n is divisible by 2, n is
divisible by 3, n is divisible by 2 AND 3 or n is NOT divisible by 2 or 3. Use a for
loop, the function mod or rem to figure out if a number is divisible by 2 or 3, and num2str
to convert each number to a string for displaying. You can use any combination of if, else,
and elseif.
a + 5b = 2.
7b + 7c = 3
Compute and display the difference between your numerical answer and the analytical
answer: 24 e
5/3
+9
23
EVEN SEMESTER
10. Practice with cells. Usually, cells are most useful for storing strings, because the
length of each string can be unique. a. Make a 3x3 cell where the first column contains the
names: Joe, Sarah, and Pat, the second column contains their last names: Smith,
Brown, Jackson, and the third column contains their salaries: $30,000, $150,000, and
$120,000. Display the cell using disp.
24
EVEN SEMESTER
Experiment - 2
Objective: Introduction of Elementary and Complex Signals.
Theory:
The Signals, which are functions of one or more independent variables, contain
information about the behaviour or nature of some phenomenon. Independent variables
may be time, space etc. depending on type of signals. Some examples are: a speech signal
would be mathematically represented by acoustic pressure as a function of time, Voltage,
current or power as functions of time, a monochromatic picture can be described as a
signal which is mathematically represented by brightness as a function of two spatial
variables,
The purpose of this lab is the introduction of the graphical representation of
elementary as well as Complex Signals. For this Lab, our focus will be on a single (1-D)
independent variable which we call time. Depending on time, signals can be classified
into continuous and discrete-time signals used in linear systems. It is important to
emphasize that. A continuous-time signal takes on a value at every point in time, whereas a
discrete-time signal is only defined at integer values of the time variable. However,
while discrete-time signals can be easily stored and processed on a computer, it is
impossible to store the values of a continuous-time signal for all points along a segment of
the real line.
How then do we process continuous-time signals? In this lab, we will see that
continuous- time signals may be processed by first approximating them by discrete-time
signals using a process known as sampling. We will see that proper selection of the
spacing between samples is crucial for an efficient and accurate approximation of a
continuous-time signal. Excessively close spacing will lead to too much data with not
much improvement in signal representation, whereas excessively distant spacing will lead
to a poor approximation of the continuous-time signal.
2. Continuous-Time Vs. Discrete-Time Signals
The representation of continuous-time signals on a computer depends on sampling
process. Selection of the sampling interval decides the precision of graphical
representation of CT signal by discrete values. To display CT and DT signal on
MATLAB see plot, stem, subplot commands.
It is common to graph a discrete-time signal as dots in a Cartesian coordinate
system. This can be done in the Matlab environment by using the stem command. We will
also use the subplot command to put multiple plots on a single figure. Start Matlab on
your workstation and type the following sequence of commands in a script file.
1 % Generate discrete-time sinusoidal signal
2 n = 0: 2: 60;
3 y = sin(n/6);
4 subplot(3,1,1)
5 stem(n, y)
This plot shows the discrete-time signal formed by computing the values of the function
sin (n/6) at points which are uniformly spaced at intervals of size 2. Notice that while sin(t
25
EVEN SEMESTER
/6)is a continuous-time function, the sampled version of the signal, sin(n/6), is a discretetime function.
A digital computer cannot store all points of a continuous-time signal since this
would require an infinite amount of memory. It is, however, possible to plot a signal which
looks like a continuous-time signal, by computing the value of the signal at closely spaced
points in time, and then connecting the plotted points with lines. The Matlab plot function
may be used to generate such plots.
Steps for plotting continuous time signals are as follows:
1). Assign the value dt very small, as per Sampling Theorem.
2). Vary the timet between two points with an increment of dt.
Use the following sequence of commands in a script file to generate two continuous-time
plots of the signal sin (t/6).
1 % Generate Continuous-time sinusoidal signal
2 t1 = 0:0.1:6,
3 z = sin(t1/6);
4 subplot(3,1,2)
5 plot(t1,z)
6 t2 = 0:2:60;
7 w = sin(t2/6);
8 subplot(3,1,3)
9 plot(t2,w)
As you can see, it is important to have many points to make the signal appear smooth. So,
the selection of sampling period is critical in getting CT signal smooth, it must be chosen
such that smooth plot is obtained at the same with not much large array size with not much
improvement in graphical representation of CT signal.
For given CT signal, Steps for converting CT signal to the DT signal are as
follows:
1) Assign the value of sampling time, T.
2) Vary the time integer n between two integer points with an increment of 1.
3) The discrete version can be obtained as:
y (n) = y(nT).
IN LAB EXERCISE
Basic CT Signals and DT Signals
Q1. Plot the following continuous-time functions over the specified intervals. Write single
script files for all CT signals with name CTsignals_GroupNo. X.m. Use the plot and
figure command, and be sure to label the time axes.
(a) Unit Impulse function, x1 (t) = (t)
(b) Unit Step function, x2(t) = u (t) for t = [-2, 2]
26
EVEN SEMESTER
xa(t) = (t + 2)
xb(t) = (t + 2) - (t -2)
xc(t) = t u(t)
xd(t) = u (t) u(t - 5)
xe(t) = r (t +1) r (t) + r (t - 2)
xf(t) = exp(-t) sin(2t) + exp(-t/2) cos(5 t)
27
EVEN SEMESTER
xa[n] = r[-n]
xb[n] = exp(n-1)
xc[n] = [n - 1] [n - 2]
xd[n] = u [n + 1] 2u[ n] + u [n-1]
xe[n] = r [n + 2] r [n - 2]
xf [n] = a n cos(2 n)
b. Using the result of part (a), compute the derivative of v(t), and sketch its waveform.
Q4. Sketch the waveform:
28
EVEN SEMESTER
Experiment-3
Objective: To compute the linear convolution of two discrete sequences.
Theory: Consider two finite duration sequences x (n) and h (n), the duration of x (n) is n1
samples in the interval 0 n (n1 1) . The duration of h (n) is n2 samples; that is h (n) is
non zero only in the interval 0 n (n 2 1) . The linear or a periodic convolution of x (n)
and h (n) yields the sequence y (n) defined as,
29
EVEN SEMESTER
Experiment-4
Objective: Computation of DFT (Discrete fourier transform) & IDFT using standard formula
We know that aperiodic finite energy signals have continuous spectra (DTFT).
values of X() over its period, called the frequency samples, are sufficient to determine
x(n) and hence X(). This leads to the concept of discrete Fourier transform (DFT) which
is obtained by periodic sampling of X () (DTFT).
We often compute a higher point (N point) DFT where N > L . This is because padding
the sequence x(n) with N-L zeros and computing an N point DFT results in a better
display of the Fourier transform X().
To summarize, the formulas are (for causal sequence)
N 1
X (k)
x(n)e
j 2 kn
N
n 0
N 1
x(n)
1
N
L 1
x(n)e
j 2 kn
N
(DFT ), k
n 0
X (k )e
j 2 kn
N
(IDFT ), n
0,1,......N
k 0
WN* X
DFT equation
IDFT equation
Where WN=e-j2/N
x=[x(0) x(1) x(N-1) ]T
X=[X(0) X(1) X(N-1)]T
30
0,1,...., N 1
EVEN SEMESTER
31
EVEN SEMESTER
Experiment-5
Objective: To develop programs for computing Z- transform and Inverse Z-transform.
Part A
The Z-transform of a discrete time signal x(n) is
n
X (z) x(n)z n
n
where, z is a complex variable. Since z-transform is an infinite series, it exists only for those
values of z for which this series converges. The region of convergence (ROC) of X(z) is the
set of all values of z for which X(z) attains a finite value.
Example:
x(n) is a finite duration signal like x(n) 1,2,5,7,0,1 .
Its z transformed signal, X (z) 1 2z 1 5z 2 7z 3 z 5 , its ROC is entire Z-plane
except z=0.
For x(n) 1,2,5,7,0,1 , its z transformed signal is X (z) z 2 2z 5 7z 1 z 3 , here its
ROC is entire Z-plane except z=0 and z= .
Transform
ROC
[n]
u[n]
-u[-n-1]
[n-m]
anu[n]
-a nu[-n-1]
nanu[n]
-na nu[-n-1]
[cos0n]u[n]
[sin0 n]u[n]
[rncos0n]u[n]
[rnsin0 n]u[n]
anu[n] - a nu[n-N]
1
all z
z/(z-1)
|z|>1
z/(z-1)
|z|<1
z-m
all z except 0 if m>0 or
z/(z-a)
|z|>|a|
z/(z-a)
|z|<|a|
2
az/(z-a)
|z|>|a|
az/(z-a)2
|z|<|a|
2
2
(z -[cos0]z)/(z -[2cos0]z+1)
|z|>1
[sin0]z)/(z2-[2cos0]z+1)
|z|>1
2
2
2
(z -[rcos0]z)/(z -[2rcos0]z+r )
|z|>r
[rsin0]z)/(z2 -[2rcos0]z+r2)
|z|>r
N N
N-1
(z -a )/z (z-a)
|z|>0
32
m<0
EVEN SEMESTER
Part B
Inverse Z-transform
The inverse Z-transform is the conversion of Z-domain signal into time domain signal. The
inversion can be done by Cauchys Integral theorem, long division process, partial fraction
expansion etc.
Then performing partial fraction expansion on the proper rational part of X(z) to obtain
33
EVEN SEMESTER
X(z)
-2
(1 2z z )
(1- z -1 0.3561z -2 )
Ques 3. Determine whether or not all the roots of the following polynomial are inside the
unit circle:
Ques 5. Determine whether or not all the roots of the following polynomial are inside the
unit circle:
3
(z
)
X(z)
(z - 0.5)(z - 0.75)(z -1)
34
EVEN SEMESTER
Experiment-6
Objective: To compute the circular convolution of two discrete sequences.
Theory: Two real N-periodic sequences x(n) and h(n) and their circular or periodic
convolution sequence y(n) is also an N- periodic and given by,
N 1
Circular convolution is some thing different from ordinary linear convolution operation,
as this involves the index ((n-m))N, which stands for a modula-N operation. Basically
both type of convolution involve same six steps. But the difference between the two types
of convolution is that in circular convolution the folding and shifting (rotating)
operations are performed in a circular fassion by computing the index of one of the
sequences with modulo-N operation. Either one of the two sequences may be folded and
rotated without changing the result of circular convolution. That is,
N 1
If x (n) contain L no of samples and h (n) has M no of samples and that L > M, then
perform circular convolution between the two using N=max (L,M), by adding (L-M) no of
zero samples to the sequence h (n), so that both sequences are periodic with number.
Two sequences x (n) and h (n), the circular convolution of these two sequences
can be found by using the following steps.
1.
2.
Start at the same point as h (n) graph N samples of x (n) as equally spaced points
around an inner circle in clock wise direction.
3.
Multiply corresponding samples on the two circles and sum the products to produce
output.
4.
Rotate the inner circle one sample at a time in counter clock wise direction and go to
step 3 to obtain the next value of output.
5.
Repeat step No.4 until the inner circle first sample lines up with first sample of the
exterior circle once again.
35
EVEN SEMESTER
36
EVEN SEMESTER
Experiment-7
Computation of DFT using FFT algorithms
MATLAB
1. Write a program to compute and plot the amplitude spectrum of the signal x(n) with the number of
data points you have determined based on FFT. Comment on your results.
37
EVEN SEMESTER
Experiment-8
Objective: Write a program to design the low pass FIR filter using the following
Windowing techniques and specifications:
Window techniques
1) Hamming Window
2) Kaiser Window
Specifications
passband edge frequency: 1800 Hz,
stopband edge frequency: 2600 Hz,
maximum passband ripple: 0.5 dB,
minimum stopband damping: 40 dB,
sampling rate: 8 kHz.
sample sinusoids at frequencies:
a. F1=500 Hz
b. F2=1800 Hz
c. F3=2000 Hz
d. F4=3200 Hz
Theory:
The FIR filter design consists of two steps;
1) The filter order is determined, then the coefficients.
2) An approximate formula for the filter order N, developed by Kaiser:
38
EVEN SEMESTER
Results:
a) Kaiser Window
0
Magnitude (dB)
-20
&
-40
-60
-80
-100
-120
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency (rad/sample)
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency (rad/sample)
0.7
0.8
0.9
Phase (degrees)
500
-500
39
EVEN SEMESTER
Input S ig
2
0
&
-2
VK
-4
0
0.005
0.01
0.015
0.02
0.025
0.015
0.02
0.025
time (s)
F iltered S ig
2
1
0
-1
-2
0
0.005
0.01
time (s)
40
EVEN SEMESTER
b) Hamming Window
Magnitude (dB)
5
0
&
-5
-10
-15
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency (rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency (rad/sample)
0.9
Phase (degrees)
-500
-1000
-1500
41
EVEN SEMESTER
Time Plots of Input and Output
VK
&
Input Sig
2
0
-2
-4
0
0.005
0.01
0.015
0.02
0.025
0.015
0.02
0.025
time (s)
Filtered Sig
4
2
0
-2
-4
0
0.005
0.01
time (s)
42
EVEN SEMESTER
Experiment-9 & 10
Objective: Write a program for IIR digital filter design (Impulse invariant and
Bilinear transformation) for a given specification.
Theory:
IIR Filter Types
1) Butterworth filter
Provides the best Taylor series approximation to the ideal lowpass filter response at
analog frequencies = 0 and = ; for any order n, the magnitude squared response has
2n 1 zero derivatives (that is, it is maximally flat) at these locations. Response is
monotonic overall, decreasing smoothly from = 0 to = .
2) Chebyshev Type I filter
It minimizes the absolute difference between the ideal and the actual frequency response
over the entire passband by using an equal ripple in the passband. Stopband response is
maximally flat. The transition from passband to stopband is more rapid than for the
Butterworth filter.
3) Chebyshev Type II filter
It minimizes the absolute difference between the ideal and the actual frequency response
over the entire stopband by using an equal ripple in the stopband. Passband response is
maximally flat. The stopband does not approach zero as quickly as the type I filter. The
absence of ripple in the passband, however, is often an important advantage.
4) Elliptic filter
Equiripple in both the passband and stopband. Generally meets filter requirements
with the lowest order of any supported filter type. Given a filter order n, passband
ripple, and stopband ripple, elliptic filters minimize transition width.
For designing Butterworth filter, the commands are
[num, den] = butter(N, Wn)
For designing a Type 1 Chebyshev digital filter, the commands are
[num, den] = cheby1(N, Rp, Wn)
For designing a Type 2 Chebyshev digital filter, the commands are
[num,den] = cheby2(N,Rs,Wn)
For designing Butterworth filter, the commands are
[num, den] = ellip(N, Rp, Rs, Wn)
Each function delivers a lowpass filter by default. To design a bandpass, Wn must be
defined as a vector of 2 elements. The elements hold the corner frequencies of the
bandpass filter. The filter order N and the scaling factor for the frequency bounds Wn can
be determined as follows:
[N, Wn] = buttord(Wp, Ws, Rp, Rs)
[N, Wn] = cheb1ord(Wp, Ws, Rp, Rs)
[N, Wn] = ellipord(Wp, Ws, Rp, Rs
43
EVEN SEMESTER
Where, the input parameters are the normalized passband edge frequency Wp, the
normalized stopband edge frequency Ws, the passband ripple Rp in dB, and the minimum
stopband attenuation Rs in dB. Both Wp and Ws must be a number between 0 and 1 with the
sampling frequency assumed to be 2 Hz. The output data are the lowest order N
meeting the specifications and the normalized cutoff frequency Wn. If Rp = 3 dB, then
Wn = Wp. Buttord can also be used to estimate the order of a highpass, a bandpass, and a
bandstop Butterworth filter. For a highpass filter design,Wp > Ws. For bandpass and
bandstop filter designs, Wp and Ws are two-element vectors specifying both edge
frequencies, with the lower edge frequency being the first element of the vector. In the
latter cases, Wn is also a two-element vector.
Digital IIR Filter design
The design of an IIR filter is rather straightforward when using the bilinear transformation
technique. An analog filter is converted to a digital one via the bilinear transformation
we obtain the relation
As the bilinear transformation preserves the type of filter (LP, BP etc.) we only need to
make sure that the cut-off frequencies gets mapped to the correct place.
The design technique is summarized here:
1. Start by identifying the discrete time frequencies describing the cut-off frequencies.
Use normalized frequencies in radians where, = represents half the sampling frequency (
= 2f / fs).
2. Calculate the corresponding analog frequencies using = 2 tan( / 2).
3. Design an analog filter Ha(s) based on the specifications.
4. Use the bilinear transformation to obtain the final digital (Z-domain) filter.
EXERCISE:
1) Using MATLAB determine the lowest order of a digital IIR highpass filter of all four
types. The specifications are as follows: sampling rate of 3,500 Hz, passband edge
frequency of 1,050 Hz, stopband edge frequency of 600 Hz, passband ripple of 1 dB, and a
minimum stopband attenuation of 50 dB. Plot the frequency response of the above IIR
filter for bilinear and impulse invariant transforms. Comment on your results.
2) Using MATLAB determine the lowest order of a digital IIR bandstop filter of all four
types. The specifications are as follows: sampling rate of 12 kHz, passband edge
frequencies at 2.1 kHz and 4.5 kHz, stopband edge frequencies at 2.7 kHz and 3.9 kHz,
passband ripple of 0.6 dB, and a minimum stopband attenuation of 45 dB. Plot the
frequency response of the above IIR filter for bilinear and impulse invariant transforms.
Comment on your results.
44