bundles / scipy 1.17.1 / scipy / signal / _signaltools / decimate
function
scipy.signal._signaltools:decimate
Signature
def decimate ( x , q , n = None , ftype = iir , axis = -1 , zero_phase = True ) Summary
Downsample the signal after applying an anti-aliasing filter.
Extended Summary
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
x: array_likeThe input signal made up of equidistant samples. If
xis a multidimensional array, the parameteraxisspecifies the time axis.q: intThe downsampling factor, which is a postive integer. When using IIR downsampling, it is recommended to call decimate multiple times for downsampling factors higher than 13.
n: int, optionalThe 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, optionalIf 'iir' or 'fir', specifies the type of lowpass filter. If an instance of an dlti object, uses that object to filter before downsampling.
axis: int, optionalThe axis along which to decimate.
zero_phase: bool, optionalPrevent 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
Trueis recommended, since a phase shift is generally not desired.
Returns
y: ndarrayThe down-sampled signal.
Notes
For non-integer downsampling factors, 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.
Array API Standard Support
decimate has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np from scipy import signal import matplotlib.pyplot as plt✓
wave_duration = 3 sample_rate = 100 freq = 2 q = 5✓
samples = wave_duration*sample_rate samples_decimated = int(samples/q)✓
x = np.linspace(0, wave_duration, samples, endpoint=False) y = np.cos(x*np.pi*freq*2)✓
ydem = signal.decimate(y, q) xnew = np.linspace(0, wave_duration, samples_decimated, endpoint=False)✓
plt.plot(x, y, '.-', xnew, ydem, 'o-') plt.xlabel('Time, Seconds') plt.legend(['data', 'decimated'], loc='best')✗
plt.show()
✓
See also
- resample
Resample up or down using the FFT method.
- resample_poly
Resample using polyphase filtering and an FIR filter.
Aliases
-
scipy.signal.decimate