Difference equations and discrete-time systems
Solves linear constant-coefficient difference equations by iteration and z-transforms, separates zero-input and zero-state responses, and reads transfer function, stability and gain.
Drafted with Aria, reviewed by the AiCanCode.org team. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Every digital filter, smoothing routine or digital controller running on a microcontroller is, in the end, a difference equation: a rule that computes the new output from the current input and a few stored past values. Being able to go from that equation to its impulse response, transfer function, stability and steady-state gain is how you check that firmware will do what the design said.
Key ideas
Linear constant-coefficient difference equation (LCCDE). A causal discrete-time LTI system is usually described by
y[n] + a1 y[n − 1] + … + aN y[n − N] = b0 x[n] + b1 x[n − 1] + … + bM x[n − M].
N (the largest output delay) is the order. Written as y[n] = Σ bk x[n − k] − Σ ak y[n − k], it is a recipe that a processor can run sample by sample.
Recursive and non-recursive systems
- Non-recursive (all
ak = 0): the output depends only on inputs. The impulse response is the coefficient list{b0, b1, …, bM}— finite length, so it is an FIR system. FIR systems are always stable. Example: a 4-point moving averagey[n] = (x[n] + x[n − 1] + x[n − 2] + x[n − 3])/4. - Recursive (some
ak ≠ 0): past outputs feed back, so the impulse response is usually infinitely long — an IIR system. Stability must be checked. Example: the exponential smoothery[n] = α x[n] + (1 − α) y[n − 1].
Solving the equation
- Iteration — start from initial conditions and step forward. Always works and is the best way to check answers.
- Classical: total response = homogeneous (natural) solution
Σ Ci·riⁿ(rootsriof the characteristic equation) + particular (forced) solution, with constants fixed by initial conditions. - z-transform: transform both sides (unilateral transform brings in initial conditions), solve algebraically, invert.
Zero-input and zero-state responses. The total response = zero-input response (due only to stored initial conditions, with x = 0) + zero-state response (due only to the input, with the system initially at rest). Only the zero-state part is described by H(z); linearity and time invariance of the input–output map require zero initial conditions.
Transfer function and characteristic equation. With zero initial conditions, H(z) = Y(z)/X(z) = (b0 + b1 z⁻¹ + … + bM z⁻ᴹ)/(1 + a1 z⁻¹ + … + aN z⁻ᴺ). Multiplying the denominator by zᴺ gives the characteristic polynomial zᴺ + a1 zᴺ⁻¹ + … + aN; its roots are the poles and the natural modes rⁿ.
Stability (causal system). BIBO stable ⇔ all poles strictly inside the unit circle. For a second-order denominator z² + a1 z + a2 the stability triangle is |a2| < 1 and |a1| < 1 + a2.
Steady state. DC gain is H(1) = Σ bk / (1 + Σ ak). A sinusoid cos(ω0 n) produces |H(e^(jω0))| cos(ω0 n + ∠H(e^(jω0))) in steady state.
Realisation (block diagrams). Built from adders, multipliers and unit delays z⁻¹. Direct Form I uses M + N delays; Direct Form II (canonical) shares the delay line and uses max(M, N) delays — the minimum.
Formulas
y[n] = Σ from k=0 to M of bk x[n − k] − Σ from k=1 to N of ak y[n − k]— LCCDE in recursive form.H(z) = (Σ bk z^(−k)) / (1 + Σ ak z^(−k))— transfer function.H(e^(jω)) = H(z)atz = e^(jω)— frequency response.H(1) = Σ bk / (1 + Σ ak)— DC gain.y[n] = (1 − α)ⁿ⁺¹ y[−1] + α Σ from k=0 to n of (1 − α)^k x[n − k]— exponential smoother solution.h[n] = A·p1ⁿ + B·p2ⁿ(n ≥ 0) — impulse response for distinct polesp1,p2.|a2| < 1,|a1| < 1 + a2— stability of1 + a1 z⁻¹ + a2 z⁻².
Symbols: x[n], y[n] input and output samples (any unit); ak, bk coefficients (dimensionless); N order; M number of past inputs; p, r poles/roots (dimensionless); α smoothing factor (0 to 1); ω digital frequency (rad/sample).
Worked examples
Example 1 (standard). y[n] = 0.5 y[n − 1] + x[n]. Find (a) the step response with y[−1] = 0, and (b) the total response to a step when y[−1] = 4.
- (a)
H(z) = 1/(1 − 0.5z⁻¹),h[n] = (0.5)ⁿ u[n]. Step responses[n] = Σ from k=0 to n of (0.5)^k = (1 − 0.5^(n+1))/(1 − 0.5) = 2(1 − 0.5^(n+1)). - Check by iteration:
y[0] = 1,y[1] = 0.5 + 1 = 1.5,y[2] = 0.75 + 1 = 1.75✓; final value= H(1) = 1/(1 − 0.5) = 2✓. - (b) Zero-input part with
y[−1] = 4:y_zi[n] = 4(0.5)^(n+1) = 2(0.5)ⁿ. - Total
= 2(0.5)ⁿ + 2(1 − 0.5^(n+1)) = 2 + (0.5)ⁿ:y[0] = 3,y[1] = 2.5,y[2] = 2.25. - Iteration check:
y[0] = 0.5 × 4 + 1 = 3,y[1] = 1.5 + 1 = 2.5✓. (a) s[n] = 2(1 − 0.5^(n+1)); (b) y[n] = 2 + (0.5)ⁿ for n ≥ 0.
Example 2 (GATE level). y[n] = 0.9 y[n − 1] − 0.2 y[n − 2] + x[n]. Find the poles, h[n], h[2], the DC gain and whether the system is stable.
H(z) = 1/(1 − 0.9z⁻¹ + 0.2z⁻²); characteristic equationz² − 0.9z + 0.2 = 0⇒z = 0.5, 0.4.- Both poles inside the unit circle ⇒ stable (triangle test:
|0.2| < 1,|−0.9| < 1.2✓). H = A/(1 − 0.5z⁻¹) + B/(1 − 0.4z⁻¹);A = 1/(1 − 0.4/0.5) = 5;B = 1/(1 − 0.5/0.4) = −4.h[n] = [5(0.5)ⁿ − 4(0.4)ⁿ] u[n];h[2] = 5(0.25) − 4(0.16) = 1.25 − 0.64 = 0.61.- Iteration check:
h[0] = 1,h[1] = 0.9,h[2] = 0.9 × 0.9 − 0.2 × 1 = 0.61✓. - DC gain
H(1) = 1/(1 − 0.9 + 0.2) = 1/0.3. Poles 0.5 and 0.4; h[n] = 5(0.5)ⁿ − 4(0.4)ⁿ; h[2] = 0.61; DC gain ≈ 3.33; stable.
Common mistakes
- Sign errors when moving
yterms across:y[n] − 0.5y[n − 1] = x[n]gives1 − 0.5z⁻¹in the denominator, not1 + 0.5z⁻¹. - Including non-zero initial conditions in
H(z). The transfer function is defined at rest. - Forgetting that the zero-input response uses
y[−1],y[−2], noty[0]. - Calling every recursive system IIR — a pole-zero cancellation can make it FIR (e.g. the recursive form of a moving average).
- Testing stability on the coefficients of
z⁻¹without first forming the polynomial inz. - Counting delays: Direct Form I needs
M + N, Direct Form II onlymax(M, N).
For GATE IN
Expect: deriving H(z) or the impulse response from a difference equation, a specific sample value (h[2], y[3]) — quickly checked by iteration, stability from pole locations or coefficient conditions, DC or high-frequency gain (H(1), H(−1)), FIR/IIR identification and the number of delays in a realisation. Practise iteration as a cross-check on every transform answer.
Quick check
- Is
y[n] = x[n] − x[n − 2]FIR or IIR? Its DC gain? - Order of
y[n] − 0.3y[n − 2] = x[n − 1]? - Pole of
y[n] = 1.2 y[n − 1] + x[n]— stable? - High-frequency gain
H(−1)ofy[n] = 0.5y[n − 1] + x[n]? - Delays needed in Direct Form II for M = 2, N = 3?
Answers: 1. FIR;
H(1) = 1 − 1 = 0. 2. Second order. 3.z = 1.2, outside the unit circle — unstable. 4.1/(1 + 0.5) = 0.667. 5. 3.
Interview questions
All Signals and Systems interview questionsTry answering each one aloud before you open it.
1.What is a linear constant-coefficient difference equation, and what does its order mean?Concept
It is an equation of the form y[n] + a1y[n − 1] + … + aNy[n − N] = b0x[n] + … + bMx[n − M] with fixed coefficients; it describes a causal discrete-time LTI system when the system starts at rest. The order N is the largest delay on the output, which equals the number of poles and the minimum number of delay elements needed to store past outputs. Rearranged as y[n] = Σbkx[n − k] − Σaky[n − k], it is exactly the loop a processor runs each sample.
2.What is the difference between FIR and IIR systems described by difference equations?Concept
An FIR system is non-recursive: the output depends only on present and past inputs, so its impulse response is just the list of b coefficients and has finite length. It is always stable and can have exactly linear phase. An IIR system feeds back past outputs, giving an infinitely long impulse response; it achieves a sharp response with far fewer coefficients, but its stability must be checked (all poles inside the unit circle) and its phase is non-linear.
3.What are the zero-input and zero-state responses of a discrete-time system?Concept
The zero-input response is the output caused only by stored initial conditions such as y[−1], with the input set to zero; it is made of the natural modes pⁿ of the characteristic equation. The zero-state response is the output caused only by the input with the system initially at rest, and equals x[n] * h[n]. The total response is their sum; the transfer function H(z) describes only the zero-state part.
4.How do you check the stability of a causal system given by a difference equation?Concept
Form the characteristic polynomial in z from the feedback coefficients, for example z² + a1z + a2, and find its roots, which are the poles. The causal system is BIBO stable if and only if every pole has magnitude less than 1. For second order you can avoid solving: it is stable if |a2| < 1 and |a1| < 1 + a2. A non-recursive (FIR) equation has no feedback poles and is always stable.
5.What is the difference between Direct Form I and Direct Form II realisations?Concept
Direct Form I implements the numerator (feed-forward) and denominator (feedback) sections separately, each with its own delay line, so it needs M + N delays. Direct Form II swaps the order of the two sections so they share a single delay line, needing only max(M, N) delays, which is why it is called canonical. Direct Form II uses less memory but its internal signals can be larger, so overflow and coefficient quantisation need more care in fixed-point hardware.
6.A sensor reading is smoothed with y[n] = 0.2x[n] + 0.8y[n − 1]. What is its DC gain, and how many samples does it take for a step to reach about 90 % of the final value?Concept
H(z) = 0.2/(1 − 0.8z⁻¹), so the DC gain is H(1) = 0.2/0.2 = 1 and a constant input is reproduced exactly. Starting from rest, the step response is 1 − 0.8^(n+1). Setting 0.8^(n+1) = 0.1 gives n + 1 = ln 0.1/ln 0.8 ≈ 10.3, so it takes about 10 samples (y[10] = 1 − 0.8¹¹ ≈ 0.914). Larger feedback coefficients smooth more noise but respond more slowly.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?