View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Autocorrelation Function (ACF)

4.8 | 16 ratings Rate this file 262 Downloads (last 30 days) File Size: 2.01 KB File ID: #30540 Version: 1.0
image thumbnail

Autocorrelation Function (ACF)


Calvin Price (view profile)


Computes ACF for a given series and plots correlogram.

| Watch this File

File Information

Computes ACF for a given series. Returns a vector of autocorrelations through lag p. Also produces bar graph of autocorrelations, with rejection region bands for testing (under white noise assumption) each autocorrelation = 0.

Example: >> myacf = acf(y,12)

Does not require any toolboxes.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
29 Jan 2017 Johan Portström

08 Nov 2016 YangQuan Chen

Thank u, very useful.

25 Sep 2016 chen tai yu


Comment only
04 Jul 2016 Andres Kiani

05 Jun 2016 Robin Szeto

Simple and nice!

03 Mar 2016 Nakul Bansal

brilliant. Just one thing ... if you could make the bars thinner

11 Dec 2014 harry

harry (view profile)

thanks for your share, very useful.

23 Feb 2014 Alan

Alan (view profile)

Thanks, this saved me a lot of time.

30 May 2013 Fatima

Fatima (view profile)

The code solved my problem after got confused with several other codes although I m so biginner and I had to be paitint to get it.
Thank you

27 Apr 2013 Martin

Martin (view profile)

18 Jan 2013 H.Muhammed BIYIKLI

08 May 2012 Dmitry

Dmitry (view profile)

Hey Calvin, ACFs produced by your code are biased towards zero...

The reason for that is that the first k elements in cross_sum (variable of the sub-function) are always zero. Also, dimensions of cross_sum after the loop in lines 104-106 are always Nx1. In large sample the bias is small but in small samples it might be sensible.

Given that matlab is very bad at handling loops it is better to avoid them altogether if possible. I adjusted your code by removing the sub-function completely, "global" attributes for N and ybar (lines 46 and 48) and substituting loop in lines 52-54 by

for i = 1:p
yvar = (y-ybar)'*(y-ybar) ;
ta(i) = (cross_sum / yvar)*(N/(N-i)) ;

Hope that helps everyone

06 Dec 2011 Martin Dimkovski

21 Nov 2011 Cristhiano Moreno

Thank you.

How do you calculate the Bartlett bands ?

16 Nov 2011 MiguelMauricio

Very useful, clear and easy to follow. Thank you

11 Aug 2011 Steven White

It did what I wanted it to do!

It might be nice to include a more meaningful example, rather than just an ACF of some random data.

03 Aug 2011 Ana

Ana (view profile)

Contact us