# A few things about the FIR filter

The FIR filter or Finite Impulse Response Filter is a pure digital implementation of the classical passive filters. Many characteristics can be achieved that cannot be obtained by classical filters. eg: extremely sharp cut off, very linear phase. However, unlike perfect classical passive filters the response repeats at multiples of the sampling frequency. Thus a digital filter is sometimes complemented by monotonic passive filter to act above the sampling frequency.

## FIR filter design

The stereo generator DSP based design implements three FIR filters, each of different design. There is the LP input filter to limit the frequency range of the input signals and remove any possible presence of a 19KHz signal. Then there is an interpolation filter, implemented as a polyphase 1:4 linear phase filter. Finally there is an amplitude/phase correction filter to compensate for the deviations from ideal of the DAC and MPX filter.

## FIR filter formulas

The generaL formula for a FIR filter is a sum of k taps (coefficients). Where N is the order of the filter. The order N can be much higher than any practical passive or active component filter. Using a suitable CAD application the filter response can be distorted "to measure".  Although it is possible to design a FIR filter by hand, the probability that an error will be made in the calculation of, say a N = 60 filter will be > 99.9%. A graphical representation of the algorithms as a transversal filter. This is the most common form of FIR filter implementation since it is easily implemented in DSP hardware. There are otherways, especially if the the filter is linear phase. In this case the filter coefficients are symettrical, so only half the number of calculations are needed. However due to the complex indexing requirements of the intermediate calculations a DSP based algorithms are more complex, so negating the time saving of reduced coefficients.

Note: the Analogue Device, especially 215xx series incorporate hardware engines for both IIR and FIR filter calculations. Using these additions can reduce the substantially the CPU load on the main core CPU by triggering the hardware engines when a filter calculation is required. Once the calculation is completed the main CPU core is informed so the results can be collected. In this way the CPU core can be dedicated to other tasks.

```
float	pm	coeffs_19k =
{
//	19k input filter, fs=48k, fl=15.4117k, fh=18.7883k, stop=100db, ripple=0.01db
-2.696474731192200e-4,-4.783155515989900e-4,+2.870879686061400e-4,+2.013645526695300e-4,-7.434440570159200e-4,+6.776944205976700e-4,
+3.052170231451200e-4,-1.517135604157250e-3,+1.596625613921430e-3,+1.656066026400500e-4,-2.657636158397540e-3,+3.390137556611130e-3,
-7.220039956334800e-4,-3.931839969689380e-3,+6.388812432997830e-3,-3.123769881118350e-3,-4.709642421159000e-3,+1.072939756480064e-2,
-8.051176805837770e-3,-3.810569648305310e-3,+1.619053520901697e-2,-1.680774532950668e-2,+7.493966647231200e-4,+2.212272934066417e-2,
-3.159269987239089e-2,+1.283562664768594e-2,+2.753632188479245e-2,-5.920031699803515e-2,+4.516763991612235e-2,+3.135083628904962e-2,
-1.494331395425284e-1,+2.571312474374237e-1,+6.993945264468495e-1,+2.571312474374237e-1,-1.494331395425284e-1,+3.135083628904962e-2,
+4.516763991612235e-2,-5.920031699803515e-2,+2.753632188479245e-2,+1.283562664768594e-2,-3.159269987239089e-2,+2.212272934066417e-2,
+7.493966647231200e-4,-1.680774532950668e-2,+1.619053520901697e-2,-3.810569648305310e-3,-8.051176805837770e-3,+1.072939756480064e-2,
-4.709642421159000e-3,-3.123769881118350e-3,+6.388812432997830e-3,-3.931839969689380e-3,-7.220039956334800e-4,+3.390137556611130e-3,
-2.657636158397540e-3,+1.656066026400500e-4,+1.596625613921430e-3,-1.517135604157250e-3,+3.052170231451200e-4,+6.776944205976700e-4,
-7.434440570159200e-4,+2.013645526695300e-4,+2.870879686061400e-4,-4.783155515989900e-4,-2.696474731192200e-4,0.0
}

```

Here are the coefficients of a linear phase 19KHz filter, the filter parameters are given in the comment line. There is a spare variable in the array that can be used as a scratch pad in the pm (program memory). Note: since the filter is not monotonic there is the need for an aliasing frequency filter in the analogue domain at the ADC input to ensure removal of any frequencies above the sampling frequency

There are two further filter type of interest that are used in the stereo generator.