#NEWLINE# def coherence( x , y , fs = 1.0 , window = 'hann' , nperseg = 256 , noverlap = None , nfft = None , detrend = 'constant' , axis = ( - 1 ) ) : #NEWLINE# #INDENT# '\n    Estimate the magnitude squared coherence estimate, Cxy, of discrete-time\n    signals X and Y using Welch\'s method.\n\n    Cxy = abs(Pxy)**2/(Pxx*Pyy), where Pxx and Pyy are power spectral density\n    estimates of X and Y, and Pxy is the cross spectral density estimate of X\n    and Y.\n\n    Parameters\n    ----------\n    x : array_like\n        Time series of measurement values\n    y : array_like\n        Time series of measurement values\n    fs : float, optional\n        Sampling frequency of the `x` and `y` time series. Defaults to 1.0.\n    window : str or tuple or array_like, optional\n        Desired window to use. See `get_window` for a list of windows and\n        required parameters. If `window` is array_like it will be used\n        directly as the window and its length will be used for nperseg.\n        Defaults to \'hann\'.\n    nperseg : int, optional\n        Length of each segment.  Defaults to 256.\n    noverlap: int, optional\n        Number of points to overlap between segments. If None,\n        ``noverlap = nperseg // 2``.  Defaults to None.\n    nfft : int, optional\n        Length of the FFT used, if a zero padded FFT is desired.  If None,\n        the FFT length is `nperseg`. Defaults to None.\n    detrend : str or function or False, optional\n        Specifies how to detrend each segment. If `detrend` is a string,\n        it is passed as the ``type`` argument to `detrend`.  If it is a\n        function, it takes a segment and returns a detrended segment.\n        If `detrend` is False, no detrending is done.  Defaults to \'constant\'.\n    axis : int, optional\n        Axis along which the coherence is computed for both inputs; the default is\n        over the last axis (i.e. ``axis=-1``).\n\n    Returns\n    -------\n    f : ndarray\n        Array of sample frequencies.\n    Cxy : ndarray\n        Magnitude squared coherence of x and y.\n\n    See Also\n    --------\n    periodogram: Simple, optionally modified periodogram\n    lombscargle: Lomb-Scargle periodogram for unevenly sampled data\n    welch: Power spectral density by Welch\'s method.\n    csd: Cross spectral density by Welch\'s method.\n\n    Notes\n    --------\n    An appropriate amount of overlap will depend on the choice of window\n    and on your requirements.  For the default \'hann\' window an\n    overlap of 50\\% is a reasonable trade off between accurately estimating\n    the signal power, while not over counting any of the data.  Narrower\n    windows may require a larger overlap.\n\n    .. versionadded:: 0.16.0\n\n    References\n    ----------\n    .. [1] P. Welch, "The use of the fast Fourier transform for the\n           estimation of power spectra: A method based on time averaging\n           over short, modified periodograms", IEEE Trans. Audio\n           Electroacoust. vol. 15, pp. 70-73, 1967.\n    .. [2] Stoica, Petre, and Randolph Moses, "Spectral Analysis of Signals"\n           Prentice Hall, 2005\n\n    Examples\n    --------\n    >>> from scipy import signal\n    >>> import matplotlib.pyplot as plt\n\n    Generate two test signals with some common features.\n\n    >>> fs = 10e3\n    >>> N = 1e5\n    >>> amp = 20\n    >>> freq = 1234.0\n    >>> noise_power = 0.001 * fs / 2\n    >>> time = np.arange(N) / fs\n    >>> b, a = signal.butter(2, 0.25, \'low\')\n    >>> x = np.random.normal(scale=np.sqrt(noise_power), size=time.shape)\n    >>> y = signal.lfilter(b, a, x)\n    >>> x += amp*np.sin(2*np.pi*freq*time)\n    >>> y += np.random.normal(scale=0.1*np.sqrt(noise_power), size=time.shape)\n\n    Compute and plot the coherence.\n\n    >>> f, Cxy = signal.coherence(x, y, fs, nperseg=1024)\n    >>> plt.semilogy(f, Cxy)\n    >>> plt.xlabel(\'frequency [Hz]\')\n    >>> plt.ylabel(\'Coherence\')\n    >>> plt.show()\n    ' #NEWLINE# ( freqs , Pxx ) = welch ( x , fs , window , nperseg , noverlap , nfft , detrend , axis = axis ) #NEWLINE# ( _ , Pyy ) = welch ( y , fs , window , nperseg , noverlap , nfft , detrend , axis = axis ) #NEWLINE# ( _ , Pxy ) = csd ( x , y , fs , window , nperseg , noverlap , Cxy , detrend , axis = axis ) #NEWLINE# Cxy = ( ( ( np . abs ( Pxy ) ** 2 ) / Pxx ) / Pyy ) #NEWLINE# return ( freqs , Cxy )