Skip to content Skip to sidebar Skip to footer

Why Is Cohere Function In Matplotlib (python) Give Answer Different From Mscohere Function In Matlab?

in maltlab and pythonmatplotlib.mlab contains Numerical python functions written for compatability with MATLAB commands with the same names. But for me I get different results in

Solution 1:

Originally matplotlib.mlab functions were meant to provide similar capabilities to their MATLAB equivalents, but some basics approaches between MATLAB and numpy differ so they don't always do things in exactly the same way, and in some cases they have diverged somewhat due to differing needs and/or goals. Nowadays mlab is more a set of numerical functions that aren't available in numpy but are needed by matplotlib.

In your case, the MATLAB function defaults to using a hamming window, while the matplotlib version defaults to using a hanning window. You can reproduce the MATLAB results by simple passing an appropriately-lengthed hamming window. Also, MATLAB uses Fs=1 by default while matplotlib uses Fs=2 by default, but I think that only changes the frequencies, not cxy:

>>>cxy, _ = mlab.cohere(y1, y2, window=np.hamming(16), NFFT=16, noverlap=0, Fs=1)>>>print(cxy)
[  8.29985202e-01   5.03649611e-02   5.54167037e-04   8.19190824e-03   1.82760544e-01   2.56179777e-01   7.98391906e-01   9.78827021e-01   9.88429511e-01]

Post a Comment for "Why Is Cohere Function In Matplotlib (python) Give Answer Different From Mscohere Function In Matlab?"