Lab Manual DSP1
Lab Manual DSP1
LABORATORY MANUAL
Digital signal processing
List of Experiments
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
Experiment No 1.
Generate and plot different signals.
1.1 Aim: Write a MATLAB code to generate and plot different signals.
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.
Q1.6 Run Program P1_2 and generate the complex-valued exponential sequence.
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)
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_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
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
Expt. 2:
Evaluation of Discrete Fourier Transform (DFT)
𝑁−1
1 2𝜋
𝑥 [𝑛 ] = ∑ 𝑋[𝑘]𝑒 𝑗 𝑁 𝑛𝑘 , 𝑛 = 0, 1, 2, . . . . . . . . 𝑁 − 1,
𝑁
𝑘=0
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
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);
xn=ifft(Xk)
subplot(3,2,6)
stem(xn)
title(signal x(n)')
2.4 Conclusions:
MATLAB code to find DFT and IDFT of a given sequences were written
and simulated.
Expt 3:
Properties of Discrete Fourier Transform (DFT).
3.1 AIM: To evaluate DFT of a given siquence.
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.
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)
𝑁−𝑝𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
% 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
Column 4
-0.2000 - 0.2000i
X4 =
1.0e+02 *
Columns 1 through 3
Column 4
-0.2000 - 0.2000i
Periodicity property :
X2 =
Columns 1 through 3
Column 4
-2.0000 - 2.0000i
X1=
Columns 1 through 3
Column 4
-2.0000 - 2.0000i
X1k =
Columns 1 through 3
Column 4
2.0000 + 2.0000i
X2k =
Columns 1 through 3
Column 4
2.0000 + 2.0000i
X =
Columns 1 through 3
Column 4
-2.0000 - 2.0000i
X1 =
Columns 1 through 3
Column 4
-2.0000 + 2.0000i
Circular convolution.
xcconv =
14 16 14 16
xconvdft =
14 16 14 16
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.
Expt. No. 4
Realization of IIR Filter Transfer Functions
4.1 AIM: To realize IIR filter.
∑𝑀
𝑘=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
(I)
Q4.2Using Program P4_1 develop a cascade realization of the following causal IIR transfer
functi
on:
(II)
sos =
Parallel Form
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.
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)
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.