On Using a Genetic Algorithm in the Designing of Linear Digital Filters

Digital filters, either as filters with moving average (Finite Impulse Response) or autore‐ gressive filters (Infinite Impulse Response), are widely used in noise suppression, signal processing or extracting information from data streams. Although well‐known theory allows for optimal pa‐ rameter selection, there still exist such real applications where requirements limit the use of digital filters. One of the most important limitations is the response time delay caused by too many used lagged input signals. The method proposed in the article allows us to estimate filter parameters with a genetic algorithm, decreasing its delay but keeping the requirements important for the user (e.g.: attenuation). Transfer functions of such filters were compared with transfer functions of the most known classical filters.


Introduction
A filter is a device (usually an electronic circuit) or an algorithm (a digital filter) which processes an input signal in order to remove (or attenuate) unwanted components of certain frequency or frequency range. Filters are widely used in signal processing to suppress the noise or condition non-sinusoidal signals. A very simple classification of filters divides them into (see Figure 1): low-pass, high-pass, band-pass and band-stop (notch).   Although analogue filters (usually electronics) are widely used in real applications, the development of fast microprocessors has led to the spread of digital filters -that are in fact an algorithm, a number of mathematical operations done on a sample of a converted input signal in order to enhance or reduce certain aspects of this signal. Digital filters, contrary to analogue ones, allow us to receive high attenuation in the stop-band, are long-term stable and can be relatively quickly designed. However, a band of processed signal must be limited to prevent aliasing (according to the Shannon-Kotelnikov theorem), its properties depend on the quality of analogue-digital conversion, and higher-frequency applications are still rather expensive. The most known digital filters are developed as: 1. FIR (Finite Impulse Response) filters -computed as the weighted, finite sum of lagged values of input (called also moving average filters): FIR filters are inherently stable, can be easily designed but need more computation power that IIR filters. 2. IIR (Infinite Impulse Response) filters -computed as the weighted finite sum of lagged values of both: input and output (called also autoregressive filters): IIR filters are rather hard to develop, there is a risk of instability (similar to non-stationarity of autoregressive time series, see Kirchgassner, Wolters, 2007), arithmetic inaccuracies cumulate and can lead to errors, however, they require less computation power and produce higher attenuation in the stop-band together with a smaller transition band.
Other methods of smoothing are presented by Cryer and Chan (2008) and Lutkepohl (2005) -Kalman filter.

Problem description
Digital filters projected with the most known classical methods usually need a large number of lagged signals. It extends the response time delay of the output signal. In certain real applications, such a time delay can be unacceptable and limits the use of digital filters. One of the examples is a wheel detector -a field part of the railway traffic system placed on a railway track. Such a system should work correctly for train speed from 0 to 350 km/h. Figure 3 shows an example of a wheel detector and describes that a time delay of 50 ms-resulting from the use of the internal digital filter -causes a virtual shift of the train location between 0 m and almost 5 m. It must be taken into consideration that such a delay, added to the communication delay and operating time of the control algorithm gives an unacceptable value. A trial to reduce the number of lagged signals with the use of the conventional method has decreased significantly the attenuation in the stop-band and has finally led to the need to remove the conventional digital filter from the wheel detector. The above-presented problem was the direct cause of the investigations into alternative methods of digital filters design. Designing such filters with classical methods means calculation of coefficients a i and b i , presented in equations 1 and 2, using the developed algorithm, according to the set requirements. Such requirements can specify: cut-off frequency, attenuation in the stop band, the maximum level of ripples, the width of the slope -depending on application. Very often in rather simple filters, the most important requirement is difference in signal attenuation in the pass-band and stop-band. Known algorithms, however, also take into account other requirements, increasing the number of coefficients -and finally increasing complexity and time delay. Properties of the genetic algorithm known from other studies (Stelmach, 2014) were used in the method proposed below, although it leads to the suboptimal solution presented as follows: 1. Select a measure appropriate to the desired filter properties (for example, the minimum value of ripples, the amplification in the pass-band, the maximum deviation from phase linearity, etc.). In the presented investigation, it was: the ratio of energy in the pass-band to stop-band. 2. Select the filter type (FIR or IIR). 3. Set the limit of time delay, i.e. m and n values (limited to 4 in this investigation).
4. Estimate a i and b i value with a genetic algorithm. 5. Check the transfer function of the developed filter -if its properties meet the requirements.

Genetic algorithm introduction
A Genetic Algorithm (GA) was invented by Holland (1975) to find solutions to optimisation and search problems -see Goldberg (1998). The method uses an evolutionary approach inspired by biological evolution. The main term in the GA is a genotype (a binary string -for example '0000100111010101') that can code a value, a number of values or logical states -parameters that describe the optimal solution and allow us to generate new generations approaching the optimum. GAs select the best genotype to produce the next generation, and subsequent generations are created based on the operations similar to those found in biology, according to the sequence, see Figure 4.
The computed fitness value, being an optimisation criterion, allows us to: 1) terminate the algorithm when a set number of generations was passed with no improvement of fitness value or the generations number reached the defined value, 2) make a selection among the genotypes.
Three operations described below are carried out in order to improve the next generations: 1) selection -based on the fitness function, only genotypes with the best fitness value (that is higher than a given constant) can be reproduced; 2) crossover -the operator used to combine the genetic information of the parents to create a new generation, a new genotype is generated as a junction of the parts of the genes from both parent genotypes, randomly choosing the point (points) of crossover: 001011|110100 010100|011001 001011011001 1) mutation -the operator used to maintain genetic diversity from one generation to the next, it alters the value of randomly chosen genes:

-> 010011100111
All above-mentioned operations are presented in more detail by Grzymkowski et al. (2008).

Experiment description
The experiment was carried out in order to verify if the above-proposed method could develop digital filters limiting time delay (the number of a i and b i parameters), with better properties than those designed with known methods. The investigation was made for both: IIR and FIR type filters and three cases: low-pass (LPF), high-pass (HPF) and band-pass (BPF), limiting the parameters number n = m to 2, 3 and 4. The fitness function was defined as the ratio of energy in the pass-band to stop-band, using FFT (Fast Fourier Transformation) of output time series y i . A genetic algorithm was carried out 500 times to estimate the dispersion of the results. Estimated filters with the biggest fitness value were compared with filters developed conventionally with well-known methods: 1) impulse response truncation method, 2) windowing design method, 3) reference analogue prototype method, using Matlab software ( fir1, firls, cfirpm, polystab, buttord, cheby1, designfilt packages), taking into consideration the values of fitness function and the shape of transfer function.

Results
The genetic algorithm stabilises very quickly, after 15-20 generations, see Figure 5 that shows the fitness value for the IIR type low-pass filter with 4 parameters. The dispersion of fitness function value was relatively small as visible on boxplots -see Figure 6. Table 1 presents it as values of coefficient of variation (the ratio of the standard deviation to the mean). It should be noted that unstable cases of IIR filters were deleted and other investigations were carried out to achieve 500 Monte Carlo iterations.   Figures 7 and 8 show the transfer functions of the best classical filters, comparing the transfer functions of the filters estimated with a genetic algorithm for the low-pass and band-pass type of digital filters and the filters conventionally designed. It must be underlined that it was not possible to design the IIR band-pass filter with the use of the classical method and only 2, 3 or 4 parameters, also the FIR band-pass filter with 2 parameters. Additionally, there were carried out trials to design digital filters with more complex transfer functions that could be created classically with such a small number of parameters.  Summarising, conventional methods of the filter design are: 1) easy to use (usually software requires only setting a number of parameters), 2) fast -the process of calculation takes a few seconds, 3) limited, not optimised to meet only certain requirements, so some filter properties are "too good" at the expense of complexity. The method proposed in this article using a Genetic Algorithm is: 1) not so user friendly, it needs the knowledge of R packages and requires writing the script, 2) slower -the process of calculation takes a few minutes, 3) more accurate for complex requirements (the fitness function is tailored to these requirements).

Conclusions
Although the theory of digital filters is well-known, it usually needs a relatively big number of lagged input observations. A genetic algorithm allows us to limit negative effects of time delay keeping the most important requirements, if only the fitness function is properly set. Even a small number of lagged observations allows us to design filters that are impossible to create with the use of the conventional method. Moreover, it is possible to design more complex filters, modifying the fitness function. An excessive increase of used lagged observations could be, however, the limitation of the method due to computational complexity.