Resampling

class tiliqua.dsp.Resample(*args, src_loc_at=0, **kwargs)

Polyphase fractional resampler.

Upsamples by factor N, filters the result, then downsamples by factor M. The upsampling action zero-pads before applying the low-pass filter, so the low-pass filter coefficients are prescaled by N to preserve total energy.

The underlying FIR interpolator only performs MACs on non-padded input samples, (and for output samples which are not discarded), which can make a big difference for large upsampling/interpolating ratios, and is what makes this a polyphase resampler - time complexity per output sample proportional to O(fir_order/N).

Members:
  • i (In(stream.Signature(ASQ))) – Input stream for sending samples to the resampler at sample rate fs_in.

  • o (In(stream.Signature(ASQ))) – Output stream for getting samples from the resampler. Samples are produced at a rate determined by fs_in * (n_up / m_down).

__init__(fs_in, n_up, m_down, bw=0.4, order_mult=5)
fs_inint

Expected sample rate of incoming samples, used for calculating filter coefficients.

n_upint

Numerator of the resampling ratio. Samples are produced at fs_in * (n_up / m_down). If n_up and m_down share a common factor, the internal resampling ratio is reduced.

m_downint

Denominator of the resampling ratio. Samples are produced at fs_in * (n_up / m_down). If n_up and m_down share a common factor, the internal resampling ratio is reduced.

bwfloat

Bandwidth (0 to 1, proportion of the nyquist frequency) of the resampling filter.

order_multint

Filter order multiplier, determines number of taps in underlying FIR filter. The underlying tap count is determined as order_factor*max(self.n_up, self.m_down), rounded up to the next multiple of n_up (required for even zero padding).