0% found this document useful (0 votes)
14 views3 pages

Lecture 6

The document contains MATLAB code for performing autocorrelation and cross-correlation on input sequences. It includes functions for signal shifting, folding, and convolution, as well as visualizations of the input sequence and the resulting correlations. The code allows users to input a sequence and computes both autocorrelation and cross-correlation using convolution methods.

Uploaded by

mumtahena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Lecture 6

The document contains MATLAB code for performing autocorrelation and cross-correlation on input sequences. It includes functions for signal shifting, folding, and convolution, as well as visualizations of the input sequence and the resulting correlations. The code allows users to input a sequence and computes both autocorrelation and cross-correlation using convolution methods.

Uploaded by

mumtahena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment: Correlation

Code: Autocorrelation
clc;
close all;
clear all;
% two input sequences
x = input ('enter input')
subplot(1,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('Input Sequence');
% auto correlation of input sequence
z=xcorr(x,x);
disp('The values of z are =');disp(z);
subplot(1,2,2);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');

command window
Output:

Code: cross correlation by convolution


clc;
clear all;
close all;
function [y,n] = sigshift(x,n1,n0)
n=n1+n0;
y=x;
end;
function[y,n]=sigfold(x,m)
n=-fliplr(m);
y=fliplr(x);
end;
function [y,k] = convolution_sum(nx, x, nh, h)
kmin = min(nx)+min(nh);
kmax = max(nx)+max(nh); % same as the kmin
k = kmin:kmax; % index vector k
y = conv(x,h); % convolution of x and h
end
nx = 0:15; % defining time index
x = 0.05*nx.^2; %defining a signal n
% y = x[n−5]
n0 = 5;
[y, ny] = sigshift(x, nx, n0);
% calculating cross−correlation using convolution
% rxy = y[n]*x[−n]
[x, nx] = sigfold(x, nx);
[rxy, nxy] = convolution_sum(nx, x, ny, y);
stem(nxy, rxy);
Output:

You might also like