xrscipy.signal.decimate

xrscipy.signal.decimate(darray: DataArray, q: int = None, target_fs: float = None, n: int = None, ftype: str = 'iir', axis: int = -1, zero_phase: bool = True, dim: str = None) DataArray

Downsample the signal after applying an anti-aliasing filter.

By default, an order 8 Chebyshev type I filter is used. A 30 point FIR filter with Hamming window is used if ftype is ‘fir’.

Parameters:
  • darray (xarray.DataArray) – The input signal made up of equidistant samples.

  • q (int, optional) – The downsampling factor, which is a postive integer. If not provided, will be calculated from target_fs.

  • n (int, optional) – The order of the filter (1 less than the length for ‘fir’). Defaults to 8 for ‘iir’ and 20 times the downsampling factor for ‘fir’.

  • ftype (str {‘iir’, ‘fir’} or dlti instance, optional) – If ‘iir’ or ‘fir’, specifies the type of lowpass filter. If an instance of an dlti object, uses that object to filter before downsampling.

  • dim (str, optional) – The dimension along which to decimate. Uses the only dimension if 1D.

  • zero_phase (bool, optional) –

    Prevent phase shift by filtering with filtfilt instead of lfilter when using an IIR filter, and shifting the outputs back by the filter’s group delay when using an FIR filter. The default value of True is recommended, since a phase shift is generally not desired.

    Added in version 0.18.0.

Returns:

y – The down-sampled signal.

Return type:

ndarray

See also

resample

Resample up or down using the FFT method.

resample_poly

Resample using polyphase filtering and an FIR filter.

scipy.signal.decimate

Original scipy implementation

Notes

For non-integer downsampling factors, ~scipy.signal.resample can be used. Consult the scipy.interpolate module for methods of resampling signals with non-constant sampling intervals.

The zero_phase keyword was added in 0.18.0. The possibility to use instances of dlti as ftype was added in 0.18.0.

Examples

>>> import numpy as np
>>> from scipy import signal
>>> import matplotlib.pyplot as plt

Define wave parameters.

Examples

>>> wave_duration = 3
>>> sample_rate = 100
>>> freq = 2
>>> q = 5

Calculate number of samples.

Examples

>>> samples = wave_duration*sample_rate
>>> samples_decimated = int(samples/q)

Create cosine wave.

Examples

>>> x = np.linspace(0, wave_duration, samples, endpoint=False)
>>> y = np.cos(x*np.pi*freq*2)

Decimate cosine wave.

Examples

>>> ydem = signal.decimate(y, q)
>>> xnew = np.linspace(0, wave_duration, samples_decimated, endpoint=False)

Plot original and decimated waves.

Examples

>>> plt.plot(x, y, '.-', xnew, ydem, 'o-')
>>> plt.xlabel('Time, Seconds')
>>> plt.legend(['data', 'decimated'], loc='best')
>>> plt.show()