0% found this document useful (0 votes)
57 views

Lab Manual DSP1

The document is a laboratory manual for a digital signal processing course. It contains instructions for generating and plotting different types of signals in MATLAB, including unit sample sequences, unit step sequences, exponential sequences, and sinusoidal sequences. Program code is provided to generate each of these signal types. Students are asked questions to help them understand how to generate and analyze the signals. The goal of the experiment is for students to learn how to represent common signal types in digital form using MATLAB.

Uploaded by

Omkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Lab Manual DSP1

The document is a laboratory manual for a digital signal processing course. It contains instructions for generating and plotting different types of signals in MATLAB, including unit sample sequences, unit step sequences, exponential sequences, and sinusoidal sequences. Program code is provided to generate each of these signal types. Students are asked questions to help them understand how to generate and analyze the signals. The goal of the experiment is for students to learn how to represent common signal types in digital form using MATLAB.

Uploaded by

Omkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Padre Conceicao College of Engineering, Verna, Goa

Affiliated to Goa University, Taleigao Plateau, Goa


Department of Electronics & Telecommunication Engineering

LABORATORY MANUAL
Digital signal processing

JULY TO NOVEMBER 2018


TE, ETC,
ROHINISem
KORTI- V
Assistant Professor, ETC Dept., P. C. C. E., Verna, GOA

ETC/ECE5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

List of Experiments

Sl. No. Tiltle of the program


1. Generating and plot various signals.

2. Evaluation of Discrete Fourier Transform (DFT).

3. Properties of Discrete Fourier Transform (DFT).

4. Realization of IIR Transfer Functions

5. Design of an IIR Filter using fdatool

6. Design of FIR Filters using fdatool.

7. Multirate Digital Signal processing.

8. FIR filter design using Kaiser Window method.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Introduction
Digital signal processing (DSP) is concerned with the representation of signals as a sequence of
numbers and the algorithmic operations carried out on the signals to extract specific
information contained in them. In barely 40 years the field of digital signal processing has
matured considerably due to the phenomenal growth in both research and applications, and
almost every university is now offering at least one or more courses at the upper division
and/or first-year graduate level on this subject. With the increasing availability of powerful
personal computers and workstations at affordable prices, it has become easier to provide the
student with a practical environment to verify the concepts and the algorithms learned in a
lecture course.

The programming language used is MATLAB, widely used for high-performance numerical
computation and visualization. MATLAB is a numerical computing environment developed by
MathWorks. MATLAB allows matrix manip , ulations, p g lotting of functions and data, and
implementation of algorithms

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

Experiment No 1.
Generate and plot different signals.

1.1 Aim: Write a MATLAB code to generate and plot different signals.

1.2 Components required:MATLAB software.

1.3 Theory and MATLAB Code:

1.3.1 Unit Sample and Unit Step Sequences


Two basic discrete-time sequences are the unit sample sequence and the unit step
sequence.
The unit sample sequence, often called the discrete-time impulse or the unit impulse,denoted by
δ[n], is defined by
δ[n] = 1, for n = 0,
0, for n ≠ 0.
The unit step sequence, denoted by u[n], is defined by
u[n] = 1, for n ≥ 0,
0, for n <0.

A unit sample sequence u[n] of length N can begenerated using the MATLAB
command
u = [1 zeros(1,N -1)];
A unit sample sequence ud[n] of length N and delayed by M samples, whereM <
N, can begenerated using the MATLAB command
ud = [zeros(1,M) 1 zeros(1,N - M - 1)];
Likewise, a unit step sequence s[n] of length N can be generated using the
MATLABcommand
s = [ones(1,N)];
A delayed unit step sequence can be generated in a manner similar to that used in
thegeneration of a delayed unit sample sequence.
Program P1_1 can be used to generate and plot a unit sample sequence.
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
% Program P1_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n,u);
xlabel(’Time index n’);
ylabel(’Amplitude’);
title(’Unit Sample Sequence’);
axis([-10 20 0 1.2]);
Q1.1 Run Program P1_1 to generate the unit sample sequence u[n] and display it.
Q1.2 What are the purposes of the commands clf, axis, title, xlabel, and ylabel?
Q1.3 Modify Program P1_1 to generate a delayed unit sample sequence ud[n]
with adelay of 11 samples. Run the modified program and display the sequence
generated.
Q1.4 Modify Program P1_1 to generate a unit step sequence s[n]. Run the
modifiedprogram and display the sequence generated.
Q1.5 Modify Program P1_1 to generate a delayed unit step sequence sd[n] with
an advance of 7 samples. Run the modified program and display the sequence
generated.

2.3.2 Exponetial signals:


Another basic discrete-time sequence is the exponential sequence. Such a sequence can
begenerated using the MATLAB operators.^ and exp.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Program P1_2 given below can be employed to generate a complex-valued
exponentialsequence.
% Program P1_2
% Generation of a complex exponential sequence
clf;
c = -(1/12)+(pi/6)*i;
K = 2;
n = 0:40;
x = K*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel(’Time index n’);
ylabel(’Amplitude’);
title(’Real part’);
subplot(2,1,2);
stem(n,imag(x));
xlabel(’Time index n’);
ylabel(’Amplitude’);
title(’Imaginary part’);
Program P1_3 given belowcan be employed to generate a real-valued exponential sequence.
% Program P1_3
% Generation of a real exponential sequence
clf;
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^+n;
stem(n,x);
xlabel(’Time index n’);
ylabel(’Amplitude’);

Q1.6 Run Program P1_2 and generate the complex-valued exponential sequence.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Q1.7 Which parameter controls the rate of growth or decay of this sequence? Whichparameter
controls the amplitude of this sequence?
Q1.8 What will happen if the parameter c is changed to (1/12)+(pi/6)*i?
Q1.9 What are the purposes of the operators real and imag?
Q1.10 What is the purpose of the command subplot?
Q1.11 Run Program P1_3 and generate the real-valued exponential sequence.
Q1.12 Which parameter controls the rate of growth or decay of this sequence? Whichparameter
controls the amplitude of this sequence?
Q1.13 What is the difference between the arithmetic operators ^ and .^?
Q1.14 What will happen if the parameter a is less than 1? Run Program P1_3 again withthe
parameter a changed to 0.9 and the parameter K changed to 20.
Q1.15 What is the length of this sequence and how can it be changed?
Q1.16 You can use the MATLAB command sum(s.*s) to compute the energy of a
realsequence s[n] stored as a vector s. Evaluate the energy of the real-valued
exponentialsequences x[n] generated in Questions Q1.11 and Q1.14.

1.3.3 Sinusoidal Sequences


Another very useful class of discrete-time signals is the real sinusoidal sequence
of theform,𝑥[𝑛] = 𝐴 cos(𝜔0 𝑛 + ∅),
Such sinusoidal sequences can be generated in MATLAB using thetrigonometric
operators cos and sin.
Program P1_4 is a simple example that generates a sinusoidal signal.
% Program P1_4
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.1;
phase = 0;
A = 1.5;
arg = 2*pi*f*n - phase;
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
x = A*cos(arg);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);
grid;
title(’Sinusoidal Sequence’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
axis;
Questions:
Q1.17 Run Program P1_4 to generate the sinusoidal sequence and display it.
Q1.18 What is the frequency of this sequence and how can it be changed? Which
parametercontrols the phase of this sequence? Which parameter controls the
amplitude of thissequence? What is the period of this sequence?
Q1.19 What is the length of this sequence and how can it be changed?
Q1.20 Compute the average power of the generated sinusoidal sequence.
Q1.21 What are the purposes of the axis and grid commands?
Q1.22 Modify Program P1_4 to generate a sinusoidal sequence of frequency 0.9
anddisplay it. Compare this new sequence with the one generated in Question
Q1.17. Now, modify Program P1_4 to generate a sinusoidal sequence of
frequency 1.1 and display it.Compare this new sequence with the one generated
in Question Q1.17. Comment on yourresults.
Q1.23 Modify the above program to generate a sinusoidal sequence of length 50,
frequency0.08, amplitude 2.5, and phase shift 90 degrees and display it. What is
the periodof this sequence?

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Q1.24 Replace the stem command in Program P1_4 with the plot command and
runthe program again. What is the difference between the new plot and the one
generated inQuestion Q1.17?
Q1.25 Replace the stem command in Program P1_4 with the stairs command and
runthe program again. What is the difference between the new plot and those
generated inQuestions Q1.17 and Q1.24?
1.3.4 Random Signals
A random signal of length N with samples uniformly distributed in the interval
(0,1) canbe generated by using the MATLAB command
x = rand(1,N);
Likewise, a random signal x[n] of length N with samples normally distributed
with zeromean and unity variance can be generated by using the following
MATLAB command
x = randn(1,N);
Q1.26 Write a MATLAB program to generate and display a random signal of
length 100whose elements are uniformly distributed in the interval [−2, 2].
Q1.27 Write a MATLAB program to generate and display a Gaussian random
signal oflength 75 whose elements are normally distributed with zero mean and a
variance of 3.
Q1.28 Write a MATLAB program to generate and display five sample sequences
of arandom sinusoidal signal of length 31

where the amplitude A and the phase φ are statistically independent random
variables withuniform probability distribution in the range 0 ≤ A ≤ 4 for the
amplitude and in the range0 ≤ φ ≤ 2π for the phase.
% Program P1_5
% Generation of a random sequence
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
% Generate values from the uniform distribution on the interval
[a, b].
% r = a + (b-a).*rand(100,1);

r1 = -2+4.*rand(1,10)

%Use the RANDI function, instead of rand, to generate integer


values
%from the uniform distribution on the set 1:100.
% r = randi(100,1,5);

r2 = randi(10,1,5)
% Reset the random number generator used by rand, RANDI, and
RANDN to its
% default startup settings, so that rand produces the same
random numbers
% as if you restarted MATLAB.
rng('default')
rand(1,5)

% Generate values from a normal distribution with mean 1 and


standard
% deviation 2.
r3 = 1 + 2.*randn(1,10)

>> generate_Random_sequence_P1_5
r1 =
Columns 1 through 6
-1.4325 -0.3130 1.6629 1.1688 1.8380 0.6230
Columns 7 through 10
-1.8572 1.3965 1.7360 0.7149
r2 =
8 8 4 7 2
ans =
0.8147 0.9058 0.1270 0.9134 0.6324
r3 =
Columns 1 through 6
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
-1.6154 0.1328 1.6852 8.1568 6.5389 -1.6998
Columns 7 through 10
7.0698 2.4508 0.8739 2.4295

Q1.29 Type who in the Command window. What information is displayed in the Command
window as a result of this command?
Q1.30 Type whos in the Command window. What information is displayed in the Command
window as a result of this command?

1.3.5Square wave and Saw tooth wave


%generate square wave and sawtooth wave
%n=0: 0.001:0.0625
%z=square(2*pi*10*n);
t = 0:0.0001:0.1;
y = square(2*pi*20*t);
subplot(2,1,1);
plot(t,y)
z= sawtooth(2*pi*20*t);
%;%stem(n,z);
axis([0,.1,-1.5,1.5]);
title('Square wave Signal');
xlabel('Time index n');
ylabel('Amplitude');
grid;
subplot(2,1,2);
plot(t,z)
axis([0,.1,-1.5,1.5]);
title('SawTooth wave Signal');
xlabel('Time index n');
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
ylabel('Amplitude');
grid;
Square wave Signal

1
Amplitude

-1

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time index n
SawTooth wave Signal

1
Amplitude

-1

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time index n

The MATLAB commands used in this exercise are as follows:


Operators and Special Characters
: . + - * / ; %
Elementary Matrices and Matrix Manipulation
i ones pi rand randn zeros
Elementary Functions
cos exp imag real
Data Analysis
sum
Two-Dimensional Graphics
axis grid plot stairs stem title xlabel ylabel
General Purpose Graphics Functions
clf subplot
Signal Processing Toolbox
sawtooth square
2.4 Conclusions:

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
MATLAB codes were written and simulated to verify the waveforms to generate and plot
different signals

Expt. 2:
Evaluation of Discrete Fourier Transform (DFT)

2.1 AIM: To evaluate DFT of a given siquence.

2.2 Components required: MATLAB software.

2.3 Theory and MATLAB Code:

Discrete Fourier Transform

The N-point discrete Fourier transform (DFT) of a finite-length sequence x[n],


defined for 0 ≤ n ≤ N − 1, is given by
𝑁−1
2𝜋
𝑋[𝑘] = ∑ 𝑥[𝑛]𝑒 −𝑗 𝑁 𝑛𝑘 , 𝑘 = 0, 1, 2, . . . . . . . . 𝑁 − 1,
𝑛=0

And IDFT is given by,

𝑁−1
1 2𝜋
𝑥 [𝑛 ] = ∑ 𝑋[𝑘]𝑒 𝑗 𝑁 𝑛𝑘 , 𝑛 = 0, 1, 2, . . . . . . . . 𝑁 − 1,
𝑁
𝑘=0

2.3.1 Find DFT and IDFT of a given sequence


1. x[n] =[1 1 1 1 0 0 0 0]
2. x(n) = 0.8n for a. N=50 b. N=5
3. g[n]=[1 3 5 7 9 11 13 15 17]
%1. x=[1 1 1 1 0 0 0 0]
x=[1 1 1 1 0 0 0 0];
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
N=length(x);
for k=0:N-1
sum=0;
for n=0:N-1
sum = sum+(x(n+1)*exp((-i*2*pi*k*n)/N));
end;
X(k+1)=sum;
end;
disp(X);
clf;
subplot (3,2,1)
stem(x)
title('input sequence x(n)')
subplot (3,2,3)
stem(abs(X))
title('Absolute value of DFT of x(n)')
subplot(3,2,4)
stem(imag(X))
title('Imaginary part of DFT of x(n)')
subplot(3,2,5)
stem(angle(X)*180/pi)
title('Phase plot of DFT of x(n)')
for n=0:N-1
sum1=0;
for k=0:N-1
sum1 = sum1+(X(k+1)*exp((i*2*pi*k*n)/N))

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
end;
y(n+1)=(sum1/N)
end;
subplot(3,2,6)
stem(abs(y))
title('IDFT of X(k)')

input sequence x(n)


1

0.5

0
0 2 4 6 8
Absolute value of DFT of x(n) Imaginary part of DFT of x(n)
4 5

2 0

0 -5
0 2 4 6 8 0 2 4 6 8
Phase plot of DFT of x(n) IDFT of X(k)
200 2

0 1

-200 0
0 2 4 6 8 0 2 4 6 8

% 2. x(n) = 0.8n for a. N=50 b. N=5


% a. N=50 Reduced aliasing effect
n1=0:49;
x1=0.8.^n1;
figure(2);
subplot (3,2,1)
stem(x1)
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
title('input sequence x(n) for N= 50')
for k1=0:49
sum2=0;
for n1=0:49
sum2 = sum2+(x1(n1+1)*exp((-i*2*pi*k1*n1)/50));
end;
X1(k1+1)=sum2;
end;
n1=0:49;
subplot (3,2,3)
stem(abs(X1))
title('Absolute value of DFT of x(n)')
for n=0:49
sum1=0;
for k=0:49
sum1 = sum1+(X1(k+1)*exp((i*2*pi*k*n)/50))
end;
y1(n+1)=(sum1/50);
end;
subplot(3,2,5)
stem(abs(y1))
title('IDFT of X(k)')

% b. N=5 with aliasing effect.


n2=0:4;
x2=0.8.^n2;

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
figure(2);
subplot (3,2,2)
stem(x2)
title('input sequence x(n) for N=5')
for k2=0:4
sum2=0;
for n2=0:4
sum2 = sum2+(x2(n2+1)*exp((-i*2*pi*k2*n2)/5));
end;
X2(k2+1)=sum2;
end;
subplot (3,2,4)
stem(abs(X2))
title('Absolute value of DFT of x(n)')
for n2=0:4
sum1=0;
for k2=0:4
sum1 = sum1+(X2(k2+1)*exp((i*2*pi*k2*n2)/5))
end;
y2(n2+1)=(sum1/5);
end;
subplot(3,2,6)
stem(abs(y2))
title('IDFT of X(k)')

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

input sequence x(n) N= 50 input sequence x(n)N=5


1 1

0.5 0.5

0 0
0 20 40 60 1 2 3 4 5
Absolute value of DFT of x(n) Absolute value of DFT of x(n)
5 4

0 0
0 10 20 30 40 50 1 2 3 4 5
IDFT of X(k) IDFT of X(k)
1 1

0.5 0.5

0 0
0 20 40 60 1 2 3 4 5

2.3.2 Modify the above program to evaluate the 1024 point DFT of the any
audio sequence in wave format.

%Project 2.2: To find 1024 point DFT of an audio sequence in wave format.
% Audio file should be present in the same folder as that of your matlab
% code i.e. *.m file. Copy any audio file that is present on your pc from
% C:\Windows\Media\ any .wav file

a=audioread('chimes.wav');
figure(3);
subplot(3,2,1);
stem(a);

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
title('input audio sequence');
N=1024;
a1=a(1:N);
subplot(3,2,2);
stem(a1);
title('input audio sequence sampled for 1024 samples');
Xk=fft(a1);
subplot (3,2,3)
stem(abs(Xk))
title('Absolute value of DFT of x(n)')
subplot(3,2,4)
stem(imag(Xk))
title('Imaginary part of DFT of x(n)')
subplot(3,2,5)
stem(angle(Xk)*180/pi)
title('Phase plot of DFT of x(n)')

xn=ifft(Xk)
subplot(3,2,6)
stem(xn)
title(signal x(n)')

2.3.3 Consider a discrete time signal given by


𝑥[𝑛] = cos(2𝜋𝑓1 𝑛) + cos(2𝜋𝑓2 𝑛) where, f1 = 1/128 and f2 = 5/128

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
The carrier signal is given by
𝑥𝑐 [𝑛] = cos(2𝜋𝑓𝑐 𝑛) where, fc = 50/128
The amplitude modulation is given by,
𝑥𝑎𝑚 [𝑛] = 𝑥[𝑛] ∗ 𝑥𝑐 [𝑛]
a. Compute the 256 point DFT and IDFT for signal x[n].
b. Compute the 256 point DFT and IDFT for signal xam[n].

2.4 Conclusions:
MATLAB code to find DFT and IDFT of a given sequences were written
and simulated.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

Expt 3:
Properties of Discrete Fourier Transform (DFT).
3.1 AIM: To evaluate DFT of a given siquence.

3.2 Components required: MATLAB software.

3.3 Theory and MATLAB Code:


The N-point discrete Fourier transform (DFT) of a finite-length sequence
x[n],defined for 0 ≤ n ≤ N − 1, is given by

The discrete Fourier transform (DFT) X[k] of a finite-length sequence x[n] can be
easily computed in MATLAB using the function fft. There are two versions of
this function. fft(x) computes the DFT X[k] of the sequence x[n] where the length
of X[k] is the same as that of x[n]. fft(x,L) computes the L-point DFT of a
sequence x[n] of lengthN where L ≥ N. IfL > N,x[n] is zero-padded with L−N
trailing zero-valued samples before the DFT is computed. The inverse discrete
Fourier transform (IDFT) x[n] of a DFT sequence X[k] can likewise be computed
using the function ifft, which also has two versions.

Verify the following DFT properties:


1. Linearity
2. Circular time shift property.
3. Circular frequency shift property
4. Circular convolution.
5. Parsval’s theorem.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
% DFT Properties
clear all;
close all;
clc;
𝑁−𝑝𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
%1. Linearity 𝑎1 𝑥1 [𝑛] + 𝑎2 𝑥2 [𝑛] ↔ 𝑎1 𝑋1 [𝑘] + 𝑎2 𝑋2 [𝑘]
x1=[1 2 3 4];
x2=[1 1 1 1];
a1=10;
a2=1+2i;
X1=fft(x1);
X2=fft(x2);
disp('linearity property :')
X3=fft((a1*x1)+(a2*x2))
X4=(a1*X1)+(a2*X2)

𝑁−𝑝𝑜𝑖𝑛𝑡 𝐷𝐹𝑇 −𝑗2𝜋𝑙𝑘


% 2. Circular Time shift Property 𝑥[𝑛 − 𝑙] ↔ 𝑋[𝑘]𝑒 𝑁

x1=[1 2 3 4];
N=length(x1)
X1=fft(x1);
m=2;
disp('Circular Time shift Property')
x1k=[x1(m+1):length(x1) x1(1:m)]; % x(n-2);
X1k=fft(x1k)
k=0:N-1;
X2k=X1.*exp((-1i*2*pi*k*m)/N)

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

𝑗2𝜋𝑙𝑛 𝑁−𝑝𝑜𝑖𝑛𝑡 𝐷𝐹𝑇


% 3. Circular frequency shift property 𝑥[𝑛]𝑒 𝑁 ↔ 𝑋[𝑘 − 𝑙]
x=[1 2 3 4]
disp('Circular frequency shift property.')
X=fft(x)
N=length(x);
n=0:N-1;
x1=x.*exp(1i*2*pi*2*n/N);
X1=fft(x1)

𝑁−𝑝𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
% 4. Circular convolution. 𝑥1 [𝑛] ∗ 𝑥2 [𝑛] ↔ 𝑋1 [𝑘]. 𝑋2 [𝑘]
x1=[2 1 2 1];
x2=[1 2 3 4];
disp('Circular convolution.')
cconv=cconv(x1,x2,4)
X1=fft(x1);
X2=fft(x2);
xconvdft=ifft(X1.*X2)

1
%5. Parseval’s theorem.∑𝑁−1 ∗
𝑛=0 𝑥[𝑛]ℎ [𝑛] = 𝑋[𝑘]𝐻∗ [𝑘]
𝑁

N = 4;
x = randn(1,N) + 1i*randn(1,N);
g = randn(1,N) + i*randn(1,N);
disp('Parsval’s theorem.')
X = fft(x);
G = fft(g);
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
z= sum(x.*conj(g))
Z=sum(X.*conj(G))/N

linearity property :

X3 =

1.0e+02 *

Columns 1 through 3

1.0400 + 0.0800i -0.2000 + 0.2000i -0.2000 + 0.0000i

Column 4

-0.2000 - 0.2000i

X4 =

1.0e+02 *

Columns 1 through 3

1.0400 + 0.0800i -0.2000 + 0.2000i -0.2000 + 0.0000i

Column 4

-0.2000 - 0.2000i

Periodicity property :

X2 =

Columns 1 through 3

10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 + 0.0000i

Column 4

-2.0000 - 2.0000i

X1=
Columns 1 through 3

10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 - 0.0000i

Column 4

-2.0000 - 2.0000i

Circular Time shift Property

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

X1k =

Columns 1 through 3

10.0000 + 0.0000i 2.0000 - 2.0000i -2.0000 + 0.0000i

Column 4

2.0000 + 2.0000i

X2k =

Columns 1 through 3

10.0000 + 0.0000i 2.0000 - 2.0000i -2.0000 - 0.0000i

Column 4

2.0000 + 2.0000i

Circular frequency shift property.

X =

Columns 1 through 3

10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 + 0.0000i

Column 4

-2.0000 - 2.0000i

X1 =

Columns 1 through 3

-2.0000 + 0.0000i -2.0000 - 2.0000i 10.0000 - 0.0000i

Column 4

-2.0000 + 2.0000i

Circular convolution.

xcconv =

14 16 14 16

xconvdft =

14 16 14 16

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

Parsval’s theorem.

z =

-1.2264 + 2.7518i

Z =

-1.2264 + 2.7518i

3.4 Conclusions:
MATLAB code to verify properties of DFT were written and verified.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

Expt. No. 4
Realization of IIR Filter Transfer Functions
4.1 AIM: To realize IIR filter.

4.2 Components required: MATLAB software.

4.3 Theory and MATLAB Code:


Introduction
A structural representation using interconnected basic building blocks is the first step in
thehardware or software implementation of an LTI digital filter. The structural
representationprovides the relations between some pertinent internal variables with the input
and theoutput that in turn provide the keys to the implementation. This exercise considers
thedevelopment of structural representations of causal IIR transfer functions in theform of
block diagrams.
A causal IIR filter of order N is characterized by a transfer function H(z):

∑𝑀
𝑘=0 𝑏𝑘 𝑧
−1
𝐻 (𝑧) = (1)
1− ∑𝑁
𝑘=1 𝑎𝑘 𝑧
−1

which is a ratio of polynomials in z−1 of degree N. In the time domain the input-outputrelation
of the above IIR filter is given by
𝑦[𝑛] = ∑𝑀 𝑁
𝑘=0 𝑏𝑘 𝑥[𝑛 − 𝑘] − ∑𝑘=1 𝑎𝑘 𝑦[𝑛 − 𝑘] (2)

Cascade Form
By expressing the numerator and the denominator polynomials of the transferfunction H(z) as a
product of polynomials of lower degree, a digital filter is often realizedas a cascade of low-
order filter sections. Usually, the polynomials are factored into a productof first-order and
second-order polynomials. In this case, H(z) is expressed as

𝐻 (𝑧) = ∏𝐾
𝑘=1 𝐻𝑘 (𝑧) (3)

Where,
𝑏0𝑘 + 𝑏1𝑘 𝑧 −1 + 𝑏2𝑘 𝑧 −2
𝐻𝑘 (𝑧) = (4)
1+ 𝑎1𝑘 𝑧 −1 + 𝑎2𝑘 𝑧 −2
ETC/ECE 5.1 – Digital Signal Processing
Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

Project 4.1 Cascade and Parallel Realizations


The factored form of a causal IIR transfer function H(z) of order N as given in Eq. (3)can be
determined from its rational form representation given by Eq. (1), which then canbe used to
realize H(z) in a cascade form. To this end, Program P4_1 can be employed.
% Program P4_1
% Conversion of a rational transfer function to its factored form
num = input('Numerator coefficient vector = ');
den = input('Denominator coefficient vector = ');
[A, B] = eqtflength(num, den);
[z,p,k] = tf2zp(A, B);
sos = zp2sos(z,p,k)

zp2sos Zero-pole-gain to second-order sections model conversion.


[SOS,G] = zp2sos(Z,P,K) finds a matrix SOS in second-order sections form and a gain G
which represent the same system H(z) as the onewith zeros in vector Z, poles in vector P and
gain in scalar K.The poles and zeros must be in complex conjugate pairs. SOS is an L by 6
matrix with the following structure:
SOS = [ b01 b11 b21 1 a11 a21
b02 b12 b22 1 a12 a22
...
b0L b1L b2L 1 a1L a2L ]
Each row of the SOS matrix describes a 2nd order transfer function:
b0k + b1k z^-1 + b2k z^-2
Hk(z) = ----------------------------
1 + a1k z^-1 + a2k z^-2
where k is the row index.
Questions:
Q4.1Using Program P4_1 develop a cascade realization of the following causal IIR
transferfunction:

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering

(I)

Sketch the block diagram of the cascade realization.

Numerator coefficient vector = [3,8,12,7,2,-2]


Denominator coefficient vector = [16,24,24,14,5,1]
sos =

0.1875 -0.0625 0 1.0000 0.5000 0


1.0000 2.0000 2.0000 1.0000 0.5000 0.2500
1.0000 1.0000 1.0000 1.0000 0.5000 0.5000

Q4.2Using Program P4_1 develop a cascade realization of the following causal IIR transfer
functi
on:

(II)

Sketch the block diagram of the cascade realization.


Numerator coefficient vector = [2,10,23,34,31,16,4]
Denominator coefficient vector = [36,78,87,59,26,7,1]

sos =

0.0556 0.1667 0.1111 1.0000 0.5000 0.2500


1.0000 1.0000 2.0000 1.0000 1.0000 0.3333
1.0000 1.0000 0.5000 1.0000 0.6667 0.3333

Parallel Form

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Parallel Form isbased on its partial-fraction expansion in z−1 as in Eq. (5), which can be
obtained usingMATLAB function residuez.
𝐴𝑘
𝐻(𝑧) = 𝐶 + ∑𝑁
𝑘=1 (5)
1− 𝑝𝑘 𝑧 −1

Where pk are the poles, Ak are the coefficients (residues) in the partial-fraction expansion, and
the constant C is defined as C=bN/aN.
[r,p,k] = residuez(b,a) finds the residues, poles, and direct terms of a partial fraction
expansion of the ratio of two polynomials, b(z) and a(z). Vectors b and a specify the
coefficients of the polynomials of the discrete-time system b(z)/a(z) in descending
powers of z.

B(z) =b0+b1z−1+b2z−2+⋯+bmz−m

A(z) =a0+a1z−1+a2z−2+⋯+anz−n
If there are no multiple roots and a > n-1,

% Program P4_2
% Parallel Form Realizations of an IIR Transfer Function
num = input('Numerator coefficient vector = ');
den = input('Denominator coefficient vector = ');
[r1,p1,k1] = residuez(num,den);
disp('Residues are');disp(r1);
disp('Poles are at');disp(p1);
disp('Constant value');disp(k1);

Questions:
Q4.3Using Program P4_2 develop the parallel-form realization of thecausal IIR transfer
function of Eq. (I). Sketch the block diagram of realization.

Q4.4Using Program P4_2 develop the parallel-form realization of thecausal IIR transfer
function of Eq. (II). Sketch the block diagram of realization.

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Numerator coefficient vector = [2,10,23,34,31,16,4]
Denominator coefficient vector = [36,78,87,59,26,7,1]
Residues are
-0.5556 - 2.2785i
-0.5556 + 2.2785i
-0.5952 - 0.7561i
-0.5952 + 0.7561i
-0.8214 + 4.3920i
-0.8214 - 4.3920i

Poles are at
-0.3333 + 0.4714i
-0.3333 - 0.4714i
-0.5000 + 0.2887i
-0.5000 - 0.2887i
-0.2500 + 0.4330i
-0.2500 - 0.4330i

Constant value
4
% Program P4_3
% Parallel Form Realizations of an IIR Transfer Function
b0 = 1;
b1 = [1 -2/3];
b2 = [1 3/2 -1];
a1 = [1 -7/8 3/32];
a2 = [1 -1 1/2];
b = b0*conv(b1,b2);
a = conv(a1,a2);
[r,p,k] = residuez(b,a)

ETC/ECE 5.1 – Digital Signal Processing


Padre Conceicao College of Engineering, Verna, Goa
Affiliated to Goa University, Taleigao Plateau, Goa
Department of Electronics & Telecommunication Engineering
Q4.5Using Program P4_3 develop the parallel-form realizations of thecausal IIR transfer
function of Eq. (III). Sketch
the block diagrams of both
realizations.
(III)

r=

0.2933 + 0.0000i
1.2373 - 1.4720i
1.2373 + 1.4720i
-1.7680 + 0.0000i

p=

0.7500 + 0.0000i
0.5000 + 0.5000i
0.5000 - 0.5000i
0.1250 + 0.0000i

k=

[]

4.4 Conclusions:
MATLAB code to find the coefficients to realize IIR filters were written.

ETC/ECE 5.1 – Digital Signal Processing

You might also like