Experiment Lab Report 2
Experiment Lab Report 2
Fall 2022
DIGITAL SIGNAL PROCESSING
LABORATORY EEE 3310
Lab Report – 2
Submitted to:
Dr. Khawza Iftekhar Uddin Ahmed
Submitted by:
GROUP 1
Name ID
Introduction: From this lab session-02 we understand how to solve difference equation system
response using filter function. We also know how to solve the convolution and correlation of
the given equation. We also learn about cross correlation and autocorrelation.
Theoretical Background: To understand the system response of any LTI system and the
relation between the input and the output of the system. To find the correlation of the different
output signals.
In Lab Evaluation:
1. A difference equation is given as, y(n)-0.3y(n-2)=0.2x(n) . Find y(n) for an input
x(n) =u(n)-u(n-3)
Code:
b=[0.2];
a=[1,-0.3];
n=[-5:10];
x=u(0,-5,10)-u(3,-5,10);
y=filter(b,a,x);
stem(n,y);
title('Output sequence');
xlabel('n');
ylabel('y(n)');
axis([-5,10,-0.1,0.35])
Page 2 of 9
2. Two sequences are given by, x(n) = [1 2 3] y(n) = [4 5 6]
(a) Find their crosscorrelation using xcorr function
(b) Find their crosscorrelation using conv function
(c) Find the correlation coefficient
Code:
x = [1 2 3];
nx = [1:3];
y = [4 5 6];
ny = [1:3];
rxy1=xcorr(x,y);
rxy1=rxy1/max(rxy1);
ny1 = -fliplr(ny);
nxy = [(nx(1) + ny1(1)):(nx(end) + ny1(end))];
[rxy2,nxy] = conv_m(x,nx,y,ny);
rxy2=rxy2/max(rxy2);
Xm=x-mean(x);
Ym=y-mean(y);
rxy3 = sum(Xm.*Ym)/sqrt(sum(Xm.^2)*sum(Ym.^2));
disp('The correlation coefficient is:');
disp(rxy3)
subplot(2,1,1);
Page 3 of 9
stem(nxy,rxy)
title('using xcorr function');
subplot(2,1,2);
stem(nxy,rxy2);
title('using conv function');
Page 4 of 9
Homework:
1. Invoke the following MATLAB commands and plot the result (y versus ny) x1 =
[0, 0, 1, 1, 1, 1, 1]; nx1 = [-3:3]; x2 = [0, 0, 0, 1, 1, 1]; nx2 = [-3:2]; Find the
crosscorrelation of x1 and x2 .
Code:
x1 = [0, 0, 1, 1, 1, 1, 1];
nx1 = [-3:3];
x2 = [0, 0, 0, 1, 1, 1];
nx2 = [-3:2];
[y1,ny1] = sigfold(x2,nx2);
[rxy1,nxy1] = conv_m(x1,nx1,y1,ny1);
subplot(2, 1, 1);
stem(nxy1,rxy1/max(rxy1))
[y2,ny2] = sigfold(x1,nx1);
[rxy2,nxy2] = conv_m(x2,nx2,y2,ny2);
subplot(2, 1, 2);
stem(nxy2,rxy2/max(rxy2))
Page 5 of 9
2. Determine the autocorrelation sequence and crosscorrelation sequence for the
following sequences. y(n) (0.8) , 20 n 0 x(n) (0.9) , 0 n 20 n n
What is your observation ?
Code:
nx = [ 0:20 ];
x = (0.9).^nx;
Page 6 of 9
ny = [-20:0 ];
y = (0.8).^ny;
[y,ny] = sigfold(y,ny);
[rxy,nxy] = conv_m(x,nx,y,ny);
subplot(2,1,1);
stem(nxy,rxy/max(rxy))
title('Crosscorrelation Sequence')
nx = [ 0:20 ]; x = (0.9).^nx;
[x1,nx1] = sigfold(x,nx);
[rxx1,nxx1] = conv_m(x,nx,x1,nx1);
subplot(2,1,2);
stem(nxx1,rxx1/max(rxx1))
title('Autocorrelation Sequence')
Page 7 of 9
3. Consider a 20 point moving average filter
(a) Generate 200 samples of a 1 Hz sine wave sampled at 40 Hz.
(b) Add some noise to generate a noisy signal.
(c) Filter the noisy signal through the 20 point MA filter.]
(d) (d) Plot each signal to display the effects of noise and smoothing.
Code:
a = [1];
b = [1/200 1/200 1/200];
n = [0:20];
xn = (2*pi*200*(1/40));
[xn1, n1] = sigshift(xn, n, 1);
[xn2, n2] = sigshift(xn, n, 199);
[xn3, n3] = sigadd(xn, n, xn1, n1);
[xn4, n4] = sigadd(xn2, n2, xn3, n3);
xn5 = xn4+(0.3.*randn(size(n4)));
w = filter(b,a,xn5);
stem(n4,xn5);
title('Noisy Signal.');
xlabel('n');ylabel('x(n1)');
Page 8 of 9
Statement: I Have contributed and given my full support in completing this report.
Page 9 of 9