Notes / Signal Processing

First-order filters

Updated

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 uu and filtered version of the signal yy (the filter output). We can define a simple filter as such:

dydt=a(u−y)\frac{dy}{dt}=a(u-y)

Here, we see that the rate of change of the output yy is proportional to the difference between the unfiltered and filtered signal. The higher aa is, the greater the corrections will be to the output and the more it will resemble the input signal. The lower aa 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 aa into 1τ\frac{1}{\tau} where τ\tau is called the time constant.

dydt=1τ(u−y)\frac{dy}{dt}=\frac{1}{\tau}(u-y)

For a step input u(t)u(t), y(t)=1−e−t/τy(t)=1-e^{-t/\tau}. 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:

y[k]=(1−α)y[k−1]+αu[k]y[k]=(1-\alpha)y[k-1]+\alpha u[k]

Here, α\alpha parametrizes the filter, and has the inverse function of its CT-analog τ\tau. In the formulation of the filter, we see that the output is equal to 1−α1-\alpha times its output at the previous timestep, plus a sample of the current value of the input signal (scaled by α\alpha). This way, we are incorporating a small bit of the current value of the signal at each time step.

If α=1\alpha=1, then the filtered signal tracks the input exactly. If α=0\alpha=0, then the filtered signal is latched and entirely disregards the input.

The response of the DT first-order filter to a step input u[k]u[k] is given by:

y[k]=1−(1−α)ky[k]=1-(1-\alpha)^k

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 α\alpha, play with the filter below. It runs the DT filter above at Δt=10\Delta t = 10 ms on a few test inputs, and reports the equivalent CT time constant through α=1−e−Δt/τ\alpha = 1 - e^{-\Delta t/\tau}. Comparing the two step responses above, this is exactly the α\alpha for which 1−(1−α)k=1−e−kΔt/τ1-(1-\alpha)^k = 1-e^{-k\Delta t/\tau} - the DT filter samples the CT one.

Things to try:

  • With the step input, drag α\alpha down and watch the output slow down. The dashed lines mark where the output reaches 1−e−1≈63%1-e^{-1} \approx 63\% of the step, which happens one time constant after the step.
  • Switch to noisy step. A small α\alpha smooths the noise away but responds slowly to the step, while a large α\alpha responds quickly but lets the noise through. This is the basic tradeoff of every low-pass filter.
  • Switch to sine + noise and lower α\alpha. 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:

u(t)=12sin⁡(2π⋅220t)+12sin⁡(2π⋅2200t).u(t)=\tfrac12\sin(2\pi\cdot220t)+\tfrac12\sin(2\pi\cdot2200t).

How should we choose the first-order filter configuration to accomplish the task? Taking the transfer function of our continuous-time equation gives

H(s)=11+τs,fc=12πτ.H(s)=\frac{1}{1+\tau s}, \qquad f_c=\frac{1}{2\pi\tau}.

Here fcf_c 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.

∣H(j2πf)∣=11+(f/fc)2,∠H(j2πf)=−tan⁡−1(f/fc).|H(j2\pi f)|=\frac{1}{\sqrt{1+(f/f_c)^2}}, \qquad \angle H(j2\pi f)=-\tan^{-1}(f/f_c).

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

220 Hz · signal
2,200 Hz · interference

Press play to listen, then move the cutoff or switch between input and output.