How do you calculate a correlation function in MATLAB?
古いコメントを表示
I am trying to calculate the correlation function given by
where I sum over all i ("part" in the following). Do I just choose time zero arbitrarily as t1 like in the following? I am not sure how to do this. vbar is calculated separately and is just a constant here..
for t1 = 1:tmax
for t2 = t1:tmax
for part = 1:tot_part
a0(t2-t1,part) = a0(t2-t1,part) + (v(t1,part)+vbar)*(v(t2,part)+vbar)
n0(t1,part) = (v(t1,part)+vbar) + 1
end
end
end
for t = 0:tmax-1
for part = 1:tot_part
corr0(t) = corr0(t) + a0(t,part)/n0(t,part)
end
end
回答 (1 件)
Hiro Yoshino
2022 年 6 月 1 日
0 投票
6 件のコメント
Hiro Yoshino
2022 年 6 月 1 日
Just a few lines of code server for this problem.
L'O.G.
2022 年 6 月 1 日
You should take a look at the documentation carefully. I would do it like:
x = rand(10,1)
[r,lag] = xcorr(x)
stem(lag,r/var(x))
Hiro Yoshino
2022 年 6 月 1 日
Does this make sense to you?
L'O.G.
2022 年 6 月 1 日
Hiro Yoshino
2022 年 6 月 2 日
Totally understood. When I was in school, I didn't realize there had been this function for ages and crafted my own from scratch but good thing about MATLAB is that you can avoid "re-inventing wheels".
カテゴリ
ヘルプ センター および File Exchange で Correlation and Convolution についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
