8000 inconsistency in the algorithm for calculating cross spectral densities · Issue #9751 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
inconsistency in the algorithm for calculating cross spectral densities #9751
Closed
@zsoltlazar

Description

@zsoltlazar

Bug report

Bug summary

In /usr/local/lib/python2.7/dist-packages/matplotlib/mlab.py Welch's periodogramm method is implemented erronously for the case of two time series. For the second time series the order of detrending and windowing are interchanged.

between lines 716 to 728, within the _spectral_helper method

    result = detrend(result, detrend_func, axis=0)    // ZIL comment: detrend first 
    result, windowVals = apply_window(result, window, axis=0,  // ZIL comment: windowing next
                                      return_window=True)      // THIS IS CORRECT!
    result = np.fft.fft(result, n=pad_to, axis=0)[:numFreqs, :]
    freqs = np.fft.fftfreq(pad_to, 1/Fs)[:numFreqs]

    if not same_data:
        # if same_data is False, mode must be 'psd'   
        resultY = stride_windows(y, NFFT, noverlap)
        resultY = apply_window(resultY, window, axis=0)  // ZIL comment: windowing first ????? 
        resultY = detrend(resultY, detrend_func, axis=0) // ZIL comment: detrend next ??????
                                                                  // THIS IS INCORRECT!
        resultY = np.fft.fft(resultY, n=pad_to, axis=0)[:numFreqs, :]
        result = np.conjugate(result) * resultY

Matplotlib version

  • Operating system: Ubuntu 16.04
  • Matplotlib version: 2.0.1
  • Python version: 2.7.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0