First-order filters
The role of a filter is to shape a signal waveform into one that is more desired, frequently by attenuating high or low frequency components. Filters act very analogously to controllers and estimators, in that they map an input onto an output, and are frequently analyzed in similar ways.
To begin our study of filters, we start with the first-order filter.
Filter order
The order of a filter can be defined in several equivalent ways, but a useful intuition is that it equals the number of internal states required to describe the system. In physical systems, this often corresponds to the number of independent energy storage elements (such as capacitors, inductors, masses, or springs). The higher the order, the more complex the dynamics (or ability to shape the signal) that the filter has. See system order for an elaborated explanation.
Continuous-time filters
Consider a signal we’d like to filter. Intuitively, we view a filtered version of a signal as one that’s more smooth than the original signal. To formalize this, consider a signal and filtered version of the signal (the filter output). We can define a simple filter as such:
Here, we see that the rate of change of the output is proportional to the difference between the unfiltered and filtered signal. The higher is, the greater the corrections will be to the output and the more it will resemble the input signal. The lower is, the smaller the corrections will be to the output and the more sluggish the corrections to the output will be, leading the output to appear ‘more filtered’ to the human eye.
We typically reformulate into where is called the time constant.
For a step input , . We see that the filtered signal exponentially approaches the input.
Discrete-time filters
The discrete time (DT) version of the first-order filter may feel even more familiar. A typical way of notating it is as follows:
Here, parametrizes the filter, and has the inverse function of its CT-analog . In the formulation of the filter, we see that the output is equal to times its output at the previous timestep, plus a sample of the current value of the input signal (scaled by ). This way, we are incorporating a small bit of the current value of the signal at each time step.
If , then the filtered signal tracks the input exactly. If , then the filtered signal is latched and entirely disregards the input.
The response of the DT first-order filter to a step input is given by:
As you can see, like its CT analog, the DT first-order filter exponentially approaches the input. In fact, the filter we have just learned is referred to as the Exponential Moving Average (EMA) filter.
To get a feel for , play with the filter below. It runs the DT filter above at ms on a few test inputs, and reports the equivalent CT time constant through . Comparing the two step responses above, this is exactly the for which - the DT filter samples the CT one.
Things to try:
- With the step input, drag down and watch the output slow down. The dashed lines mark where the output reaches of the step, which happens one time constant after the step.
- Switch to noisy step. A small smooths the noise away but responds slowly to the step, while a large responds quickly but lets the noise through. This is the basic tradeoff of every low-pass filter.
- Switch to sine + noise and lower . The output shrinks and lags behind the input - the filter attenuates and delays the slow sine too, not just the noise.
A small filter design example
Suppose we have a signal we care about at 220 Hz, with an unwanted 2,200 Hz tone superimposed on it:
How should we choose the first-order filter configuration to accomplish the task? Taking the transfer function of our continuous-time equation gives
Here is the cutoff frequency, in Hz. The cutoff frequency is the frequency at which the frequency signal loses half of its power at the output of the filter. At the cutoff, the frequency component’s amplitude at the output is scaled to 71% (or -3dB) of its input amplitude.
Try playing around with the interactive exercise here with your audio on Try placing the cutoff at 550 Hz, between our two frequencies. The 220 Hz signal retains about 93% of its amplitude, while the 2,200 Hz interference falls to about 24%. Lowering the cutoff further suppresses the interference more, but eventually suppresses the signal we wanted too.
Time-domain response
Input: 220 Hz + 2,200 HzFiltered output
Frequency magnitude response
Press play to listen, then move the cutoff or switch between input and output.