Signal processing#

In a wide-array of applications, the original data recorded from a digital system must be manipulated in order to extract the greatest amount of information. GWpy provides a suite of functions to simplify and extend the excellent digital signal processing suite in scipy.signal.

See also

Spectral density estimation#

Spectral density estimation is a common way of investigating the frequency-domain content of a time-domain signal. GWpy provides wrappers of power spectral density (PSD) estimation methods from scipy.signal to simplify calculating a FrequencySeries from a TimeSeries.

The gwpy.signal.spectral sub-package provides the following PSD estimation averaging methods:

  • 'bartlett' - mean average of non-overlapping periodograms

  • 'median' - median average of overlapping periodograms

  • 'welch' - mean average of overlapping periodograms

Each of these can be specified by passing the function name as the method keyword argument to any of the relevant TimeSeries instance methods:

TimeSeries.psd([fftlength, overlap, window, ...])

Calculate the PSD FrequencySeries for this TimeSeries.

TimeSeries.asd([fftlength, overlap, window, ...])

Calculate the ASD FrequencySeries of this TimeSeries.

TimeSeries.spectrogram(stride[, fftlength, ...])

Calculate the average power spectrogram of this TimeSeries.

TimeSeries.spectrogram2(fftlength[, ...])

Calculate the non-averaged power Spectrogram of this TimeSeries.

e.g, TimeSeries.psd():

>>> ts = TimeSeries(...)
>>> psd = ts.psd(..., method='median', ...)

See scipy.signal.welch() for more detailed documentation on the PSD estimation method used.

Time-domain filtering#

The TimeSeries object comes with a number of instance methods that should make filtering data easy for a number of common use cases. Available methods include:

TimeSeries.highpass

Filter this TimeSeries with a high-pass filter.

TimeSeries.lowpass

Filter this TimeSeries with a Butterworth low-pass filter.

TimeSeries.bandpass

Filter this TimeSeries with a band-pass filter.

TimeSeries.zpk

Filter this TimeSeries by applying a digital zero-pole-gain filter.

TimeSeries.whiten

Whiten this TimeSeries using inverse spectrum truncation.

TimeSeries.filter

Filter this TimeSeries with an IIR or FIR filter.

Each of the above methods eventually calls out to TimeSeries.filter() to apply a digital linear filter, normally via cascaded second-order-sections.

For a worked example of how to filter LIGO data to discover a gravitational-wave signal, see Filtering a TimeSeries to detect gravitational waves.

Frequency-domain filtering#

Additionally, the TimeSeries object includes a number of instance methods to generate frequency-domain information for some data. Available methods include:

TimeSeries.psd

Calculate the PSD FrequencySeries for this TimeSeries.

TimeSeries.asd

Calculate the ASD FrequencySeries of this TimeSeries.

TimeSeries.spectrogram

Calculate the average power spectrogram of this TimeSeries.

TimeSeries.q_transform

Compute the multi-Q transform and return an interpolated spectrogram.

TimeSeries.rayleigh_spectrum

Calculate the Rayleigh FrequencySeries for this TimeSeries.

TimeSeries.rayleigh_spectrogram

Calculate the Rayleigh statistic spectrogram of this TimeSeries.

For a worked example of how to load data and calculate the Amplitude Spectral Density FrequencySeries, see Calculate and plot a FrequencySeries.

Filter design#

gwpy.signal.filter_design provides a number of filter design methods which, when combined with the BodePlot visualisation, can be used to create a number of common filters:

lowpass

Design a low-pass filter for the given cutoff frequency.

highpass

Design a high-pass filter for the given cutoff frequency.

bandpass

Design a band-pass filter for the given cutoff frequencies.

notch

Design a ZPK notch filter for the given frequency and sampling rate.

concatenate_zpks

Concatenate a list of zero-pole-gain (ZPK) filters.

Each of these will return filter coefficients that can be passed directly into filter.

For a worked example of designing a digital filter, and then visualising it, see Visualising filters (BodePlot).

Cross-channel correlations#

The TimeSeries object also includes instance methods to calculate cross-channel correlations in the frequency domain. Available methods include:

TimeSeries.coherence

Calculate the frequency-coherence between this TimeSeries and another.

TimeSeries.coherence_spectrogram

Calculate the coherence spectrogram between this TimeSeries and other.

For a worked example of how to compare channels like this, see Calculate the coherence between two channels.