Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

coherence (MathScript RT Module Function)

LabVIEW 2010 Help

Edition Date: June 2010

Part Number: 371361G-01

»View Product Info

Owning Class: spectral analysis

Requires: MathScript RT Module

Syntax

coherence(x, y)

coherence(x, y, fftsize, fs, window)

coherence(x, y, fftsize, fs, window, noverlap)

coherence(x, y, fftsize, fs, window, noverlap, flag)

Rxy = coherence(x, y)

Rxy = coherence(x, y, fftsize, fs, window)

Rxy = coherence(x, y, fftsize, fs, window, noverlap)

Rxy = coherence(x, y, fftsize, fs, window, noverlap, flag)

[Rxy, f] = coherence(x, y)

[Rxy, f] = coherence(x, y, fftsize, fs, window)

[Rxy, f] = coherence(x, y, fftsize, fs, window, noverlap)

[Rxy, f] = coherence(x, y, fftsize, fs, window, noverlap, flag)

Legacy Name: cohere

Description

Uses the Welch method to estimate the coherence of two signals. If you do not specify an output, this function plots the coherence in the current plot window.

Details

Examples

Inputs

Name Description
x Specifies the first input sequence.
y Specifies the second input sequence. length(y) must equal length(x).
fftsize Specifies the length of the FFT to perform on each segment of data. The default is the minimum of 256 and the length of x.
fs Specifies the sampling frequency. The default is 2.
window Specifies the window to apply to x and y. The length of the window must be less than or equal to fftsize. The default is a Hanning window with a length of fftsize.
noverlap Specifies the number of overlapping data elements between adjacent segments of data. noverlap must be less than the length of window. The default is 0.
flag Specifies the method to use to preprocess x and y before applying the window. flag is a string that accepts the following values.

'linear' LabVIEW removes the best linear fit of each segment of data.
'mean' LabVIEW removes the mean of each segment of data.
'none' (default) LabVIEW does not preprocess x and y.

Outputs

Name Description
Rxy Returns the coherence of the input signals x and y. If x and y are real, the length of Rxy is fftsize/2 + 1 for an even fftsize and (fftsize + 1) / 2 for an odd fftsize. If x and y are complex, the length of Rxy is fftsize.
f Returns the frequencies that correspond to Rxy.

Details

This function uses the Welch method to compute the power spectrum of x, the power spectrum of y, and the cross power spectrum of x and y. LabVIEW uses the following equation to compute the coherence of x and y:

R_xy(f) = |P_xy(f)|^2/(P_xx(f)*P_yy(f))

This function is supported in the LabVIEW Run-Time Engine only if you request an output from the function. This function can remain in your scripts when you build a stand-alone application or shared library, but if you do not request an output, the LabVIEW Run-Time Engine does not execute this function. If you request an output, the LabVIEW Run-Time Engine executes this function as normal.

Examples

fs = 1000;
T = 2;
t = 0:1 / fs:T - 1 / fs;
fftsize = 256;
noverlap = fftsize / 2;
window = win_hann2(fftsize);
dflag = 'none';
xn = sin(2*pi*100*t) + randnormal(1, length(t));
h = fir_win(5, 0.2, 'low', win_hann2(6));
yn = filter(h, 1, xn);
[Rxy, f] = coherence(xn, yn, fftsize, fs, window, noverlap, dflag);

Related Topics

crosssd
filter
fir_win
randnormal
sin
tf_estimate
win_hann2


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit