def average_fft(self, fftlength=None, overlap=0, window=None):
        """Compute the averaged one-dimensional DFT of this `TimeSeries`.

        This method computes a number of FFTs of duration ``fftlength``
        and ``overlap`` (both given in seconds), and returns the mean
        average. This method is analogous to the Welch average method
        for power spectra.

        Parameters
        ----------
        fftlength : `float`
            number of seconds in single FFT, default, use
            whole `TimeSeries`

        overlap : `float`, optional
            number of seconds of overlap between FFTs, defaults to the
            recommended overlap for the given window (if given), or 0

        window : `str`, `numpy.ndarray`, optional
            window function to apply to timeseries prior to FFT,
            see :func:`scipy.signal.get_window` for details on acceptable
            formats

        Returns
        -------
        out : complex-valued `~gwpy.frequencyseries.FrequencySeries`
            the transformed output, with populated frequencies array
            metadata

        See Also
        --------
        :mod:`scipy.fftpack` for the definition of the DFT and conventions
        used.
        """
        from gwpy.spectrogram import Spectrogram
        # format lengths
        if fftlength is None:
            fftlength = self.duration
        if isinstance(fftlength, units.Quantity):
            fftlength = fftlength.value
        nfft = int((fftlength * self.sample_rate).decompose().value)
        noverlap = int((overlap * self.sample_rate).decompose().value)

        navg = divmod(self.size-noverlap, (nfft-noverlap))[0]

        # format window
        if window is None:
            window = 'boxcar'
        if isinstance(window, (str, tuple)):
            win = signal.get_window(window, nfft)
        else:
            win = numpy.asarray(window)
            if len(win.shape) != 1:
                raise ValueError('window must be 1-D')
            elif win.shape[0] != nfft:
                raise ValueError('Window is the wrong size.')
        win = win.astype(self.dtype)
        scaling = 1. / numpy.absolute(win).mean()

        if nfft % 2:
            nfreqs = (nfft + 1) // 2
        else:
            nfreqs = nfft // 2 + 1
        ffts = Spectrogram(numpy.zeros((navg, nfreqs), dtype=numpy.complex),
                           channel=self.channel, epoch=self.epoch, f0=0,
                           df=1 / fftlength, dt=1, copy=True)
        # stride through TimeSeries, recording FFTs as columns of Spectrogram
        idx = 0
        for i in range(navg):
            # find step TimeSeries
            idx_end = idx + nfft
            if idx_end > self.size:
                continue
            stepseries = self[idx:idx_end].detrend() * win
            # calculated FFT, weight, and stack
            fft_ = stepseries.fft(nfft=nfft) * scaling
            ffts.value[i, :] = fft_.value
            idx += (nfft - noverlap)
        mean = ffts.mean(0)
        mean.name = self.name
        mean.epoch = self.epoch
        mean.channel = self.channel
        return mean
def average_fft ( self , fftlength = None , overlap = 0 , window = None ) : from gwpy . spectrogram import Spectrogram if fftlength is None : fftlength = self . duration if isinstance ( fftlength , units . Quantity ) : fftlength = fftlength . value nfft = int ( ( fftlength * self . sample_rate ) . decompose ( ) . value ) noverlap = int ( ( overlap * self . sample_rate ) . decompose ( ) . value ) navg = divmod ( self . size - noverlap , ( nfft - noverlap ) ) [ 0 ] if window is None : window = 'boxcar' if isinstance ( window , ( str , tuple ) ) : win = signal . get_window ( window , nfft ) else : win = numpy . asarray ( window ) if len ( win . shape ) != 1 : raise ValueError ( 'window must be 1-D' ) elif win . shape [ 0 ] != nfft : raise ValueError ( 'Window is the wrong size.' ) win = win . astype ( self . dtype ) scaling = 1. / numpy . absolute ( win ) . mean ( ) if nfft % 2 : nfreqs = ( nfft + 1 ) // 2 else : nfreqs = nfft // 2 + 1 ffts = Spectrogram ( numpy . zeros ( ( navg , nfreqs ) , dtype = numpy . complex ) , channel = self . channel , epoch = self . epoch , f0 = 0 , df = 1 / fftlength , dt = 1 , copy = True ) idx = 0 for i in range ( navg ) : idx_end = idx + nfft if idx_end > self . size : continue stepseries = self [ idx : idx_end ] . detrend ( ) * win fft_ = stepseries . fft ( nfft = nfft ) * scaling ffts . value [ i , : ] = fft_ . value idx += ( nfft - noverlap ) mean = ffts . mean ( 0 ) mean . name = self . name mean . epoch = self . epoch mean . channel = self . channel return mean
Compute the averaged one-dimensional DFT of this `TimeSeries`.

        This method computes a number of FFTs of duration ``fftlength``
        and ``overlap`` (both given in seconds), and returns the mean
        average. This method is analogous to the Welch average method
        for power spectra.

        Parameters
        ----------
        fftlength : `float`
            number of seconds in single FFT, default, use
            whole `TimeSeries`

        overlap : `float`, optional
            number of seconds of overlap between FFTs, defaults to the
            recommended overlap for the given window (if given), or 0

        window : `str`, `numpy.ndarray`, optional
            window function to apply to timeseries prior to FFT,
            see :func:`scipy.signal.get_window` for details on acceptable
            formats

        Returns
        -------
        out : complex-valued `~gwpy.frequencyseries.FrequencySeries`
            the transformed output, with populated frequencies array
            metadata

        See Also
        --------
        :mod:`scipy.fftpack` for the definition of the DFT and conventions
        used.