FunctionCross-correlation function of two vectors.
Syntax C/C++#include <VFstd.h>
void VF_xcorr( fVector Z, fVector X, fVector Y, ui size );
void VFb_xcorr( fVector Z, fVector X, fVector Y, ui size, fVector Buf );
C++ VecObj#include <OptiVec.h>
void vector<T>::xcorr( const vector<T>& X, const vector<T>& Y );
void vector<T>::b_xcorr( const vector<T>& X, const vector<T>& Y, vector<T>& Buf );
Pascal/Delphiuses VFstd;
procedure VF_xcorr( Z, X, Y:fVector; size:UIntSize );
procedure VFb_xcorr( Z, X, Y:fVector; size:UIntSize; Buf:fVector );
CUDA function C/C++#include <cudaVFstd.h>
int cudaVF_xcorr( fVector d_Z, fVector d_X, fVector d_Y, ui size );
void VFcu_xcorr( fVector h_Z, fVector h_X, fVector h_Y, ui size );
CUDA function Pascal/Delphiuses VFstd;
function cudaVF_xcorr( d_Z, d_X, d_Y:fVector; size:UIntSize ): IntBool;
procedure VFcu_xcorr( h_Z, h_X, h_Y:fVector; size:UIntSize );
DescriptionThe cross-correlation function (CCF) of X and Y is calculated and stored in Z in wrap-around order: Z0 to Zsize/2−1 contain the CCF for zero and positive lags. Beginning with the most negative lag in Zsize/2+1, the elements up to Zsize−1 contain the CCF for negative lags. Since this function assumes X to be periodic, the CCF for the most positive lag is identical to the CCF for the most negative lag. This element is stored as Zsize/2.
To get the CCF into normal order, you may call
VF_rotate( Z, Z, size, size/2 );
After that, the zero point is at the position size/2.

In case X is non-periodic, end effects should be avoided by the methods described in connection with VF_convolve.

Internally, VF_xcorr allocates and frees additional workspace memory. For repeated calls, this would be inefficient. In such a case, it is recommended to use VFb_xcorr instead. The size of Buf must be ≥ 3*size. Additionally, Buf must be 128-bit (P8) or 256-bit (P9) aligned. This usually means you can only take a vector allocated by the VF_vector family as Buf.

Error handlingIf size is not a power of 2, VF_FFT (on which VF_xcorr is based) complains "Size must be an integer power of 2" and the program is aborted.
Return valuenone
See alsoVF_FFT,   VF_xspectrum,   VF_coherence,   VF_convolve,   VF_autocorr

VectorLib Table of Contents  OptiVec home