Cross-Correlation of Two Exponential Sequences

Compute and plot the cross-correlation of two 16-sample exponential sequences, xa=0.84n and xb=0.92n, with n0.

N = 16;
n = 0:N-1;

a = 0.84;
b = 0.92;

xa = a.^n;
xb = b.^n;

r = xcorr(xa,xb);

stem(-(N-1):(N-1),r)

Determine c analytically to check the correctness of the result. Use a larger sample rate to simulate a continuous situation. The cross-correlation function of the sequences xa(n)=an and xb(n)=bn for n0, with 0<a,b<1, is

cab(n)=1-(ab)N-|n|1-ab×{an,n>0, 1,n=0b-n,n<0.

fs = 10;
nn = -(N-1):1/fs:(N-1);

cn = (1 - (a*b).^(N-abs(nn)))/(1 - a*b) .* ...
     (a.^nn.*(nn>0) + (nn==0) + b.^-(nn).*(nn<0));

Plot the sequences on the same figure.

hold on
plot(nn,cn)

xlabel('Lag')
legend('xcorr','Analytic')

Verify that switching the order of the operands reverses the sequence.

figure

stem(-(N-1):(N-1),xcorr(xb,xa))

hold on
stem(-(N-1):(N-1),fliplr(r),'--*')

xlabel('Lag')
legend('xcorr(x_b,x_a)','fliplr(xcorr(x_a,x_b))')

Generate the 20-sample exponential sequence xc=0.77n. Compute and plot its cross-correlations with xa and xb. Output the lags to make the plotting easier. xcorr appends zeros at the end of the shorter sequence to match the length of the longer one.

xc = 0.77.^(0:20-1);

[xca,la] = xcorr(xa,xc);
[xcb,lb] = xcorr(xb,xc);

figure

subplot(2,1,1)
stem(la,xca)
subplot(2,1,2)
stem(lb,xcb)
xlabel('Lag')

See Also

Functions