x[0]8x[1]8x[2]8x[3]8x[4]8×0.5DELAY0×0.5y[0]–y[1]–y[2]–y[3]–y[4]–1prev = 0.02for xn in [8, 8, 8, 8, 8]:3 y = 0.5*prev + 0.5*xn4 prev = y5 print(y)00000000
-20246802468n (sample number)x[n]INPUTx[n] = 8 for n ≥ 0x[n] = 8 for n ≥ 08·δ[n]: one 8, then 0x[n] = 8 for n ≥ 0-20246802468n (sample number)y[n]OUTPUTsettles at 84, 2, 1, 0.5 … never 0x * h gives the same y[n]lfilter gives the same y[n]
Coloured parts: what the current step is about; everything else rests in whiteBlocks: input cells x[n], two ×0.5 blocks, the adder, the delay box, output cells y[n] and a Python code cardPlots: input and output as stems, one per sample nValue tokens ride the wires one sample at a time; the delay box shows the number it remembersThe rule y[n] = 0.5·y[n−1] + 0.5·x[n] runs from rest on a step of height 8: the output climbs 4, 6, 7, 7.5, 7.75 toward 8. Books and scipy put every output term on the left: y[n] − 0.5·y[n−1] = 0.5·x[n]. That is why lfilter's second list holds −0.5 for a feedback weight of +0.5.

A rule, one sample at a time

  1. A difference equation is a rule a system follows once per sample. Ours: y[n] = 0.5·y[n−1] + 0.5·x[n]. The new output is half the new input plus half the last output.

Running the rule

Two views of one system

In code

The working

# step 1/10 · rule

y[n] = 0.5·y[n−1] + 0.5·x[n]

x[n]    the input, sample number n
y[n]    the output, sample number n
y[n−1]  the output one sample earlier

four parts do the work:
  ×0.5   multiply the new input
  +      the adder
  delay  remembers the last output
  ×0.5   multiply that old output

The weights 0.5 and 0.5 and the step height 8 are chosen so every output is a short, exact number. Every value in the figure is computed from this model. "Initial rest" (input zero before n = 0 means output zero before n = 0) is the start condition Oppenheim and Schafer use to make a difference equation describe one linear, time-invariant system; scipy.signal.lfilter assumes it when zi is not given.