Objective: CLC Clear All Close All
Objective: CLC Clear All Close All
The convolution of two discrete time sequences x[n] and To create the signals,
h[n] can be computed as follows,
≫ x = [0 1 0 0 0 0];
∞
X
y[n] = x[n] ∗ h[n] = x[k]h[n − k] ≫ xs = [1 1 1 1 1 1];
k=−∞
Now, convolve the signals and create a time vector
or, equivalently,
∞
≫ y = conv(x,xs);
X
y[n] = h[n] ∗ x[n] = h[k]x[n − k] ≫ t = 0:length(y)-1;
k=−∞
This sum of products (or convolution sum) is in fact And, to plot the output.
a function of n that represent the overlap between x[n]
≫ stem(t,y);
and the time-reversed and shifted version of h[n]. The
number of samples N in the output signal y[n] will be What can you observe about the output? Try shifting
N = M1 + M2 –1. Where, M1 is the number of samples the time square wave and/or the impulse. How does
in sequence x[n] and M2 is the number of samples in this change the convolution output? Try to convolve
sequence h[n]. two square waves y[n] = xs [n] ∗ xs [n] and observe the
In MATLAB, the function y = conv(x, h) implements result.
the convolution of two finite length sequences x(n) and
h(n), generating the finite length sequence y. The pro-
cess is illustrated in the following example. 1.3 Example
Determine and sketch the convolution sum of,
1.1 Convolution of two impulses x(n) = [−2 0 1 −1 3] and h(n) = [1 2 0 −1]
clc , clear all , close all
Lets say we want to examine the convolution sum of two x = [ -2 0 1 -1 3]; % x ( n )
impulses, e.g. y[n] = δ[n] ∗ δ[n − 1] using the time axis h = [1 2 0 -1]; % h ( n )
n = [0, 1, 2] y = conv (x , h ) ; % convoluti o n
n1 = length ( h ) -1;
≫ x1 = [1 0 0]; n2 = length ( x ) -1;
k = - n1 :1: n2 ;
disp ([ ’ Output Sequence y [ n ] = ’ , num2str ( y ) ]) ;
≫ x2 = [0 1 0];
figure ;
subplot (311)
Now, we can convolve them, and create the proper stem (x , ’ . ’) , title ( ’ x [ n ] ’)
time vector the output. subplot (312)
stem (h , ’ . ’) , title ( ’ h [ n ] ’)
≫ y = conv(x1,x2); subplot (313)
stem (k ,y , ’. ’) , title ( ’y [ n ] ’)
≫ t = 0:length(y)-1; To have better insight, lets do another example where,
And, to see the result graphically, let’s plot the out- x(n) = { 1 ↑2 3 } and h(n) = { 2 4 ↑3 5 }. Using the MAT-
put. LAB script.
clc , clear all , close all
≫ stem(t,y); x = [1 ,2 ,3]; % x ( n )
nx = -1:1;
h = [2 ,4 ,3 ,5]; % h ( n )
What can you observe about the output of this sys- nh = -2:1;
tem? Try changing the order of convolution, i.e. try nyb = nx (1) + nh (1) ; nye = nx ( length ( x ) ) + nh (
conv(x2,x1). Does this change the output? length ( h )) ;
1/3
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES
ADVANCED DIGITAL SIGNAL PROCESSING
Lab 4: Convolution Sum and Correlation
2/3
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES
ADVANCED DIGITAL SIGNAL PROCESSING
Lab 4: Convolution Sum and Correlation
4.1 Example
Find the autocorrelation function of the signal,
x(n) = [1 2 1 1]
clc , clear all , close all
x = [1 2 1 1];
y = xcorr2 ( x ) ;
n = length ( x ) -1;
k = - n :1: n ;
disp ([ ’ Output Sequence y [ n ] = ’ , num2str ( y ) ]) ;
figure ;
subplot (211)
stem (x , ’ . ’) , title ( ’ x [ n ] ’ )
subplot (212)
stem (k ,y , ’. ’)
title ( ’y [ n ] ’)
xlabel ( ’ Lag index k ’ )
ylabel ( ’ Amplitude ’)
3/3