VF_coherenceVD_coherenceVE_coherence
VFb_coherenceVDb_coherenceVEb_coherence
FunctionAmplitude-squared Coherence function of two signals
Syntax C/C++#include <VFstd.h>
float VF_coherence( fVector Coher, ui specsiz, fVector X, fVector Y, ui xsiz, fVector Win );
float VFb_coherence( fVector Coher, ui specsiz, fVector X, fVector Y, ui xsiz, fVector Win, fVector Buf );
C++ VecObj#include <OptiVec.h>
T vector<T>::coherence( const vector<T>& X, const vector<T>& Y, const vector<T>& Win );
T vector<T>::b_coherence( const vector<T>& X, const vector<T>& Y, const vector<T>& Win, vector<T>& Buf );
Pascal/Delphiuses VFstd;
function VF_coherence( Coher:fVector; specsiz:UIntSize; X,Y:fVector; xsiz:UIntSize; Win:fVector ): Single;
function VFb_coherence( Coher:fVector; specsiz:UIntSize; X,Y:fVector; xsiz:UIntSize; Win, Buf:fVector ): Single;
CUDA Function C/C++#include <cudaVFstd.h>
int cudaVF_coherence( float *h_coherfNyq, fVector d_Coher, ui specsiz, fVector d_X, fVector d_Y, ui xsiz, fVector d_Win );
int cusdVF_coherence( float *d_coherfNyq, fVector d_Coher, ui specsiz, fVector d_X, fVector d_Y, ui xsiz, fVector d_Win );
float VFcu_coherence( fVector h_Coher, ui specsiz, fVector h_X, fVector h_Y, ui xsiz, fVector h_Win );
CUDA Function Pascal/Delphiuses VFstd;
function cudaVF_coherence( var h_coherfNyq:Single; d_Coher:fVector; specsiz:UIntSize; d_X, d_Y:fVector; xsiz:UIntSize; d_Win:fVector ): IntBool;
function cusdVF_coherence( d_coherfNyq:PSingle; d_Coher:fVector; specsiz:UIntSize; d_X, d_Y:fVector; xsiz:UIntSize; d_Win:fVector ): IntBool;
function VFcu_coherence( h_Coher:fVector; specsiz:UIntSize; h_X, h_Y:fVector; xsiz:UIntSize; h_Win:fVector ): Single;
DescriptionThe amplitude-squared Coherence function of the two data sets X and Y is calculated. It is defined as the square of the cross-density spectrum of X and Y, divided by the product of the individual power-density spectra of X and Y:
CXY = SXY2 / (SXX * SYY).
As the result is identical for negative and positive frequencies, here the coherence function for 0 and positive frequencies is stored. In order to keep specsiz an integer power of 2, there are only specsiz points stored in Coher and the last one, the Coherence function at the Nyquist frequency fNyquist = 0.5 / sampling_interval, is given as the return value of the function. It may either be neglected (by calling the function like a void function) or stored as the last element in Spc by calling the function as
Coher[specsiz] = VF_coherence( Coher, specsiz, X, X, xsiz, Win );
in this case, Coher must have a length of specsiz+1.

xsiz must be at least 2*specsiz, and specsiz has to be an integer power of 2. Internally, X is divided into (xsiz/specsiz)−1 segments and the average over the spectra of the individual segments is calculated, before calculating the coherence function from these averaged spectra.

Win is a window that is applied to the data segments. The size of the Win vector must be 2*specsiz. Within the VectorLib library, three functions are available that give suitable Windows: VF_Welch,   VF_Parzen, and VF_Hann. A square window (i.e. no windowing at all) is achieved by setting all elements of Win to 1.0 using VF_equ1. Use of the square window is not recommended here, though.

Internally, VF_coherence allocate and frees additional workspace memory. For repeated calls, this would be inefficient. In such a case, it is recommended to use VFb_coherence instead. The size of Buf must be ≥ 4*xsiz + 8*specsiz. 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_coherence is based) complains "Size must be an integer power of 2" and the program is aborted.
Return valueCoherence function at the Nyquist frequency
See alsoVF_FFT,   VF_spectrum,   VF_xspectrum,   VF_convolve,   VF_autocorr,   VF_xcorr,   VF_filter

VectorLib Table of Contents  OptiVec home