crosscorr
Sample cross-correlation
Syntax
Description
[
returns the sample cross-correlation
function (XCF) and associated lags between two input vectors of
univariate time series data.xcf
,lags
] = crosscorr(y1
,y2
)
returns a table containing variables for the sample XCF and associated lags of
the last two variables in the input table or timetable. To select different
variables, for which to compute the XCF, use the
XCFTbl
= crosscorr(Tbl
)DataVariables
name-value argument. (since R2022a)
[___,
uses any input-argument combination in the
previous syntaxes, and returns the output-argument combination for the
corresponding input arguments and the approximate upper and lower confidence
bounds on the XCF.bounds
]
= crosscorr(___)
[___] = crosscorr(___,
uses additional options specified by one or more name-value arguments. For
example, Name=Value
)crosscorr(Tbl,DataVariables=["RGDP"
"CPI"],NumLags=10,NumSTD=1.96)
returns the sample XCF for lags -10
through 10 of the table variables "RGDP"
and
"CPI"
in Tbl
and 95% confidence
bounds.
crosscorr(___)
plots the sample XCF between
the input series with confidence bounds.
crosscorr(
plots on the axes specified by ax
,___)ax
instead of
the current axes (gca
). ax
can precede any of the input
argument combinations in the previous syntaxes.
[___,
plots the sample XCF between the input
series and additionally returns handles to plotted graphics objects. Use
elements of h
]
= crosscorr(___)h
to modify properties of the plot after you
create it.
Examples
Input Arguments
Output Arguments
More About
Algorithms
If
y1
andy2
have different lengths,crosscorr
appends enough zeros to the end of the shorter vector to make both vectors the same size.crosscorr
uses a Fourier transform (fft
) to compute the XCF in the frequency domain, and thencrosscorr
converts back to the time domain using an inverse Fourier transform (ifft
).NaN
values in the input series result inNaN
values in the output XCF. Unlikeautocorr
andparcorr
,crosscorr
does not treatNaN
values as missing completely at random. Whereasautocorr
andparcorr
compute coefficients in the time domain,crosscorr
usesfft
andifft
to compute coefficients in the frequency domain. Therefore, missing data treatments followfft
andifft
defaults.crosscorr
plots the XCF when you do not request any output or when you request the fourth output.
References
[1] Box, George E. P., Gwilym M. Jenkins, and Gregory C. Reinsel. Time Series Analysis: Forecasting and Control. 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1994.