PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

504 Practical MATLAB® Applications for Engineers


ANALYTICAL Solution

R 11 (0) = [0 1 2 1 2 0 1 0]. * [0 1 2 1 2 0 1 0] = [0 1 4 1 4 0 1 0] = 11


R 11 (1) = [0 1 2 1 2 0 1 0]. * [1 2 1 2 0 1 0 0] = [0 2 2 2 0 0 0 0] = 6


R 11 (2) = [0 1 2 1 2 0 1 0]. * [2 1 2 0 1 0 0 0] = [0 1 4 0 2 0 0 0] = 7


R 12 (0) = [0 1 2 1 2 0 1 0]. * [0 1 2 3 4 5 6 7] = [0 1 4 3 8 0 6 0] = 22


R 12 (1) = [0 1 2 1 2 0 1 0]. * [1 2 3 4 5 6 7 0] = [0 2 6 4 10 0 7 0] = 29


R 12 (2) = [0 1 2 1 2 0 1 0]. * [2 3 4 5 6 7 0 0] = [0 3 8 5 12 0 0 0] = 28


MATLAB Solution
% Script file: auto _ cross
fn1=[0 1 2 1 2 0 1 0]; fn2 = [0 1 2 3 4 5 6 7];
auto _ corr=xcorr(fn1);cross _ corr = xcorr(fn1,fn2);cross _ corrx =
xcorr(fn2,fn1);
disp(‘******************* R E S U L T S ***************************’)
disp(‘The auto-correlation coefficients of f1(n)are:’)
auto _ corr
disp(‘The cross-correlation coefficients of f1(n) with f2(n) are:’)
cross _ corr
disp(‘***************************************************************’)
n=-7:7;
subplot(3,1,1)
bar(n,auto _ corr)
title(‘Auto-correlation of f1(n)’)
xlabel(‘time index n’)
ylabel(‘Amplitude’)
subplot(3,1,2)
bar(n,cross _ corr)
title(‘Cross-correlation of f1(n) with f2(n)’)
xlabel(‘time index n’); ylabel(‘Amplitude’)
Subplot(3,1,3)
bar(n,cross _ corrx)
title(‘Cross-correlation of f2(n) with f1(n)’)
xlabel(‘time index n’); ylabel(‘Amplitude’)
********************** R E S U L T S *************************
The auto-correlation coefficients of f1(n)are:
auto _ corr =
Columns 1 through 8
-0.0000 -0.0000 1.0000 2.0000 3.0000 7.0000 6.0000 11.0000
Columns 9 through 15
6.0000 7.0000 3.0000 2.0000 1.0000 -0.0000 -0.0000
The cross-correlation coefficients of f1(n) with f2(n) are:
cross _ corr =
Columns 1 through 8
-0.0000 7.0000 20.0000 24.0000 34.0000 28.0000 29.0000 22.0000
Columns 9 through 15
15.0000 9.0000 5.0000 2.0000 1.0000 -0.0000 0
****************************************************************
Free download pdf