# Signals and Systems/Filter Design

The Laplace transform allows analyzing the frequency response of circuits based on the differential equations of their capacitive and inductive components. Filter design starts with finding the proper transfer function in order to amplify selected parts of a signal and to damp other ones as a function of their frequency.
Choosing the proper filter structure and deriving the coefficient values is a further topic prensented in the wikibook Signal Processing which deals with the application of signal and systems.

## Brick-wall filters

Separating signal from noise or different signals in the same transmission channel basing on their frequency content is best done with a brick-wall filter which shows full transmission in the passband and complete attenuation in the nearby stopbands, with abrupt transitions.
This can be done with the help of the Fourier transform which provides complete information of the frequency content of a given signal. Having calculated a Fourier transform, one can zero out unwanted frequency contents and calculate the inverse Fourier Transform, in order to provide the signal filtered with a brick-wall gauge.
The Fourier transform being given by:
    ${\mathcal {F}}(f(t))=F(j\omega )=\int _{-\infty }^{\infty }f(t)e^{-j\omega t}dt$
one finds out that the Fourier transform integral, with its infinite bounds, would have to be calculated from the day of the creation of our universe and all the way up to the day of its decay before the integral could have been fully calculated. And only then can the ideal brick-wall filtered signal be delivered.
In more technical terms, the ideal brick-wall filter suffers from an infinite latency.

## Analog filters

The analysis of analog circuits shows that their outputs are related to their input by a set of differential equations. The Laplace transform rewrites these differential equations as a set of linear equations of the complex variable $s$. With this, a polynomial function multiplying the Laplace transform of the input signal can be equated to another polynomial function multiplying the Laplace transform of the output signal:
    $(b_{m}s^{m}+b_{m-1}s^{m-1}+\ldots +b_{1}s+b_{0})\cdot X(s)=(a_{n}s^{n}+a_{n-1}s^{n-1}+\ldots +a_{1}s+a_{0})\cdot Y(s)$
Thus, the transfer function of a realizable analog filter can be written as the ratio of two polynomial functions of $s$:
    $H(s)={\frac {Y(s)}{X(s)}}={\frac {b_{m}s^{m}+b_{m-1}s^{m-1}+\ldots +b_{1}s+b_{0}}{a_{n}s^{n}+a_{n-1}s^{n-1}+\ldots +a_{1}s+a_{0}}}$
Hence, the problem of analog filter design is to find a pair of polynomial functions which, put together, best approximate the ideal but not realizable brick-wall transfer function.
In the early days of electric signal processing, scientists have come up with filter functions which are still largely used today. The functions they have devised are all of lowpass type. Frequency transformation techniques allow to find polynomials for other filter types such as highpass and bandpass.

## The Complex Plane

The transfer function of an analog filter is the ratio of two polynomial functions of $s$:
    $H(s)={\frac {Y(s)}{X(s)}}={\frac {num(s)}{den(s)}}$
The variable $s$ is a complex number which can be written as $s=\sigma +i\cdot \omega$. The complex plane is a plane with the imaginary axis vertical and the horizontal axis as the real part.
The roots of the transfer function numerator polynom are called the transfer function zeroes. The roots of the transfer function denominator polynom are called the transfer function poles.
The transfer function can be written as a function of its zeroes $z_{i}$, its poles $p_{i}$ and an additional gain factor $k$ in the form:
    $H(s)=k\cdot {\frac {\prod _{i=1}^{M}(s-z_{i})}{\prod _{i=1}^{N}(s-p_{i})}}$
The poles and the zeroes of a transfer function can be drawn in the complex plane. Their position provide information about the frequency response of the system. Indeed, the frequency response is equal to the transfer function taken for $s=i\omega$, which is along the imaginary axis.
    ${\frac {Y(i\omega )}{X(i\omega )}}=H(s=i\omega )$

### Effect of Poles

A stable LTI system has all its poles on the left side half plane of $s$.
If a pole would be located on the imaginary axis, at $p=i\omega _{p}$, then the factor $1/{(s-p)}$ of the transfer function would be infinite at the point $s=i\omega _{p}$ and so would the global frequency response $H(s=i\omega _{p})$. A special case of this is the integrator: it has a pole at $p=0$, and indeed has a long-term infinite output for a constant, non-zero, input.
For poles close to the imaginary axis, the frequency response takes a large amplitude for frequencies close to them. In other words, poles close to the imaginary axis indicate the passband.

### Effect of Zeros

If a zero is located on the imaginary axis, at $z=i\omega _{z}$, then the factor $(s-z)$ of the transfer function is zero at the point $s=i\omega _{z}$ and so is the global frequency response $H(s=i\omega _{z})$.
Zeroes on, or close to the imaginary axis indicate the stopband.

## Designing Filters

Devising the proper transfer function for a given filter function goes through the following steps:
* selecting a normalized filter function
* transforming and scaling the function for the particular needs
The coefficients of the numerator and denominator coefficients are finally used to calculate the element values of a selected filter circuit.

### Example: Lowpass Filter

A reduced version of CCITT G712 input filter specification, giving only the lowpass part, is shown in the plot on the side.
The passband goes up to $3kHz$ and allows a maximal ripple of $0.125dB$. The stopband requires an attenuation of $14dB$ at $4kHz$ and an attenuation of $32dB$ above $4.6kHz$.

#### Filter Function

As a first step, we have to choose a filter function.
Programs such as Octave or Matlab provide functions which allow to determine the minimal filter order required to fulfill a given specification. This is a good help when choosing from the possible functions.
Let's however here arbitrarily choose a Butterworth transfer function.

#### Normalized Filter Function

The following Octave script allows to plot the amplitudes of normalized Butterworth transfer functions from order 8 to 16.
The following figure shows the result: one needs at least a 13th order Butterworth filter to meet the specifications.
On the graph, one can note that all the amplitude responses go through the same point at -3 dB.
The specification frequencies have been scaled down to fit to the normalized cutoff frequency of 1 Hz. In the script, one might have noted an additional scaling factor of fc = 0.87: this is due to the fact that the corner cutoff amplitude is -0.125 dB and not -3 dB. That value has been adjusted by hand for this example. Again, Octave or Matlab scripts automate this task.

#### Denormalized Filter Function

The frequency scaling of the normalized transfer function is done by replacing
$s\to f_{c}\cdot s$
The following Octave script does this by multiplying the numerator and denominator coefficients by the appropriate power of $f_{c}$.
The coefficients of the numerator and denominator coefficients are now ready to be used to calculate the element values of a selected filter circuit.