## All-pass filter

All-pass filters (phase equalisers) provide a simple way of altering/improving the phase response of an IIR without affecting its magnitude response.

## All-pass Peaking/Bell filter

A  Peaking or Bell filter is a type of audio equalisation filter that boosts or attenuates the magnitude of a specified set of frequencies around a centre frequency in order to perform magnitude equalisation. As seen in the plot in the below, the filter gets its name from the shape of the its magnitude spectrum (blue line) which resembles a Bell curve.

Frequency response (magnitude shown in blue, phase shown in purple) of a 2nd order Bell filter peaking at 125Hz.

## All-pass filters

Central to the Bell filter is the so called All-pass filter. All-pass filters provide a simple way of altering/improving the phase response of an IIR without affecting its magnitude response. As such, they are commonly referred to as phase equalisers and have found particular use in digital audio applications.

A second order all-pass filter is defined as:

$$A(z)=\Large\frac{r^2-2rcos \left( \frac{2\pi f_c}{fs}\right) z^{-1}+z^{-2}}{1-2rcos \left( \frac{2\pi f_c}{fs}\right)z^{-1}+r^2 z^{-2}}$$

Notice how the numerator and denominator coefficients are arranged as a mirror image pair of one another.  The mirror image property is what gives the all-pass filter its desirable property, namely allowing the designer to alter the phase response while keeping the magnitude response constant or flat over the complete frequency spectrum.

A Bell filter can be constructed from the $$A(z)$$ filter by the following transfer function:

$$H(z)=\Large\frac{(1+K)+A(z)(1-K)}{2}$$

After some algebraic simplication, we obtain the transfer function for the Peaking or Bell filter as:

$$H(z)=\Large{\frac{1}{2}}\left[\normalsize{(1+K)} + \underbrace{\Large\frac{k_2 + k_1(1+k_2)z^{-1}+z^{-2}}{1+k_1(1+k_2)z^{-1}+k_2 z^{-2}}}_{all-pass filter}\normalsize{(1-K)} \right]$$

• $$K$$ is used to set the gain and sign of the peak
• $$k_1$$ sets the peak centre frequency
• $$k_2$$ sets the bandwidth of the peak

## Implementation

A Bell filter may easily be implemented in ASN FilterScript as follows:

ClearH1;  // clear primary filter from cascade
interface BW = {0,2,0.1,0.5}; // filter bandwidth
interface fc = {0, fs/2,fs/100,fs/4}; // peak/notch centre frequency
interface K = {0,3,0.1,0.5}; // gain/sign

Main()

k1=-cos(2*pi*fc/fs);
k2=(1-tan(BW/2))/(1+tan(BW/2));

Pz = {1,k1*(1+k2),k2}; // define denominator coefficients
Qz = {k2,k1*(1+k2),1}; // define numerator coefficients
Num = (Pz*(1+K) + Qz*(1-K))/2;
Den = Pz;
Gain = 1;


This code may now be used to design a suitable Bell filter, where the exact values of $$K, f_c$$ and $$BW$$ may be easily found by tweaking the interface variables and seeing the results in real-time, as described below.

## Designing the filter on the fly

Central to the interactivity of the FilterScript IDE (integrated development environment) are the so called interface variables. An interface variable is simply stated: a scalar input variable that can be used modify a symbolic expression without having to re-compile the code – allowing designers to design on the fly and quickly reach an optimal solution.

As seen in the code example above, interface variables must be defined in the initialisation section of the code, and may contain constants (such as, fs and pi) and simple mathematical operators, such as multiply * and / divide. Where, adding functions to an interface variable is not supported.

An interface variable is defined as vector expression:

interface name = {minimum, maximum, step_size, default_value};

Where, all entries must be real scalars values. Vectors and complex values will not compile.

All interface variables are modified via the interface variable controller GUI. After compiling the code, use the interface variable controller to tweak the interface variables values and see the effects on the transfer function. If testing on live audio, you may stream a loaded audio file and adjust the interface variables in real-time in order to hear the effects of the new settings.

## FIR Comb Filter: powerline harmonic cancellation and CIC

Comb filters: powerline (50/60Hz) harmonic cancellation filters, audio applications; cascaded integrator–comb (CIC) filters: anti-aliasing, anti-imaging

## Fractional Farrow Delay Filter

FIR Farrow delay filter: nudge or fine-tune the sampling instants by a fraction of a sample. May be May be combined with traditional integer delay line

## The moving average filter

The moving average (MA) filter is perhaps one of the most widely used FIR filters due to its conceptual simplicity and ease of implementation. As seen in the diagram below, notice that the filter doesn’t require any multiplications, just additions and a delay line, making it very suitable for many extreme low-power embedded devices with basic computational capabilities. However, despite its simplicity, the moving average filter is optimal for reducing random noise while retaining a sharp step response, making it a versatile building block for smart sensor signal processing applications.

A moving average filter of length $$L$$ for an input signal $$x(n)$$ may be defined as follows:

$$y(n)=\large{\frac{1}{L}}\normalsize{\sum\limits_{k=0}^{L-1}x(n-k)}$$ for $$\normalsize{n=0,1,2,3….}$$

Where, a simple rule of thumb states that the amount of noise reduction is equal to the square-root of the number of points in the average. For example, an MA of length 9 will result in a factor 3 noise reduction. Frequency response of an MA filter of length 9. Notice the poor stopband attentuation at around -20dB.

• Most commonly used digital lowpass filter.
• Optimal for reducing random noise while retaining a sharp step response.
• Good smoother (time domain).
• Unity valued filter coefficients, no MAC (multiply and accumulate) operations required.
• Conceptually simple to implement.

• Inflexible frequency response: nudging a conjugate zero pair results in non-unity coefficients.
• Poor lowpass filter (frequency domain): slow roll-off and terrible stopband attenuation characteristics.

## Implementation

The MA filter may be implemented in ASN FilterScript as follows:

ClearH1;  // clear primary filter from cascade
Main();
Hd=movaver(8,"symbolic");  // design an 8th order MA
Num = getnum(Hd);   // define numerator coefficients
Den = {1};          // define denominator coefficients
Gain = getgain(Hd); // define gain


A more computationally efficient implementation of the MA filter is discussed here. 