0% found this document useful (0 votes)
62 views2 pages

Lab 12 PDF

This document contains MATLAB code to calculate the cross-correlation between two signals, x and y. It generates the two signals, calculates their cross-correlation using the xcorr function, and identifies the lag where the maximum correlation occurs. Finally, it plots the original signals and the cross-correlation function.

Uploaded by

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

Lab 12 PDF

This document contains MATLAB code to calculate the cross-correlation between two signals, x and y. It generates the two signals, calculates their cross-correlation using the xcorr function, and identifies the lag where the maximum correlation occurs. Finally, it plots the original signals and the cross-correlation function.

Uploaded by

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

LAB 12

clear all;
close all;
clc;
n=[0:9];
ph1=0;
ph2=0;
x=sin(2*pi*0.1*n + ph1);
org_x=1;
nx=[0:length(x)-1]-org_x + 1;
y=sin(2*pi*0.1*n + ph2);
org_y=1;
ny = [0 : length(y) - 1] - org_y +1;
rxy=xcorr(x,y);
nr=[nx(1) - ny(end): nx(end) - ny(1)];
[maxR indR] = max(rxy);
disp(['the correlation at lag zero is: '
num2str(rxy(find(nr==0))) '.']);
disp(['the max correlation at lag is: '
num2str(nr(indR)) '.']);
figure, subplot(3,1,1),
stem(nx,x);
xlabel('time');ylabel('amplitude');xlim([nx(1)-1
nx(end)+1]);
title('signalx(n)');
grid;
subplot(3,1,2),
stem(ny,y);
xlabel('time');ylabel('amplitude');xlim([ny(1)-1
ny(end)+1]);
title('signal y(n)');
grid;
subplot(3,1,3),
stem(nr,rxy);
xlabel('time');ylabel('amplitude');xlim([nr(1)-1
nr(end)+1]);
title('cross correlation');
grid;

You might also like