def coherence(x, y, fs=1.0, window='hann', nperseg=None, noverlap=None, nfft=None, detrend='constant', axis=(-1)):
 (freqs, Pxx) = welch(x, fs, window, nperseg, noverlap, nfft, detrend, axis=axis)
 (_, Pyy) = welch(y, fs, window, nperseg, noverlap, nfft, detrend, axis=axis)
 (_, Pxy) = csd(x, y, fs, window, nperseg, noverlap, nfft, detrend, axis=axis)
 Cxy = (((np.abs(Pxy) ** 2) / Pxx) / Pyy)
 return (freqs, Cxy)

def coherence ( x , y , fs = 1.0 , window = 'hann' , nperseg = None , noverlap = None , nfft = None , detrend = 'constant' , axis = ( - 1 ) ) : ( freqs , Pxx ) = welch ( x , fs , window , nperseg , noverlap , nfft , detrend , axis = axis ) ( _ , Pyy ) = welch ( y , fs , window , nperseg , noverlap , nfft , detrend , axis = axis ) ( _ , Pxy ) = csd ( x , y , fs , window , nperseg , noverlap , nfft , detrend , axis = axis ) Cxy = ( ( ( np . abs ( Pxy ) ** 2 ) / Pxx ) / Pyy ) return ( freqs , Cxy )
estimate the magnitude squared coherence estimate .