2013-11-01 27 views
0

我想自动关联一个随机噪声矢量与任何内置的MATLAB函数。是给予如何创建没有任何内置函数的自相关函数,如xcorr

我的自相关方程为:

Rxx[L] = ∑ from n = 1 to N-1 [x(n)*x(n+L)] 

L = [0:200] 

我已经写了下面的代码,但plotRxx VS Lplot是不是我期待的。 我期待我的阴谋从或L = 1开始在一定的最大值,因为MATLAB开始在1的指数。然后指数下降和饱和在零分钟。


clc 
clear all 

randn('seed',2496132); 
n = randn(1,1024); 

upperbound = numel(n)-1; 

for L = 1:200 

    for j = 1 : upperbound 

      n1(j) = n(j)+L; 
      Rxx(j) = (n(j)*n1(j));    

    end 

    Rxx_sum(L) = sum(Rxx); 
    Rxx = 0; 

end 

plot([1:200], Rxx_sum) 

回答

1

您在内环错误:你需要使用n1(j) = n(j+L);代替n1(j) = n(j)+L;。例如。您需要添加L来索引值。

第二个错误如下:如果你想使用upperbound = numel(n)-1比你应该使用L等于0或1只。例如。你外环将

for L = 0:1 
    ... 
    Rxx_sum(L+1) = sum(Rxx); 
    ... 

取而代之的是你也是正确的上界值可以:

upperbound = numel(n) - maxL; 

maxL是将在下一循环使用升最大值。

另一个提示:如果用标量产品替换内环,可以提高计算速度,例如,

for L = 1:200 
    Rxx_sum(L) = n(1:upperbound) * n(1+L:upperbound+L)';  
end 
+0

这不正是我一直在寻找但它有助于引导我走上正确的道路。非常感谢Danil –

0

我最终在上面的代码的帮助下修复了我的脚本。

CLC

清楚所有

randn( '种子',2496132);

z = randn(1,1024);

n = [z零(1,200)];

upperbound = numel(z)-1;

为L = 0:200

for j = 1 : upperbound 

    Rxx(j) = (n(j)*n(j+L));    

>end 

Rxx_sum(L+1) = sum(Rxx); 
Rxx = 0; 

图([0:200],Rxx_sum)

相关问题