VTU DSP Lab Using Compose
VTU DSP Lab Using Compose
(2)
1
Contents
Experiment 1: Verification of Sampling Theorem ........................................................................................ 3
Experiment 2: Impulse response of a system ............................................................................................... 5
Experiment 3: Linear Convolution of two signals ......................................................................................... 7
3a: Linear Convolution of two sequences..................................................................................................... 7
3b: Linear Convolution using DFT/IDFT ........................................................................................................ 8
Experiment 4: Circular convolution of two given sequences ..................................................................... 10
Experiment 5: Autocorrelation of a given sequence and verification of its properties ............................. 12
Experiment 6: Solving a given difference equation. ................................................................................... 14
Software Code:............................................................................................................................................ 14
Experiment 7: Computation of N point DFT of a given sequence and to plot magnitude and phase
spectrum. .................................................................................................................................................... 16
Experiment 8: Circular convolution of two given sequences using DFT and IDFT ...................................... 18
Experiment 9: Design and implementation of IIR Butterworth filter to meet given specifications ........... 20
Table of figures
2
Experiment 1: Verification of Sampling Theorem
Description:
In this experiment the task is to understand how sampling theorem works and demonstrate the ideal
sampling, under sampling as well as over sampling scenarios for a given signal
Software code:
3
subplot(2,2,4);
stem(n,x_ts3);
title('less than Nq');
xlabel('n');
ylabel('x(n)');
Simulation Results:
4
Experiment 2: Impulse response of a system
Description: Impulse response of a dynamic system is its output when presented with a brief input signal
called an impulse. Since it contains all frequencies, the impulse response defines the response of a LTI system
for all frequencies.
Software Code:
% y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
ylabel('Amplitude');
grid on;
disp(h);
function [h,t]=impz(b,a,N)
imp=[1 zeros(1,N-1)]; % Padding Zeros from 1 to N-1 points since impulse fn is defined only at 0.
end
Simulation Results:
b= [1 0.5 0.85];
a= [1 -1 -1];
5
Number of samples=10;
Output sequence= [1, 1.5, 3.35, 4.85, 8.2, 13.05, 21.25, 34.3, 55.55, 89.85]
6
Experiment 3: Linear Convolution of two signals
Software Code:
Sequence1: [1 2 3]
Sequence2: [1 2 3 4]
Out put sequence=[1, 4, 10, 16, 17, 12]
7
Figure 3.a.1: Linear Convolution of two sequence
Software code:
8
m = n1+n2-1; % Length of linear convolution
x = [x1 zeros(1,n2-1)]; % Padding of zeros to make it of length m
y = [x2 zeros(1,n1-1)];
x_fft = fft(x,m); % Finding dft
y_fft = fft(y,m);
dft_xy = x_fft.*y_fft; % Convoluted sequence in frequency domain
y=ifft(dft_xy,m); % Circular convoluted sequence in discrete domain
disp('The circular convolution result is ......');
disp(y);
subplot(3,1,3);
stem(y); % Plot for convoluted sequence
title('Circularly convoluted sequence');
xlabel('Time index, n');
ylabel('Amplitude');grid on;
Simulation Results:
Sequence 1:[1 2 3]
Sequence 2: [ 1 2 3 4]
9
Experiment 4: Circular convolution of two given sequences
Description: To find the circular convolution of two given sequences. The circular convolution, also known
as cyclic convolution, of two aperiodic functions occurs when one of them is convolved in the normal way with
a periodic summation of the other function.
Software code:
subplot(3,1,1);
title('First sequence');
ylabel('Amplitude');grid on;
subplot(3,1,2);
title('Second sequence');
ylabel('Amplitude');grid on;
y2=fft(x2,n);
y3=y1.*y2;
disp(y);
10
subplot(3,1,3);
ylabel('Amplitude');grid on;
Simulation Results:
Sequence1:[1,2,3]
Sequence 2:[1,2,3,4]
11
Experiment 5: Autocorrelation of a given sequence and verification of its
properties
Description: To find the auto correlation of two sequences. Autocorrelation, also known as
serial correlation or cross-autocorrelation, is the cross-correlation of a signal with itself at different points in
time (that is what the cross stands for). Informally, it is the similarity between observations as a function of
the time lag between them.
Software code:
12
Figure 5.1: Auto correlation of Two Discrete Sequences
13
Experiment 6: Solving a given difference equation.
Description: To solve a difference equation. The difference equation is a formula for computing an output
sample at time, n based on past and present input samples and past output samples in the time domain.
Software Code:
clc; clear all; close all;
subplot(3,1,1);
xlabel('Time index,n');
ylabel('Amplitude');
subplot(3,1,2);
xlabel('Time index,n');
ylabel('Amplitude');
% y(n)-(1/2)*y(n-1) = (1/2)*x(n)+(1/2)*x(n-1)
subplot(3,1,3)
stem(t,h);
14
title('plot of impulse response');
ylabel('amplitude');
xlabel('time index----->N');
Simulation Results:
b=[0.5 0.5]
a=[1 -0.5]
N=10
Output sequence for impulse response=[0.5, 0.75, 0.375, 0.1875, 0.09375, 0.04688, 0.02344, 0.01172,
0.00586, 0.00293]
15
Experiment 7: Computation of N point DFT of a given sequence and to
plot magnitude and phase spectrum.
Description: Computation of N Point DFT and plotting magnitude and phase spectrum
Software code:
n=[0:1:N-1];
k=[0:1:N-1];
nk=n'*k;
WNnk=WN.^nk;
subplot(2,1,1);
title('Magnitude Plot');
xlabel('Time index,n')
ylabel('Magnitude');grid on;
subplot(2,1,2);
xlabel('Time index,n')
ylabel('Phase (deg)');
16
Simulation Results:
Value of N=4
Figure 7.1: Computation of N point DFT of a sequence to plot magnitude and phase spectrum
17
Experiment 8: Circular convolution of two given sequences using DFT and
IDFT
Description: To find the circular convolution of two given sequences using DFT and IDFT
Software Code:
subplot(3,1,1);
title('First sequence');
xlabel('Time index,n')
ylabel('Amplitude');grid on;
subplot(3,1,2);
title('Second sequence');
xlabel('Time index,n')
ylabel('Amplitude');grid on;
y2=fft(x2,n);
y3=y1.*y2;
disp(y);
subplot(3,1,3);
xlabel('Time index,n');
18
ylabel('Amplitude');grid on;
Simulation Results:
Sequence1=[1 2 3]
Sequence 2=[1 2 3 4]
Figure 8.1: Circular convolution of two sequences using DFT and IDFT
19
Experiment 9: Design and implementation of IIR Butterworth filter to
meet given specifications
Description: Design and implementation of IIR BUTTERWORTH filter to meet given specifications.
Software code:
20
Simulation results
21