Digital Signal Processing Basics
DSP transforms sampled signals numerically to filter, measure, and extract information, and in real-time control it must complete within each sample period.
Signals as Numbers
Digital signal processing (DSP) treats a signal as a sequence of numbers, produced by sampling a continuous quantity at regular intervals. Operations that were once done with analog circuits, such as filtering, mixing, and spectral analysis, become arithmetic on these sequences. The advantages are precision, repeatability, and flexibility: a filter is a set of coefficients, changed without rewiring.
The Core Operations
- Filtering: emphasize or suppress frequency bands to remove noise or isolate signals
- Convolution: the fundamental operation behind linear filtering
- Fourier transform: decompose a signal into its frequency components
- Correlation: measure similarity, used in detection and timing
FIR and IIR Filters
Digital filters come in two families. A finite impulse response (FIR) filter computes each output as a weighted sum of recent inputs; it is always stable and can have exactly linear phase, at the cost of needing many taps for sharp responses. An infinite impulse response (IIR) filter also feeds back past outputs; it achieves sharp responses with few coefficients but can be unstable and has nonlinear phase. The choice depends on whether phase linearity or computational economy matters more.
# single-pole IIR low-pass filter, one sample step
# y[n] = y[n-1] + alpha * (x[n] - y[n-1])
alpha = 0.1 # smaller alpha = more smoothing
y = 0.0
def step(x):
global y
y = y + alpha * (x - y)
return y
Real-Time Constraints
In control, DSP is not offline. Each new sample must be processed before the next arrives, so the algorithm's worst-case cost must fit within the sample period. This favors algorithms with bounded, data-independent cost, such as fixed-length FIR filters, over ones whose runtime varies. Fixed-point arithmetic is common for speed and determinism on hardware, though it requires care about scaling and overflow.
Why It Precedes Control
The quality of a control loop is limited by the quality of its measurements. DSP conditions raw sensor data, removing noise and interference and extracting the quantity of interest, before it reaches the control law. Poorly filtered measurements inject noise that the controller amplifies; good filtering, correctly bounded in time, is part of making the loop both accurate and stable.