Linear Time-Invariant Systems
A system turns an input signal into an output signal: an amplifier, a room's acoustics, a smoothing filter, a car's suspension. Two properties, linearity and time invariance, make a system completely predictable from a single measurement and connect it to everything in this course. This is the central idea of Oppenheim and Willsky's book.
The two properties
A system maps to .
- Linear: . Scaling and superposition pass through.
- Time-invariant: if then . The system does not care when the input arrives.
Systems with both are LTI. Examples: (LTI), (not linear), (not time-invariant), (not linear: zero input gives nonzero output).
import numpy as np
rng = np.random.default_rng(0)
systems = {
"average y = (x[n] + x[n-1])/2": lambda x: (x + np.concatenate([[0], x[:-1]])) / 2,
"square y = x[n]^2": lambda x: x ** 2,
"ramp gain y = n x[n]": lambda x: np.arange(len(x)) * x,
"offset y = x[n] + 1": lambda x: x + 1,
}
def delay(x, k):
return np.concatenate([np.zeros(k), x[:-k]])
x1, x2 = rng.normal(size=20), rng.normal(size=20)
for name, S in systems.items():
linear = np.allclose(S(2 * x1 + 3 * x2), 2 * S(x1) + 3 * S(x2))
time_inv = np.allclose(S(delay(x1, 3))[3:], delay(S(x1), 3)[3:])
print(f"{name:34s} linear: {linear!s:5s} time-invariant: {time_inv}")average y = (x[n] + x[n-1])/2 linear: True time-invariant: True
square y = x[n]^2 linear: False time-invariant: True
ramp gain y = n x[n] linear: True time-invariant: False
offset y = x[n] + 1 linear: False time-invariant: True
Why LTI systems are convolutions
Any discrete input is a sum of shifted, scaled impulses: . Let , the impulse response. Time invariance gives , and linearity lets the sum pass through:
So an LTI system is convolution with its impulse response, and one measurement, the response to a single click, determines its response to every input.
import numpy as np
def system(x): # some LTI "black box": an echo plus smoothing
y = np.zeros(len(x) + 10)
y[:len(x)] += 0.5 * x
y[1:len(x) + 1] += 0.3 * x
y[6:len(x) + 6] += 0.2 * x
return y
impulse = np.zeros(1); impulse[0] = 1
h = system(impulse)[:7]
print("impulse response h:", h.tolist())
x = np.array([1.0, -2.0, 0.5, 3.0])
print("black box output: ", np.round(system(x)[:len(x) + 6], 4).tolist())
print("x convolved with h:", np.round(np.convolve(x, h), 4).tolist())impulse response h: [0.5, 0.3, 0.0, 0.0, 0.0, 0.0, 0.2]
black box output: [0.5, -0.7, -0.35, 1.65, 0.9, 0.0, 0.2, -0.4, 0.1, 0.6]
x convolved with h: [0.5, -0.7, -0.35, 1.65, 0.9, 0.0, 0.2, -0.4, 0.1, 0.6]
Eigenfunctions
Feed into an LTI system with impulse response :
The output is the same exponential times the number , the frequency response. LTI systems cannot create new frequencies; they only scale and phase-shift existing ones. Nonlinear systems (a distorting guitar amplifier) do create new ones, harmonics and intermodulation products.
In software
scipy.signal.lti,dltiandlfiltermodel and simulate LTI systems; control engineers describe them by transfer functions (The z-Transform).- Linear differential equations with constant coefficients (circuits, springs) are LTI systems; see Differential Equations.
Exercises
Exercise 1: Classify
Is linear? Time-invariant?
Answer
Linear, but not time-invariant.
Solution
Scaling and sums pass through, so it is linear. Delaying the input by gives , but delaying the output gives : different, so not time-invariant.
Exercise 2: Impulse response from the equation
Find the impulse response of .
Answer
.
Solution
Put : , , , and 0 afterwards. This is a second difference, a discrete second derivative.
Exercise 3: New frequencies (code)
Pass a 50 Hz tone through and list the frequencies in the output.
Answer
0 Hz and 100 Hz.
Solution
import numpy as np
fs = 1000
t = np.arange(0, 1, 1 / fs)
y = np.cos(2 * np.pi * 50 * t) ** 2
A = np.abs(np.fft.rfft(y)) / len(t)
print(np.fft.rfftfreq(len(t), 1 / fs)[A > 0.01].tolist())[0.0, 100.0]
: the squarer created a DC term and the second harmonic, which no LTI system can do.
Test yourself
Which system is LTI?
The output of an LTI system with impulse response is…
If the input to an LTI system is a pure 100 Hz tone, the output…
- can contain any frequency
- is a 100 Hz tone with possibly different amplitude and phase
- is always zero
- is a 200 Hz tone