Lab 12 PDF
Lab 12 PDF
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;