Estimates the
MSCOHERE(x, y, win, overlap, nfft, fs, detrend, zeropad, range, output)
x |
- |
A series or array, the input series |
|||||||||
y |
- |
A series or array, the response. |
|||||||||
win |
- |
An integer or series, the segment size or window. If a series, each input segment is multiplied by win with the segment size set to length(win). Defaults to a Hamming window of where the length is 1/8 the length of the input series. |
|||||||||
overlap |
- |
Optional. An integer, the number of points to overlap each segment. Defaults to length(series)/2. |
|||||||||
nfft |
- |
Optional. An integer or series. If nfft is an integer, nfft is the FFT length. If nfft is a series, the series contains the frequencies used to evaluate the coherence. Defaults to the integer bestpow2(win). |
|||||||||
fs |
- |
Optional. A real, the sample rate. Defaults to rate(series). |
|||||||||
detrend |
- |
Optional. A string, the segment detrend mode:
|
|||||||||
zeropad |
- |
Optional. A string, the short segment zero pad mode:
|
|||||||||
range |
- |
Optional. A string, the frequency range of the coherence:
|
|||||||||
output
|
- |
Optional. A string, the output real/complex form:
|
A real series or array, the
W1: gsin(10000, 1/10000, 3000)
W2: gnorm(length(w1), deltax(w1)) + w1
W3: mscohere(W1, W2)
W1 contains 10000 samples of a 3 kHz sine sampled at 10 kHz.
W2 adds random noise to the sine.
W3 estimates the
W1: gsin(10000, 1/10000, 3000)
W2: gnorm(length(w1), deltax(w1)) + w1
W3: mscohere(W1, W2, hamming(1000), 500, 1024)
Same as above, except the series are divided into segments of 1000 points overlapped by 500 points and the 1024 point FFT is computed for each segment.
W1: gsin(10000, 1/10000, 3000)
W2: cumsum(gnorm(length(w1), deltax(w1))) + w1
W3: mscohere(W1, W2, hamming(1000), 500, 1024)
W4: mscohere(W1, W2, hamming(1000), 500, 1024, "constant")
Similar to above except the output noise is not normally distributed. W4 computes the coherence in the same manner as W3 except the mean of each segment is removed before FFT processing.
W1: gsin(10000, 1/10000, 3000);setvunits("V")
W2: gnorm(length(w1), deltax(w1)) + w1;setvunits("V")
W3: mscohere(W1, W2, hamming(1000), 500, 2000)
W4: 10*log10(mag(W3))
W5: mscohere(W1, W2, hamming(1000, 4), 500, 2940..3060)
W6: 10*log10(mag(W5));overp(W4)

Similar to above, except W4 displays the log
W1: gcos(10240, 1/1024, 256, pi/2)
W2: gcos(10240, 1/1024, 256, pi/3)
W3: mscohere(w1, w2, 128, 64, 1024, "complex")
W4: phase(w3)
p256 = w4[xtoidx(w4, 256)];
W1 and W2 contain 256 Hz cosine series sampled
at 1024 Hz. The cosine in W1 has a phase shift of π/2
radians and the cosine in W2 has a phase shift of π/3
radians. The phase difference between the two series is
W3 computes the complex coherence by dividing the series into segments of 128 samples overlapped by 64 samples. The 1024 FFTs of each segment are averaged.
W4 computes the phase of the complex coherence.
The variable p256 returns the phase of the coherence at 256 Hz with a value of -0.523599, essentially -π/6.
The complex coherence function Cxy( f ) between two series x[n] and y[n] is defined as:
where:
Sxy(
f )
is the
Sxx(
f )
and Syy(
f )
are the auto-power spectral densities of x[n]
and y[n]
(always real and
The complex coherence is purely real only if the
The magnitude-squared coherence is always real and always lies between 0 and 1 inclusive.
MSCOHERE estimates the magnitude-squared coherence function between an input series x and a corresponding output series y using the Welch method (see PWELCH). The input and output series are divided into overlapping segments and the magnitude-squared FFTs of the segments are averaged.
Series x is often a white noise process and y is the response of the system to the noise process.
By convention, the complex conjugate of x is used to compute the coherence.
The amplitudes of the magnitude-squared coherence estimate provide a measure of the linear correlation between x and y at frequency f and should lie between 0 (no correlation) and 1 (perfect correlation) inclusive.
If nfft is an array of one or
more target frequencies, MSCOHERE uses the GOERTZEL
algorithm to compute the coherence magnitudes at each input frequency.
The input frequencies can be any real values. Frequency values less than
zero or greater than
If detrend is "constant" or "linear", the mean or linear trend is computed and removed from each segment before FFT processing.
If zeropad is "zeropad", the last column is padded with zeros to make it the same length as the other columns. If zeropad is "none" or empty, the last column is ignored if it is shorter than the others.
If range is "twosided",
the full coherence is displayed from 0 to
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
is mapped to frequencies:
{-4, -3, -2, -1, 0, 1, 2, 3, 4, 5}
If range is "center",
the full coherence is displayed from
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
is mapped to frequencies:
{0, 1, 2, 3, 4, 5, -4, -3, -2, -1}
If both inputs are real, range defaults to "onesided", else if any input is complex, range defaults to "twosided".
By default, the
and phase of the complex coherence function is computed with:
See CPSD to estimate the complex
See TFESTIMATE to estimate the complex transfer function.
See PWELCH to estimate the
See DADiSP/FFTXL to optimize the underlying FFT computation.