Compute the cross-spectral density. The cross spectral density :math:`P_{xy}` by Welch's average periodogram method. The vectors *x* and *y* are divided into *NFFT* length segments. Each segment is detrended by function *detrend* and windowed by function *window*. *noverlap*
(x, y, NFFT=None, Fs=None, detrend=None, window=None,
noverlap=None, pad_to=None, sides=None, scale_by_freq=None)
| 534 | |
| 535 | @_docstring.interpd |
| 536 | def csd(x, y, NFFT=None, Fs=None, detrend=None, window=None, |
| 537 | noverlap=None, pad_to=None, sides=None, scale_by_freq=None): |
| 538 | """ |
| 539 | Compute the cross-spectral density. |
| 540 | |
| 541 | The cross spectral density :math:`P_{xy}` by Welch's average |
| 542 | periodogram method. The vectors *x* and *y* are divided into |
| 543 | *NFFT* length segments. Each segment is detrended by function |
| 544 | *detrend* and windowed by function *window*. *noverlap* gives |
| 545 | the length of the overlap between segments. The product of |
| 546 | the direct FFTs of *x* and *y* are averaged over each segment |
| 547 | to compute :math:`P_{xy}`, with a scaling to correct for power |
| 548 | loss due to windowing. |
| 549 | |
| 550 | If len(*x*) < *NFFT* or len(*y*) < *NFFT*, they will be zero |
| 551 | padded to *NFFT*. |
| 552 | |
| 553 | Parameters |
| 554 | ---------- |
| 555 | x, y : 1-D arrays or sequences |
| 556 | Arrays or sequences containing the data |
| 557 | |
| 558 | %(Spectral)s |
| 559 | |
| 560 | %(PSD)s |
| 561 | |
| 562 | noverlap : int, default: 0 (no overlap) |
| 563 | The number of points of overlap between segments. |
| 564 | |
| 565 | Returns |
| 566 | ------- |
| 567 | Pxy : 1-D array |
| 568 | The values for the cross spectrum :math:`P_{xy}` before scaling (real |
| 569 | valued) |
| 570 | |
| 571 | freqs : 1-D array |
| 572 | The frequencies corresponding to the elements in *Pxy* |
| 573 | |
| 574 | References |
| 575 | ---------- |
| 576 | Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John |
| 577 | Wiley & Sons (1986) |
| 578 | |
| 579 | See Also |
| 580 | -------- |
| 581 | psd : equivalent to setting ``y = x``. |
| 582 | """ |
| 583 | if NFFT is None: |
| 584 | NFFT = 256 |
| 585 | Pxy, freqs, _ = _spectral_helper(x=x, y=y, NFFT=NFFT, Fs=Fs, |
| 586 | detrend_func=detrend, window=window, |
| 587 | noverlap=noverlap, pad_to=pad_to, |
| 588 | sides=sides, scale_by_freq=scale_by_freq, |
| 589 | mode='psd') |
| 590 | |
| 591 | if Pxy.ndim == 2: |
| 592 | if Pxy.shape[1] > 1: |
| 593 | Pxy = Pxy.mean(axis=1) |
no test coverage detected