#NEWLINE# def welch( x , fs = 1.0 , window = 'hann' , nperseg = 256 , noverlap = None , nfft = None , detrend = 'constant' , return_onesided = True , scaling = 'density' , axis = ( - 1 ) ) : #NEWLINE# #INDENT# '\n    Estimate power spectral density using Welch\'s method.\n\n    Welch\'s method [1]_ computes an estimate of the power spectral density\n    by dividing the data into overlapping segments, computing a modified\n    periodogram for each segment and averaging the periodograms.\n\n    Parameters\n    ----------\n    x : array_like\n        Time series of measurement values\n    fs : float, optional\n        Sampling frequency of the `x` 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    return_onesided : bool, optional\n        If True, return a one-sided spectrum for real data. If False return\n        a two-sided spectrum. Note that for complex data, a two-sided\n        spectrum is always returned.\n    scaling : { \'density\', \'spectrum\' }, optional\n        Selects between computing the power spectral density (\'density\')\n        where `Pxx` has units of V**2/Hz and computing the power spectrum\n        (\'spectrum\') where `Pxx` has units of V**2, if `x` is measured in V\n        and fs is measured in Hz.  Defaults to \'density\'\n    axis : int, optional\n        Axis along which the periodogram is computed; the default is over\n        the last axis (i.e. ``axis=-1``).\n\n    Returns\n    -------\n    f : ndarray\n        Array of sample frequencies.\n    Pxx : ndarray\n        Power spectral density or power spectrum of x.\n\n    See Also\n    --------\n    periodogram: Simple, optionally modified periodogram\n    lombscargle: Lomb-Scargle periodogram for unevenly sampled data\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    If `noverlap` is 0, this method is equivalent to Bartlett\'s method [2]_.\n\n    .. versionadded:: 0.12.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] M.S. Bartlett, "Periodogram Analysis and Continuous Spectra",\n           Biometrika, vol. 37, pp. 1-16, 1950.\n\n    Examples\n    --------\n    >>> from scipy import signal\n    >>> import matplotlib.pyplot as plt\n    >>> np.random.seed(1234)\n\n    Generate a test signal, a 2 Vrms sine wave at 1234 Hz, corrupted by\n    0.001 V**2/Hz of white noise sampled at 10 kHz.\n\n    >>> fs = 10e3\n    >>> N = 1e5\n    >>> amp = 2*np.sqrt(2)\n    >>> freq = 1234.0\n    >>> noise_power = 0.001 * fs / 2\n    >>> time = np.arange(N) / fs\n    >>> x = amp*np.sin(2*np.pi*freq*time)\n    >>> x += np.random.normal(scale=np.sqrt(noise_power), size=time.shape)\n\n    Compute and plot the power spectral density.\n\n    >>> f, Pxx_den = signal.welch(x, fs, nperseg=1024)\n    >>> plt.semilogy(f, Pxx_den)\n    >>> plt.ylim([0.5e-3, 1])\n    >>> plt.xlabel(\'frequency [Hz]\')\n    >>> plt.ylabel(\'PSD [V**2/Hz]\')\n    >>> plt.show()\n\n    If we average the last half of the spectral density, to exclude the\n    peak, we can recover the noise power on the signal.\n\n    >>> np.mean(Pxx_den[256:])\n    0.0009924865443739191\n\n    Now compute and plot the power spectrum.\n\n    >>> f, Pxx_spec = signal.welch(x, fs, \'flattop\', 1024, scaling=\'spectrum\')\n    >>> plt.figure()\n    >>> plt.semilogy(f, np.sqrt(Pxx_spec))\n    >>> plt.xlabel(\'frequency [Hz]\')\n    >>> plt.ylabel(\'Linear spectrum [V RMS]\')\n    >>> plt.show()\n\n    The peak height in the power spectrum is an estimate of the RMS amplitude.\n\n    >>> np.sqrt(Pxx_spec.max())\n    2.0077340678640727\n\n    ' #NEWLINE# ( freqs , Pxx ) = csd ( x , x , fs , window , nperseg , noverlap , nfft , detrend , return_onesided , scaling , axis ) #NEWLINE# return ( freqs , Pxx . real )