Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I found my mistake. In the lines

a = np.ones(len(h))
rec = sig.lfilter(h, a, dem)

I should not have passed an array of ones to lfilter(). The correct way to do this turned out to be:

rec = sig.lfilter(h, [1.0], dem)

This gives the correct output. On a side note, since the output of a linear system is effectively the convolution of its input and its unit impulse response, I could have used

rec = sig.convolve(dem, h, mode='same')

I recalled this after struggling with lfilter(). The convolution approach may even be better, because the output of lfilter results in the signal having a phase delay that must be accounted for (this is especially notable when it comes to plotting). convolve() has no such issue.