MATLAB自相关矩阵计算方法

clear;
close all;
clc;
N = 1000;
n = 0:N-1;
noise = (randn(1,N)+1j*randn(1,N))/sqrt(2);
signal1 = exp(1j*(0.5*pi*n+2*pi*rand));
signal2 = exp(1j*(-0.3*pi*n+2*pi*rand));
signal = signal1 + signal2 + noise;
%-----------------------------------自相关矩阵计算------------------------------------
M = 8;  % M = 阶数-1
r1 = xcorr(signal,M-1,'biased'); %计算相关
%自相关矩阵计算方法1
R1 = zeros(M,M);
for i=1:M
    R1(i,:) = r1(M+1-i:-i+2*M);
end
%自相关矩阵计算方法2(最简单)
r1 = r1(M:end);
R2 = toeplitz(r1);
%自相关矩阵计算方法3(定义法)
U = zeros(M,1007);
for i = 1:M
    u = [zeros(1,i-1),signal,zeros(1,M-i)];
    U(i,:) = u;
end
R3 = (1/N)*(U*U');

三种方法均可计算自相关矩阵。

你可能感兴趣的:(matlab,开发语言)