5
$\begingroup$

When I create a digital first-order IIR low-pass filter with scipy (code below), I get the following coefficients:

B: [ 0.1367  0.1367]
A: [ 1.     -0.7265]

The impulse response of this filter does not look like most text-book examples in that the first value is not the largest.

Why is this so? Does it have to be so?

If I want to make an FIR filter to mimic such a first-order IIR low-pass filter, should it be a normal exponential decay shape, or does it need the first value "tweaked" in this manner?

Impulse response

import numpy as np
from scipy.signal import butter, lfilter
import matplotlib.pyplot as plt

b, a  = butter(1, .1, btype='lowpass')
print('B:', b)
print('A:', a)

x = np.zeros(1000)
x[0] = 1.

xf = lfilter(b, a, x)

plt.figure()
plt.plot(x,'o', label='impulse')
plt.plot(xf,'s-', label='response')
plt.xlim(-1, 10)
plt.ylim(-.1, .3)
plt.legend()
$\endgroup$
6
$\begingroup$

A causal first-order IIR filter is characterized by the following difference equation:

$$y[n]=b_0x[n]+b_1x[n-1]-a_1y[n-1]\tag{1}$$

with $x[n]$ the input signal, and $y[n]$ the output signal. The impulse response of that system can be computed via the $\mathcal{Z}$-transform or otherwise, and it turns out to be

$$h[n]=b_0\delta[n]+(-a_1)^{n-1}(b_1-b_0a_1)u[n-1]\tag{2}$$

where $\delta[n]$ is the unit impulse, and $u[n]$ is the unit step sequence. Assuming that the filter is stable, we can conclude that $|a_1|<1$ is satisfied. Consequently, $|h[0]|>|h[n]|$ for $n>0$ is satisfied if and only if

$$|b_0|>|b_1-b_0a_1|\tag{3}$$

holds.

With $b_0=b_1$ and $a_1<0$ as in your example, condition $(3)$ can never be satisfied, and, consequently, the maximum magnitude of the impulse response is not assumed at index $n=0$.

EDIT:

I add more details referring to your filter design problem. A Butterworth low pass filter's frequency response satisfies $H(1)=1$ (DC) and $H(-1)=0$ (Nyquist). With

$$H(z)=\frac{b_0+b_1z^{-1}}{1+a_1z^{-1}}\tag{4}$$

we have the following requirements on the coefficients:

$$H(1)=\frac{b_0+b_1}{1+a_1}=1\\ H(-1)=\frac{b_0-b_1}{1-a_1}=0\tag{5}$$

which gives

$$b_0=b_1\quad\textrm{ and }\quad a_1=2b_0-1\tag{6}$$

From the stability condition $|a_1|<1$ we get

$$|2b_0-1|<1\Longrightarrow 0<b_0<1\tag{7}$$

Combining the constraints $(6)$ and $(7)$ with the inequality $(3)$ yields

$$1 >b_0>\frac12\tag{8}$$

If $(8)$ is satisfied, $h[0]$ will have the largest magnitude, otherwise it won't. Now it turns out that the exact value of $b_0$ depends on the desired cut-off frequency of the low pass filter. For cut-off frequencies less than $\frac12$ (i.e., less than half the Nyquist frequency), you get $b_0<\frac12$, and hence $|h[0]|$ is smaller than the maximum magnitude of the impulse response. Only for cut-off frequencies greater than half the Nyquist frequency do you get $|h[0]|>|h[n]|$, $n>0$.

So to directly answer the question in your title: the first impulse response value is not the largest (in magnitude) because the filter coefficients do not satisfy inequality $(3)$, and in your example of a (first-order) Butterworth low pass filter this happens because the cut-off frequency is smaller than half the Nyquist frequency.

$\endgroup$
  • $\begingroup$ I'm afraid this doesn't help me understand the bigger picture. I know how the coefficients produce the observed impulse response. But why are the coefficients the way they are? Does it have something to do with analog vs. digital? $\endgroup$ – adr Sep 3 '18 at 12:37
  • $\begingroup$ I believe it is because he has zeros in his filter implementation (it is not completely IIR but FIR/IIR) and a true minimum phase IIR would have trailing echos only. (??) Is that true @MattL? $\endgroup$ – Dan Boschen Sep 3 '18 at 13:31
  • 1
    $\begingroup$ @DanBoschen: The zeros don't really matter, it depends on the value of the cut-off frequency. For cut-off frequencies less than half the Nyquist frequency, the first value of the impulse response has a smaller magnitude than the second value. See my edited answer. $\endgroup$ – Matt L. Sep 3 '18 at 15:18
  • 1
    $\begingroup$ @adr: Sure, any good low pass filter has a zero at Nyquist. Note though that this is just an ordinary IIR filter. IIR filters normally have a recursive and a feed forward path. What you mean is called an "all pole filter", i.e., a filter with only poles away from the origin of the z-plane, with just a constant in the numerator. $\endgroup$ – Matt L. Sep 3 '18 at 15:23
  • 1
    $\begingroup$ @MattL In retrospect, my question should have been: why does the first value not lie on the exponential curve defined by the subsequent values? Anyway, things are clearer to me now, which is what the objective was! $\endgroup$ – adr Sep 3 '18 at 19:00
2
$\begingroup$

The impulse response of this filter does not look like most text-book examples in that the first value is not the largest.

That's simply an issue with interpreting the text books the wrong way. There is nothing special about the first sample, and there is no reason at all, why it would have to be the largest. I'm quite sure that none of the text box actually says anything about this.

Some very simple "beginner" filters just happen to have this property, so you looked at a bunch of pictures and formed a conclusion & generalization that's neither supported by the text or the math.

$\endgroup$
1
$\begingroup$

The confusion might arise from what people mean by first order. In some places, like:

a first order filter follows the input ($x$)/output ($y$) equation:

$$ y[n] = (1-\lambda)y[n-1]+\lambda x[n]\,,$$ or equivalently in tracking form: $$ y[n] = y[n-1]+\lambda (x[n]-y[n-1])\,.$$

It has numerous names, including first order exponential averaging low-pass filter or exponentially weighted moving average (EWMA). More details are given in

In that case, the impulse response $h$ of the filter is explicit. For $k< 0 $, $h[k] = 0$, and for $k\ge 0 $, $h[k] = \lambda(1-\lambda)^k$, where $0<\lambda < 1$ is a smoothing factor. In this situation, the "first" value $h[0] $ is indeed the largest, since the exponential sequence $\lambda(1-\lambda)^k$ is decreasing:

Impulse responses for exponential first order filters

Other filter families are called first order, with additional constraints, like Butterworth's for which Mmatt's answer is complete.

$\endgroup$
1
$\begingroup$

Starting from an FIR filter with an absolutely flat frequency response:

  • [ 1 0 0 0 0 ] has a delay of one sample,
  • [ 0 0 1 0 0 ] has a delay of three samples.

The largest coefficient corresponds to the filter's group delay. For a lowpass filter like [ 1 -2 7 -2 1] it is the group delay for the DC component — if you look at the step [ 0 0 0 1 1 1 1 1 1 1 ] response [ 0 0 0 1 -1 6 4 5 5 5] it is fairly obvious what the filter's DC delay is. If you design an FIR lowpass filter with uniform group delay for all passband frequencies, it will have a single largest coefficient in the middle bin, while the length of the filter corresponds to the filter's selectivity.

The same filter with no delay would be non-causal, as the small coefficients before the large one would have negative indexes.

For IIR filters, it's slightly less obvious, because they have two coefficient sets and are unlikely to have flat group delay, but you can still get better stopband attenuation and sharper falloffs with larger delays.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.