Estimates the
CPSD(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 |
|||||||||
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
|
|||||||||
output |
- |
Optional. A string, the output real/complex form:
|
A complex series or array, the complex
W1: gsin(10000, 1/10000, 3000);setvunits("V")
W2: gnorm(length(w1), deltax(w1)) + w1;setvunits("V")
W3: cpsd(W1, W2)
W4: 10*log10(mag(W3))

W1 contains 10000 samples of a 3 kHz sine sampled at 10 kHz.
W2 adds random noise to the sine.
W3 estimates the
W4 displays the dB log magnitude of the complex
W1: gsin(10000, 1/10000, 3000);setvunits("V")
W2: gnorm(length(w1), deltax(w1)) + w1;setvunits("V")
W3: cpsd(W1, W2, hamming(1000), 500, 1024)
W4: 10*log10(mag(W3))
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);setvunits("V")
W2: gnorm(length(w1), deltax(w1)) + w1;setvunits("V")
W3: cpsd(W1, W2, hamming(1000), 500, 1024, "constant")
W4: 10*log10(mag(W3))
Same as above, except the mean value of each segment is subtracted from the segment before FFT processing.
W1: gsin(10000, 1/10000, 3000);setvunits("V")
W2: gnorm(length(w1), deltax(w1)) + w1;setvunits("V")
W3: cpsd(W1, W2, hamming(1000), 500, 2000)
W4: 10*log10(mag(W3))
W5: cpsd(W1, W2, hamming(1000, 4), 500, 2940..3060)
W6: 10*log10(mag(W5));overp(W4)
Similar to above, except W4 displays the log magnitude of the CPSD. W5 computes the CPSD over the frequency range from 2940 Hz to 3060 Hz. W6 shows the log magnitude of the CPSD contained in W5 and overplots the full log magnitude CPSD contained in W4.
W1: gsin(10000, 1/10000, 3000);setvunits("V")
W2: gnorm(length(w1), deltax(w1)) + w1;setvunits("V")
W3: 10*log10(cpsd(W1, W2, hamming(1000), 500, 2000, "mag"))
W4: 10*log10(cpsd(W1, W2, hamming(1000, 4), 500, 2940..3060, "mag"));overp(w3)
Similar to above, except the magnitudes of
the
W1: gcos(10240, 1/1024, 256, pi/2)
W2: gcos(10240, 1/1024, 256, pi/3)
W3: cpsd(w1, w2, 128, 64, 1024)
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
W4 computes the phase of the complex
The variable p256 returns the phase of the CPSD at 256 Hz with a value of -0.523599, essentially -π/6.
The
where E
is the expected value operator, x[n] and y[n]
are a stationary random processes and * indicates complex conjugate. In
practice, the
The digital CPSD is the DTFT of the cross-correlation estimate:
The CPSD can be computed from the DTFTs of the input series X( f ) and Y( f ):
CPSD estimates the complex
By convention, the complex conjugate of x is used to compute the CPSD.
If nfft is an array of one or more target frequencies, CPSD uses the GOERTZEL algorithm to compute the CPSD at each input frequency. The input frequencies can be any real values. Frequency values less than zero or greater than rate(x) are wrapped to the range between 0 and rate(x).
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 CPSD is displayed from 0 to
rate(x) in
{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 CPSD is displayed from -rate(x)/2 to rate(x)/2 with the zero frequency in the middle. For example, a 10 point full CPSD with values at frequencies:
{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 output of CPSD is complex. Use MAGNITUDE
and PHASE to compute the magnitude
and phase components from the complex CPSD. For example, the
mag(CPSD(x, y))^2
and phase of the CPSD is computed with:
phase(CPSD(x, y))
By default, the complex CPSD is returned. However, if
output is "mag2" or "mag", CPSD returns the
See MSCOHERE to estimate the
See TFESTIMATE to estimate the complex transfer function.
See PWELCH to estimate the power spectral density.
See DADiSP/FFTXL to optimize the underlying FFT computation.
[1] |
P. Welch |
|
The use of the fast Fourier transform for the estimation of power spectra: A method based on time averaging over short, modified periodograms. |
|
IEEE Trans. Audio Electroacoust. vol. 15, 1967 |
|
pp 70-73 |
[2] |
Rabiner, Lawrence R., and B. Gold |
|
Theory and Application of Digital Signal Processing |
|
Prentice-Hall, 1975 |
|
pp 414-419 |