I'm experimenting with decimating a signal, in this case a unit impulse.
I'm using Python, with pylab. First, I create a unit impulse, and decimate it by 5.
x = r_[zeros(0), 1, zeros(100)]
N = 2 ** 14
q = 5
y = decimate(x, q, ftype="fir")
subplot(211)
title("Original")
stem(range(len(x)), x)
subplot(212)
title("Decimated - FIR")
stem(range(len(y)), y)
figure()
subplot(211)
semilogx(log(abs(fft(x, N))))
subplot(212)
y = decimate(x, q, ftype="fir")
semilogx(log(abs(fft(y, N))))
This results with the following plots
I then add a few samples of delay before the impulse, by changing x to:
x = r_[zeros(3), 1, zeros(100)]
This results in the following plots
In the second set of plots, the resulting decimated signal is no longer a single sample, but has been distorted.
If I delay the signal with 5 - and any multiple of q - samples, I get the first set of plots again.
The source code for the decimate function is, https://github.com/scipy/scipy/blob/master/scipy/signal/signaltools.py#L1570
def decimate(x, q, n=None, ftype='iir', axis=-1):
if not isinstance(q, int):
raise TypeError("q must be an integer")
if n is None:
if ftype == 'fir':
n = 30
else:
n = 8
if ftype == 'fir':
b = firwin(n + 1, 1. / q, window='hamming')
a = 1.
else:
b, a = cheby1(n, 0.05, 0.8 / q)
y = lfilter(b, a, x, axis=axis)
sl = [slice(None)] * y.ndim
sl[axis] = slice(None, None, q)
return y[sl]
I'm using a fir low pass filter before decimating, the impulse response of the filter is
This explains why the impulse is distorted when there is a delay, the decimation is selecting parts of the impulse response, when the delay is a multiple of the decimation, it only selects the zero's of the impulse response, and one non-zero sample at the peak.
Is there a way to decimate a unit sample with an arbitrary delay, which results in a scaled unit sample output?