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

EXPERIMENT2

This document describes experiments on convolution and correlation of discrete time signals using MATLAB. It provides the theory, code, and results for linear convolution of sequences [a,b,c] and [e,f,g], observing that the output length is the sum of inputs minus one. It also gives the theory, code, and results for correlation, noting that the correlation function is asymmetric and the peak indicates the direction of relationship between signals.

Uploaded by

Sanjith Pranav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

EXPERIMENT2

This document describes experiments on convolution and correlation of discrete time signals using MATLAB. It provides the theory, code, and results for linear convolution of sequences [a,b,c] and [e,f,g], observing that the output length is the sum of inputs minus one. It also gives the theory, code, and results for correlation, noting that the correlation function is asymmetric and the peak indicates the direction of relationship between signals.

Uploaded by

Sanjith Pranav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

EXPERIMENT-2A

Convolution of discrete time signals

AIM:
To perform Linear convolution of discrete time signals.

SOFTWARE REQUIRED:
Matlab software

THEORY:
To calculate discrete linear convolution for two sequences namely,
x[n] = [a, b, c]
h[n] = [e, f, g]
The convolved output will be
x[n] * h[n] = [ea, fa+eb, ga+fb+ec, gb+fc, gc]

MATLAB SOURCE CODE:


clc
clear all
close all
l1=input('Enter the lower time index of first sequence');
u1=input('Enter the upper time index of first sequence');
n1=l1:1:u1;
x=input('Enter the sample values for each n1');
l2=input('Enter the lower time index of second sequence');
u2=input('Enter the upper time index of second sequence');
n2=l2:1:u2;
h=input('Enter the sample values for each n2');
n3=(l1+l2):(u1+u2);
L=length(x);
M=length(h);
n=L+M-1;
if L>=M
H=[h zeros(1,L-M)];
X=x;
else
X=[x zeros(1,M-L)];
H=h;
end
for i=1:length(X)
for j=1:length(H)
w(i,j)=X(i)*H(j);
end
end
y=zeros(1,n);
for k=1:n
for i=1:length(X)
for j=1:length(H)
if (i+j==k+1)
y(k)=y(k)+w(i,j);
end
end
end
end
figure
subplot(3,1,1)
stem(n1,x);
xlabel('time index(n)');
ylabel('x[n]');
title('input sequence 1');
subplot(3,1,2);
stem(n2,h);
xlabel('time index(n)');
ylabel('h[n]');
title('input sequence 2');
subplot(3,1,3);
stem(n3,y);
xlabel('time index(n)');
ylabel('x[n]*h[n]');
title('Convolved signal');

PROCEDURE:
Type the above code in Matlab, simulate the same and get the output.
SIMULATION RESULTS:

OBSERVATION:
The length of the output sequence in linear convolution is equal to the
sum of the lengths of the input sequences minus one. For example, if the
first input sequence has N samples and the second input sequence has
M samples, then the output sequence will have N + M - 1 samples.

CALCULATION:
In linear convolution, each sample in the output sequence is obtained by
summing the products of corresponding samples from the input
sequences.

CONCLUDING REMARKS:
The linear convolution of two discrete time signals have been calculated
and the same has been plotted
EXPERIMENT-2B
Correlation of discrete time signals

AIM:

To perform correlation of discrete time signals.

SOFTWARE REQUIRED:
Matlab software

THEORY:
The correlation of discrete-time signals is a measure of similarity or
relationship between two signals. It is often used in signal processing
and communication systems to analyse and compare signals.

r
The cross-correlation of x[n] and y[n], denoted as xy[n], is given by the
following expression:

rxy[n] = ∑ (x[k] * y[k - n])
k = -∞

MATLAB SOURCE CODE:


l1=input('Enter the lower time index of first sequence');
u1=input('Enter the upper time index of first sequence');
n1=l1:1:u1;
x=input('Enter the sample values for each n1');
l2=input('Enter the lower time index of second sequence');
u2=input('Enter the upper time index of second sequence');
n2=l2:1:u2;
h=input('Enter the sample values for each n2');
n3=(l1-u2):(u1-l2);
p=fliplr(h);
L=length(x);
M=length(p);
n=L+M-1;
if L>=M
P=[p zeros(1,L-M)];
X=x;
else
X=[x zeros(1,M-L)];
P=p;
end
for i=1:length(X)
for j=1:length(P)
w(i,j)=X(i)*P(j);
end
end
y=zeros(1,n);
for k=1:n
for i=1:length(X)
for j=1:length(P)
if (i+j==k+1)
y(k)=y(k)+w(i,j);
end
end
end
end
figure
subplot(4,1,1)
stem(n1,x);
xlabel('time index(n)');
ylabel('x[n]');
title('input sequence 1');
subplot(4,1,2);
stem(n2,h);
xlabel('time index(n)');
ylabel('h[n]');
title('input sequence 2');
subplot(4,1,3);
stem(n2,p);
xlabel('time index(n)');
ylabel('p[n]=h[-n]');
title('time reversed input sequence 2');
subplot(4,1,4);
stem(n3,y);
xlabel('time index(n)');
ylabel('x[n]*h[-n]');
title('Correlated signal');
PROCEDURE:
Type the above code in Matlab, simulate the same and get the output.

SIMULATION RESULTS:

OBSERVATION:
In the case of cross-correlation, the correlation function is
generally asymmetric. If x[n] is cross-correlated with y[n], the
correlation function will not be the same as when y[n] is cross-
correlated with x[n]. The position of the peak will be different,
indicating the direction of the relationship between the signals.

CALCULATION:
Step-by-step process to calculate the cross-correlation:
 Choose a specific value of n, the time lag.
 For that value of n, perform the following steps:
 Initialize a variable, let's call it sum, to 0.
 Iterate over all possible values of k.
 Inside the iteration:
 Multiply x[k] with y[k - n].
 Add the result to the sum.

r
 After the iteration, assign the value of sum to xy[n].

CONCLUDING REMARKS:
The cross-correlation of two discrete time signals have been calculated
and the same has been plotted.

You might also like