Many
digital filters are designed to give low-pass characteristics. Both
infinite impulse response and
finite impulse response low pass filters, as well as filters using
Fourier transforms, are widely used.
Simple infinite impulse response filter The effect of an infinite impulse response low-pass filter can be simulated on a computer by analyzing an RC filter's behavior in the time domain, and then
discretizing the model. From the circuit diagram to the right, according to
Kirchhoff's Laws and the definition of
capacitance: {{NumBlk|::|v_{\text{in}}(t) - v_{\text{out}}(t) = R \; i(t)|}} {{NumBlk|::|Q_c(t) = C \, v_{\text{out}}(t)|}} {{NumBlk|::|i(t) = \frac{\operatorname{d} Q_c}{\operatorname{d} t}|}} where Q_c(t) is the charge stored in the capacitor at time . Substituting equation into equation gives i(t) \;=\; C \frac{\operatorname{d}v_{\text{out}}}{\operatorname{d}t}, which can be substituted into equation so that :v_{\text{in}}(t) - v_{\text{out}}(t) = RC \frac{\operatorname{d}v_{\text{out}}}{\operatorname{d}t}. This equation can be discretized. For simplicity, assume that samples of the input and output are taken at evenly spaced points in time separated by \Delta_T time. Let the samples of v_{\text{in}} be represented by the sequence (x_1,\, x_2,\, \ldots,\, x_n), and let v_{\text{out}} be represented by the sequence (y_1,\, y_2,\, \ldots,\, y_n), which correspond to the same points in time. V_{\text{in}(t) with x_i :Replace V_{\text{out}}(t) with y_i :Replace \operatorname{d}V_{\text{out}} with y_{i} - y_{i-1} :Replace \operatorname{d}t with \Delta_T. --> Making these substitutions, :x_i - y_i = RC \, \frac{y_{i}-y_{i-1}}{\Delta_T}. Rearranging terms gives the
recurrence relation :y_i = \overbrace{x_i \left( \frac{\Delta_T}{RC + \Delta_T} \right)}^{\text{Input contribution}} + \overbrace{y_{i-1} \left( \frac{RC}{RC + \Delta_T} \right)}^{\text{Inertia from previous output}}. That is, this discrete-time implementation of a simple
RC low-pass filter is the
exponentially weighted moving average :y_i = \alpha x_i + (1 - \alpha) y_{i-1} \qquad \text{where} \qquad \alpha := \frac{\Delta_T}{RC + \Delta_T} . By definition, the
smoothing factor is within the range 0 \;\leq\; \alpha \;\leq\; 1. The expression for yields the equivalent
time constant in terms of the sampling period \Delta_T and smoothing factor , :RC = \Delta_T \left( \frac{1 - \alpha}{\alpha} \right). Recalling that :f_c=\frac{1}{2\pi RC} so RC=\frac{1}{2\pi f_c}, note and f_c are related by, :\alpha = \frac{2\pi \Delta_T f_c}{2\pi \Delta_T f_c + 1} and :f_c=\frac{\alpha}{(1 - \alpha)2\pi \Delta_T}. If =0.5, then the
RC time constant equals the sampling period. If \alpha \;\ll\; 0.5, then
RC is significantly larger than the sampling interval, and \Delta_T \;\approx\; \alpha RC. The filter recurrence relation provides a way to determine the output samples in terms of the input samples and the preceding output. The following
pseudocode algorithm simulates the effect of a low-pass filter on a series of digital samples: // Return RC low-pass filter output samples, given input samples, // time interval
dt, and time constant
RC function lowpass(
real[1..n] x,
real dt,
real RC)
var real[1..n] y
var real α := dt / (RC + dt) y[1] := α * x[1]
for i
from 2
to n y[i] := α * x[i] + (1-α) * y[i-1]
return y The
loop that calculates each of the
n outputs can be
refactored into the equivalent:
for i
from 2
to n y[i] := y[i-1] + α * (x[i] - y[i-1]) That is, the change from one filter output to the next is
proportional to the difference between the previous output and the next input. This
exponential smoothing property matches the
exponential decay seen in the continuous-time system. As expected, as the
time constant RC increases, the discrete-time smoothing parameter \alpha decreases, and the output samples (y_1,\, y_2,\, \ldots,\, y_n) respond more slowly to a change in the input samples (x_1,\, x_2,\, \ldots,\, x_n); the system has more
inertia. This filter is an
infinite-impulse-response (IIR) single-pole low-pass filter.
Finite impulse response Finite-impulse-response filters can be built that approximate the
sinc function time-domain response of an ideal sharp-cutoff low-pass filter. For minimum distortion, the finite impulse response filter has an unbounded number of coefficients operating on an unbounded signal. In practice, the time-domain response must be time truncated and is often of a simplified shape; in the simplest case, a
running average can be used, giving a square time response.
Fourier transform For non-realtime filtering, to achieve a low pass filter, the entire signal is usually taken as a looped signal, the Fourier transform is taken, filtered in the frequency domain, followed by an inverse Fourier transform. Only O(n log(n)) operations are required compared to O(n2) for the time domain filtering algorithm. This can also sometimes be done in real time, where the signal is delayed long enough to perform the Fourier transformation on shorter, overlapping blocks. ==Continuous-time realization==