Qu

downsample

Builtin index · Signal processing

result = downsample(x, M, [order=60], [fs=])

Input: x, M, order, fs · Output: result

What it is

x: a length-N vector or Signal; M: a whole number ≥ 1, the integer decimation factor; order (optional, even, default 60): the FIR anti-alias filter's order; fs (optional): the input sample rate, defaulting to the Signal's own Fs or 1.0 for a plain vector. Lowers the sample rate by an integer factor, anti-aliasing first: applies a lowpass at the new Nyquist (fs/(2*M), at the input rate) and only then keeps every Mth sample. The order matters and is the point — decimating first and filtering afterwards filters alias that has already folded into the band, which no filter can separate from signal again.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = downsample(x, M, [order=60], [fs=])
x vector or Signalx: a length-N vector or Signal.
M numberM: a whole number ≥ 1, the integer decimation factor.
order optional (default 60)order (optional, even, default 60): the FIR anti-alias filter's order.
fs Signal or vector, optionalfs (optional): the input sample rate, defaulting to the Signal's own Fs or 1.0 for a plain vector.
result Signal or vector
Returns ceil(N/M) samples (y[i] = filtered[i*M], sample 0 always kept) — a Signal at Fs = fs/M if x was one, a plain vector otherwise. The filter is causal, so the output is delayed by order/2 samples at the INPUT rate (30 by default, i.e. order/(2*M) output samples), which is order/(2*fs) seconds. M = 1 is the identity. Added in v0.3.0.

Examples

No documentation example calls this form yet. The Signal processing chapter is where one belongs.

How it works

downsample(x, M, [order=], [fs=]) — anti-alias FIRST with a lowpass at the new Nyquist (fs/(2*M), running at the input rate fs), THEN keep every Mth sample. The order matters and is the whole point: decimating first and filtering afterwards filters alias that has already folded into the band, which no filter can separate from signal again. Output length is ceil(len(x)/M) — y[i] = filtered[i*M], MATLAB's own downsample/decimate convention (sample 0 is always kept). Group delay: order/2 samples at the INPUT rate fs, which is order/(2*M) samples at the output rate (15 output samples for M=2 at the default order 60), i.e. order/(2*fs) seconds.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.