Functions > Signal Processing > Time Series Analysis > Example: Correlation and Partial Autocorrelation
Example: Correlation and Partial Autocorrelation
Use the lcorr and plcorr functions to calculate the lagged sample correlation and partial autocorrelation, respectively.
For definitions and examples see Time Series Analysis by Bowerman and O'Connell (Duxbury) and Forecasting Economic Time Series by Granger and Newbold (Academic Press).
lcorr
The lcorr function assumes that the two inputs have the same length.
Suppose an input signal in the form of a windowed sine wave pulse. This pulse might be used, for example, as a sonar test signal. The return signal travels some distance, bounces off the object under investigation, and returns to the source, lagged (because of the travel time), attenuated, and noisy. By correlating the received signal with the test signal, it is possible to determine the lag, and hence the distance to the object under test.
1. Define the number of sample points.
2. Define the pulse length.
3. Use the sin function to define the signal.
4. Use the hanning function to define the windowing function.
The width of window is 200
The length of vector x is 1000 elements long
5. Plot input signal x, and use a vertical marker to show the pulse length line.
6. Use the rnd function to define the random noise, then define the lag and attenuation of the return signal.
7. Define and plot the return signal along with the input signal.
If the lag time was not known, such as when signals are measured and not simulated, then it would be difficult to say where the return pulse was in the noisy plot above.
At or around lag time, expect the linear correlation of x and y to be a maximum compared with other correlated samples, since the correlation slides one signal across another, multiplying and summing to arrive at each sample. When the lag time is reached, the overlap is at a maximum.
8. Use functions lcorr, max and match to verify that the linear correlation of x and y is maximum at or around lag time.
Autocorrelation using lcorr
Use autocorrelation to estimate the order of a moving-average process.
1. Use the rnd and movavg functions to smooth a random sequence, with a window width of N.
2. Plot the moving average.
3. Use the lcorr function to compute and plot the autocorrelation of Y.
The first N values of autocorrelation form a more or less straight line declining to near 0 at N. If we didn't know the value of N we could use this behavior to make a good estimate.
4. For reference, use function slope to compute the slope of this initial segment and compare it to -1/N.
The autocorrelation is a Fourier transform of the spectrum of the signal. It can, therefore, be efficiently computed using the dft function.
plcorr
The plcorr function is used to estimate the order of the model that can best fit an autoregressive time series, and help compute the model parameter.
The partial autocorrelation sequence, also known as the reflection coefficient sequence, represents the correlation between values of the time series at times t and t-k, after those values have been adjusted by subtracting the forward and backward predictions. The predictions are based on the values of the series at the intermediate times.
For additional technical details refer to D. B. Percival and A. T. Walden, "Spectral Analysis for Physical Applications," p. 409, Cambridge University Press, 1993, which describes the use of Levinson-Durban recursion for autoregressive models.
To illustrate the use of the partial autocorrelation plcorr function, use the following steps to construct an autoregressive process.
1. Define coefficients for the process.
2. Use the rnd function to initialize the time series.
3. Generate the rest of the series by using the autoregression signal plus random noise.
4. Compute and plot the first 200 steps of the process.
5. Use the lcorr and plcorr functions to compute the autocorrelation and partial autocorrelation.
6. Plot the first 30 elements of each correlation vector, and use a vertical marker to mark the number of coefficients.
For the autoregressive process b the autocorrelation oscillates but the partial autocorrelation essentially cuts off after 6. Thus the partial autocorrelation gives information about the order of the process, which could then be used, for example, with the burg function.
Economic time series are often fitted and analyzed using low-order models, for which only a few of the plcorr coefficients are nonzero. For data whose plcorr coefficients do not drop off quickly, the data might reflect nonlinear phenomena. A common technique in this case is to difference the data and analyze the differenced data for correlations.