% xcorr is cross-correlation in MATLAB
% Goes along with Section 2.10 in Oppenheim & Schafer
N = 100000;

x = randn(N, 1);

figure(1);
plot(x);

[phi_x, lags] = xcorr(x,x);
figure(2);
stem(lags, phi_x);
xlim([-1 15]);


h = [1 2 3 4 5 6 7 8 9 10];


y = conv(h, x);

mean(x)
sum(h)
mean(y)

figure(3);
plot(y)

figure(4);
[phi_y, lags] = xcorr(y, y);
stem(lags, phi_y);
xlim([-1 15]);

figure(5);
[phi_yx, lags] = xcorr(y,x);
stem(lags, phi_yx);
xlim([-1 15]);

figure(6);
c_hh = conv(h, fliplr(h));

stem(fftshift(conv(c_hh, phi_x)));
xlim([0 15]);
