| 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.
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.