Matlab:无法执行逆运算 - 如何创建非奇异方阵

时间:2014-11-26 00:29:01

标签: matlab time-series covariance correlation matrix-inverse

我正在尝试Matrix操作。数据是时间序列模型 - 自回归模型,AR(2),其中由变量p =2表示的模型顺序Y由白高斯噪声epsilon激发。我对概念性问题感到困惑,我将很感激你的答案。该代码在将1个采样时间延迟矢量Y与1个采样时间延迟矢量的转置相乘之后计算自相关矩阵。相关的通用公式为E(Y*Y')。在这种情况下,我需要做E(Y(1:end)*Y(1:end)')。如果以这种方式完成,答案就是标量。但是,根据Walter Roberts mathematical expectation的回复,我能够获得9 by 9 matrix。但是,我没有得到非奇异矩阵。

如何为自相关矩阵创建奇异矩阵,以便计算逆?请帮忙

代码:

clc;
clear all;
 var_eps = 1;
    epsilon = sqrt(var_eps)*randn(5000,1); % Gaussian signal exciting the AR model

   Y(1) = 0.0;
    Y(2) = 0.0;
    for n= 3:5000
    Y(n)=  0.1950*Y(n-1) -0.9500*Y(n-2)+ epsilon(n); %AR(2) model
    end

  y_tminus1 = Y(1:end-1).';
    mult = y_tminus1*y_tminus1';  %This creates a square matrix
    autocorr = xcorr2(mult);  %To perform autocorrelation of 1 sampled lag time series with itself(1 sampled lag)
  inverse_autocorr = inv(autocorr);  **%PROBLEM**        


%Warning: Matrix is singular to working precision. 
  trace_inv=trace(inverse_autocorr);

更新:我正面临这个问题,因为我试图在方程(20)的表达式和方程(24){R}中img1实现矩阵的项。 img2

更新:12月1日

在此代码中,问题,变量的分析形式

CRB_LHS = (b_transpose_b/N)*tr(inv(E[y(t-1)y(t-1)']))

CRB_RHS = sigma2_v*tr(inv(sum_t =1 to N E[y(t-1)y(t-1)']))

其中 y(t-1) =

[y(t-1), y(t-2),..,y(t-p)]'

CRB_LHS根据论文的方程(19)计算

`Y_ARMA(n)=  0.1950*Y_ARMA(n-1)- 0.1950*Y_ARMA(n-2) + b*x_gauss(n);` where

 x_gauss = N(0,1)

CRB_RHS根据公式(1)

计算得出

Y_AR(n)= 0.1950 * Y_AR(n-1)-0.9500 * Y_AR(n-2)+ x_chaos(n);

x_chaos(n)= f(x(n-1),x(n-2),...,x(n-d)); d = 2

我在方程(19)的ARMA模型中假设了白噪声的系数b = 1

对于每个SNR级别,snrbd = -3:1:2我模拟M个时间序列(M个独立运行)。关于实施有两个疑点:(1)对于方程(25)的RHS,在代码中,期望是针对独立运行的(根据答案中的建议,只要我理解正确) - 表达式表明总和取自所有数据点&对(t-1)的M个样本的期望。实施这一点令人困惑。 (2)代码因反转而抛出错误。无法解决这个问题。

每个snr的结果应为CRB_LHS > CRB_RHS

clc;
clear all;
N = 10;
M = 100;  % number of independent runs over which the 

  snrdb = -3:1:2;
for snr_levels = 1:length(snrdb)



for monte_carlo = 1: M
     x_gauss = randn(1,N);
     x_chaos(1) = rand();
% generate the chaotic code
    for i =1 : N
        x_chaos(i+1) = 4*x_chaos(i)*(1-x_chaos(i));
    end

    x_chaos = x_chaos-mean(x_chaos);
    Y_AR(1) = 0.0;
    Y_AR(2) = 0.0;

   Y_ARMA(1) = 0.0;
    Y_ARMA(2) = 0.0;
    for n= 3:N
    Y_ARMA(n)=  0.1950*Y_ARMA(n-1)- 0.1950*Y_ARMA(n-2) + x_gauss(n); %Eq(19) model
    Y_AR(n) =   0.1950*Y_AR(n-1) -0.9500*Y_AR(n-2)  + x_chaos(n); %Eq(1)
    end
    % signalPower_Y_AR = var(Y_AR);
 signalPower_Y_AR = 1;

    sigma2_v = signalPower_Y_AR .*(10^(-snrdb(snr_levels))) ;
    v = sqrt(sigma2_v)*randn(1,length(Y_AR));
    z = Y_AR + v;  %Eq(3)

Y_LHS = Y_ARMA(end-2:end-1).';
Y_RHS = z(end-2:end-1).';

A1(:,monte_carlo) = Y_LHS;
B1(monte_carlo,:) = Y_LHS.';

A2(:,monte_carlo) = Y_RHS;
B2(monte_carlo,:) = Y_RHS.';
end


dimension = length(Y_LHS);
sum_of_products_LHS = zeros(dimension,dimension);
sum_prod_RHS = zeros(dimension,dimension);

for runs = 1:M
A = A1(:,runs);
B = B1(runs,:);
mult_LHS = A*B;

C = A2(:,runs);
D = B2(runs,:);
mult_RHS = C*D;

sum_of_products_LHS = sum_of_products_LHS+ mult_LHS;
sum_of_products_RHS = sum_prod_RHS + mult_RHS;
end 

  b_transpose_b = 1;

Expectation_LHS = mean(sum_of_products_LHS);
% Inverse_LHS = inv(Expectation_LHS);
% trace_LHS = tr(Inverse_LHS);

Expectation_RHS = mean(sum_of_products_RHS);

% Inverse_RHS = inv(Expectation_RHS);
% trace_RHS = tr(Inverse_RHS);
%MANUALLY MAKING A SQUARE MATRIX
size_Inverse = 7;
InverseMatrix_LHS = eye(size_Inverse,size_Inverse);
InverseMatrix_RHS = eye(size_Inverse,size_Inverse);

for i = 1:size_Inverse
    InverseMatrix_LHS(i:size_Inverse,i) = Expectation_LHS(1:size_Inverse-i+1);
    InverseMatrix_LHS(i,i:size_Inverse) = Expectation_LHS(1:size_Inverse-i+1);

    InverseMatrix_RHS(i:size_Inverse,i) = Expectation_RHS(1:size_Inverse-i+1);
    InverseMatrix_RHS(i,i:size_Inverse) = Expectation_RHS(1:size_Inverse-i+1);

end
  trace_LHS = tr(InverseMatrix_LHS);
  CRLB_RHS(snr_levels)=  (b_transpose_b/N).*trace_RHS;

  trace_RHS = tr(InverseMatrix_RHS);
  CRLB_RHS(snr_levels)= sigma2_v*trace_RHS;

 end

1 个答案:

答案 0 :(得分:0)

对于p = 2,y_tminus1的表达式应该是(参见论文中方程1之后的表达式)

y_tminus1 = Y(end-2:end-1).' 

你的声音很好。对于Eq。 20你需要期待E(mult)。为此,您需要生成多个路径并对它们取平均值。对于方程式的RHS。 25,你需要在ARMA过程的每一步使用y_tminus1,对相应的多矩阵求和,对整体进行预期,然后才进行反演。也许,尝试沿着这些方向调整代码,我会纠正它。