フィルターのクリア

Help composing Personal autocorrelation function

3 ビュー (過去 30 日間)
Ishmael
Ishmael 2012 年 4 月 2 日
The following is my code for calculating the autocorrelation:
function [Rxx]= myauto(x)
% This function Estimates the autocorrelation of the sequence of
% random variables given in x as: Rxx(1), Rxx(2),…,Rxx(N),
% where N is Number of samples in x.
N=length(x);
Rxx=zeros(1,N);
for m=1: N+1
for n=1: N-m+1
Rxx(m)=Rxx(m)+x(n)*x(n+m-1);
end;
end;
plot(Rxx)
The challenge, however, is that after I plot the values I get from my autocorrelation function (i.e Rxx), only half the points that I would otherwise get with the Matlab function xcorr are produced. For example, If I were to plot the autocorrelation of sin(x) [for x from 0 to 2pi], my function would only produce half of the curve that the Matlab function would.
I, thus, need help adjusting my function so that I am able to replicate the results that I get using the Matlab xcorr function.
Thanks.
  1 件のコメント
Daniel Shub
Daniel Shub 2012 年 4 月 4 日
It looks like you are only using positive lags. You need to include negative lags. Of course this causes "problems" with MATLAB indexing ...

サインインしてコメントする。

採用された回答

Rick Rosson
Rick Rosson 2012 年 4 月 5 日
Since we know in advance that the autocorrelation is an even function of time lag, you can simply invert the result and concatenate:
Rxx = [ fliplr(Rxx(2:end)) Rxx ];
HTH.
Rick
  2 件のコメント
Daniel Shub
Daniel Shub 2012 年 4 月 5 日
Doesn't this add 0 lag twice?
Ishmael
Ishmael 2012 年 4 月 5 日
Thanks for your help, Rick, and your input, Daniel. Rick's suggestion fixed my issue.
I am also looking to develop a crosscorelation function for the same project. Are there any suggestions as to how to further modify my code?
Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by