Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistency in the algorithm for calculating cross spectral densities #9751

Closed
zsoltlazar opened this issue Nov 11, 2017 · 3 comments
Closed
Milestone

Comments

@zsoltlazar
Copy link

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
@jklymak
Copy link
Member

jklymak commented Nov 11, 2017

What to do about these fcns is an interesting conversation, because users really should be using the numpy functions. I think these ones are a historic artifact.

That said, I agree this is wrong, and I just checked, that it is indeed wrong in master. Did you want to try a PR to fix it. If not, I'm happy to do it.

@zsoltlazar
Copy link
Author

Thank you for the feedback!
I don't have experience in working with these repositories. So you can go ahead and correct it if you have the resources.

@dstansby
Copy link
Member

Fixed by #9753

@QuLogic QuLogic added this to the v2.2 milestone Nov 12, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants