DECIMATE

Decimation reduces the sampling rate of a signal by an integer factor while suppressing frequency content that would otherwise alias into the lower-rate signal. The input is first passed through a low-pass filter and is then kept at every q-th sample.

If the original sampling rate is f_s and the decimation factor is q, the new sampling rate becomes:

f_{s,\text{new}} = \frac{f_s}{q}

This wrapper exposes SciPy’s IIR and FIR anti-alias filtering modes. The default IIR mode uses an order-8 Chebyshev Type I filter, while the FIR mode uses a Hamming-window FIR design whose default order scales with the decimation factor.

Excel Usage

=DECIMATE(x, q, n, decimate_ftype, zero_phase)
  • x (list[list], required): The data to be downsampled.
  • q (int, required): The downsampling factor.
  • n (int, optional, default: null): The order of the filter. Defaults to 8 for IIR and 20*q for FIR.
  • decimate_ftype (str, optional, default: “iir”): The type of lowpass filter.
  • zero_phase (bool, optional, default: true): Prevent phase shift by filtering with filtfilt (IIR) or shifting (FIR).

Returns (list[list]): A 2D array of the downsampled signal.

Example 1: Downsample by 4 (IIR)

Inputs:

x q
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 4

Excel formula:

=DECIMATE({1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}, 4)

Expected output:

Result
0.990849 4.93716 8.91137 12.8262 16.8428 20.7077 24.7702 28.6382
Example 2: Downsample by 2 (FIR)

Inputs:

x q decimate_ftype
1 2 3 4 5 6 7 8 2 fir

Excel formula:

=DECIMATE({1,2,3,4,5,6,7,8}, 2, "fir")

Expected output:

Result
0.788906 3.23884 4.66274 7.64716
Example 3: Downsample by 3 without zero-phase filtering

Inputs:

x q zero_phase
1 2 3 4 5 6 7 8 9 10 11 12 3 false

Excel formula:

=DECIMATE({1,2,3,4,5,6,7,8,9,10,11,12}, 3, FALSE)

Expected output:

Result
0.0000347995 0.0192557 0.47327 2.68031
Example 4: Downsample by 2 with custom IIR filter order

Inputs:

x q n
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 2 4

Excel formula:

=DECIMATE({1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5}, 2, 4)

Expected output:

Result
0.988349 1.9774 2.96535 3.95458 4.94223 5.93224 6.91825 7.9112

Python Code

Show Code
import numpy as np
from scipy.signal import decimate as scipy_decimate

def decimate(x, q, n=None, decimate_ftype='iir', zero_phase=True):
    """
    Downsample the signal after applying an anti-aliasing filter.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.decimate.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        x (list[list]): The data to be downsampled.
        q (int): The downsampling factor.
        n (int, optional): The order of the filter. Defaults to 8 for IIR and 20*q for FIR. Default is None.
        decimate_ftype (str, optional): The type of lowpass filter. Valid options: IIR, FIR. Default is 'iir'.
        zero_phase (bool, optional): Prevent phase shift by filtering with filtfilt (IIR) or shifting (FIR). Default is True.

    Returns:
        list[list]: A 2D array of the downsampled signal.
    """
    try:
        def to_1d(v):
            if isinstance(v, list):
                return np.array([float(x) for row in v for x in row])
            return np.array([float(v)])

        x_arr = to_1d(x)

        result = scipy_decimate(
            x_arr, 
            int(q), 
            n=int(n) if n is not None else None, 
            ftype=decimate_ftype, 
            zero_phase=bool(zero_phase)
        )

        return [result.tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

The data to be downsampled.
The downsampling factor.
The order of the filter. Defaults to 8 for IIR and 20*q for FIR.
The type of lowpass filter.
Prevent phase shift by filtering with filtfilt (IIR) or shifting (FIR).