EXERCISE: 6 Auto correlation and cross correlation
Date: 08.09.2025
1. Simulate two signals given by X(t)= cos(2*pi*5*t) and a white noise signal.
Plot their autocorrelation functions and compare the plots. What is your
inference.
AIM:
To simulate a deterministic signal X(t)=cos(2π5t)X(t) = \cos(2\pi
5t)X(t)=cos(2π5t) and a white noise signal, compute and plot their
autocorrelation functions, and compare the characteristics of periodic and
random signals.
PROCEDURE:
clc; clear; close all;
fs = 1000;
t = 0:1/fs:1;
x1 = cos(2*pi*5*t);
x2 = randn(size(t));
[Rx1, lags1] = xcorr(x1, 'normalized');
[Rx2, lags2] = xcorr(x2, 'normalized');
figure;
subplot(2,1,1);
plot(lags1/fs, Rx1, 'b');
title('Autocorrelation of cos(2π5t)');
xlabel('Lag (s)'); ylabel('ACF');
grid on;
subplot(2,1,2);
plot(lags2/fs, Rx2, 'r');
title('Autocorrelation of White Noise');
xlabel('Lag (s)'); ylabel('ACF');
grid on;
OUTPUT:
2. Compute the cross correlation between a random process given by
X(t) = sin(2*pi*5*t) and a test signal. What do you infer from the
plot of the cross correlation?
AIM:
To compute and plot the cross-correlation between a sinusoidal random
process X(t)=sin(2π5t)X(t) = \sin(2\pi 5t)X(t)=sin(2π5t) and a test
signal, and to analyze the phase relationship between the two signals.
PROCEDURE:
x = sin(2*pi*5*t);
y = cos(2*pi*5*t);
[Rxy, lags] = xcorr(x, y, 'normalized');
figure;
plot(lags/fs, Rxy, 'm');
title('Cross-correlation between sin(2π5t) and cos(2π5t)');
xlabel('Lag (s)'); ylabel('CCF'); grid on;
OUTPUT:
3. Compute the auto correlation between a auto regressive process of
order 3 and auto regressive process of order 5. Also compute and
plot the cross-correlation function. What is your observation about
the order of the process?
AIM:
To generate and simulate an autoregressive process of order 3 and
another of order 5, compute their autocorrelation functions, and
evaluate the cross-correlation between them in order to study the
effect of process order on correlation.
PROCEDURE:
clc; clear; close all;
rng(0);
N = 1000;
burn = 200;
total = N + burn;
maxlag = 50;
phi3 = [0.75, -0.5, 0.3];
a3 = [1, -phi3];
phi5 = [0.5, -0.4, 0.3, -0.2, 0.1];
a5 = [1, -phi5];
e1 = randn(total,1);
e2 = randn(total,1);
x_full3 = filter(1, a3, e1);
x_ar3 = x_full3(burn+1:end);
x_full5 = filter(1, a5, e2);
x_ar5 = x_full5(burn+1:end);
[Rx_ar3, lags_ar3] = xcorr(x_ar3, maxlag, 'coeff');
[Rx_ar5, lags_ar5] = xcorr(x_ar5, maxlag, 'coeff');
[Rcross_ar, lags_cross_ar] = xcorr(x_ar3, x_ar5, maxlag, 'coeff');
figure('Name','Q3: AR(3) vs AR(5)','NumberTitle','off','Position',[100 100
700 800]);
subplot(3,1,1);
stem(lags_ar3, Rx_ar3, 'filled'); grid on;
title('ACF of AR(3)'); xlabel('Lag'); ylabel('ACF');
subplot(3,1,2);
stem(lags_ar5, Rx_ar5, 'filled'); grid on;
title('ACF of AR(5)'); xlabel('Lag'); ylabel('ACF');
subplot(3,1,3);
stem(lags_cross_ar, Rcross_ar, 'filled'); grid on;
title('Cross-correlation: AR(3) vs AR(5)'); xlabel('Lag'); ylabel('CCF');
fprintf('\nQ3 Observations:\n- AR processes display slowly decaying
ACF (not a hard cutoff).\n- Higher-order AR (p=5) typically shows longer
memory / slower decay than AR(3).\n- Cross-correlation shows how
similar the two AR realizations are (short-range peaks).\n');
OUTPUT:
4. Compute the auto correlation between a Moving average process of
order 4 and Moving average process of order 6. Also compute and
plot the cross-correlation function. What is your observation about
the order of the process?
AIM:
To generate and simulate moving average processes of order 4 and
order 6, compute their autocorrelation functions, and evaluate the
cross-correlation between them in order to observe the cutoff property
of MA processes.
PROCEDURE:
clc; clear; close all;
rng(1);
N = 1000;
burn = 200;
total = N + burn;
maxlag = 20;
theta4 = [0.6, -0.4, 0.3, 0.2];
b4 = [1, theta4];
theta6 = [0.5, -0.3, 0.25, 0.15, -0.1, 0.05];
b6 = [1, theta6];
e1 = randn(total,1);
e2 = randn(total,1);
x_ma4_full = filter(b4, 1, e1);
x_ma6_full = filter(b6, 1, e2);
x_ma4 = x_ma4_full(burn+1:end);
x_ma6 = x_ma6_full(burn+1:end);
[Rx_ma4, lags_ma4] = xcorr(x_ma4, maxlag, 'coeff');
[Rx_ma6, lags_ma6] = xcorr(x_ma6, maxlag, 'coeff');
[Rcross_ma, lags_cross_ma] = xcorr(x_ma4, x_ma6, maxlag, 'coeff');
figure('Name','Q4: MA(4) vs MA(6)','NumberTitle','off','Position',[100
100 700 800]);
subplot(3,1,1);
stem(lags_ma4, Rx_ma4, 'filled');
title('ACF of MA(4) process'); xlabel('Lag'); ylabel('ACF'); grid on;
subplot(3,1,2);
stem(lags_ma6, Rx_ma6, 'filled');
title('ACF of MA(6) process'); xlabel('Lag'); ylabel('ACF'); grid on;
subplot(3,1,3);
stem(lags_cross_ma, Rcross_ma, 'filled');
title('Cross-correlation: MA(4) vs MA(6)'); xlabel('Lag'); ylabel('CCF');
grid on;
fprintf('\nQ4 Observations:\n');
fprintf('- MA(q) processes have ACF that cuts off after lag q.\n');
fprintf('- MA(4) → ACF becomes ~0 beyond lag 4.\n');
fprintf('- MA(6) → ACF becomes ~0 beyond lag 6.\n');
fprintf('- Cross-correlation shows short-range dependence only.\n');
OUTPUT:
5. Generate two random walks X(t) and Y(t). Plot their acfs. Let Z(t) =
X(t) + Y(t). Plot the acf of Z(t). Compute the cross correlation
between X(t) and Z(t). What is your conclusion?
AIM:
To generate two independent random walks X(t)X(t)X(t) and Y(t)Y(t)Y(t),
compute and plot their autocorrelation functions, form a combined
process Z(t)=X(t)+Y(t)Z(t) = X(t) + Y(t)Z(t)=X(t)+Y(t), and analyze the
autocorrelation of Z(t)Z(t)Z(t) and the cross-correlation between
X(t)X(t)X(t) and Z(t)Z(t)Z(t).
PROCEDURE:
rw_len = 1000;
X = cumsum(randn(rw_len,1));
Y = cumsum(randn(rw_len,1));
Z = X + Y;
[Rx, lagsX] = xcorr(X,'normalized');
[Ry, lagsY] = xcorr(Y,'normalized');
[Rz, lagsZ] = xcorr(Z,'normalized');
[Rxz, lagsXZ] = xcorr(X,Z,'normalized');
figure;
subplot(4,1,1);
plot(lagsX, Rx); title('ACF of X(t)'); grid on;
subplot(4,1,2);
plot(lagsY, Ry); title('ACF of Y(t)'); grid on;
subplot(4,1,3);
plot(lagsZ, Rz); title('ACF of Z(t) = X(t)+Y(t)'); grid on;
subplot(4,1,4);
plot(lagsXZ, Rxz); title('Cross-correlation X(t) vs Z(t)'); grid on;
OUTPUT:
RESULT:
Thus the output ares verified using matlab.