# How do you calculate a correlation function in MATLAB?

조회 수: 2 (최근 30일)
L'O.G. 2022년 5월 31일
댓글: Hiro Yoshino 2022년 6월 2일
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일
If you want to calculate "auto correlation", see xcorr.
You may need to devide the result by var.
##### 댓글 수: 6이전 댓글 4개 표시이전 댓글 4개 숨기기
L'O.G. 2022년 6월 1일
Thanks, yes, it would nice though if it would be possible to understand this without resorting first things first to the xcorr function, which is why I had the clunky for loops in my post.
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".

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by