The Design Of Intelligent Filter For EEG

. EEG data processing method is usually digital filter designed by the traditional method. Its disadvantage is the transition zone is wide and the filtering effect is poor. Using an improved particle swarm optimization algorithm on IIR digital filters design, the performances of filters designed by various methods are compared and analyzed. Experiments illustrate particle swarm optimization algorithm is effective in IIR filter design and its performance is promising.


Introduction
EEG signal, a kind of weak bioelectrical signal, usually has amplitudes from 5μv to 100μv and frequencies from 0.5Hz to 35Hz. Therefore, it is easy to be interfered by other physiological signals and external noise sources [1][2] . EEG is the overall response of brain nerve cell conduction information to electrical activity on the surface of the cerebral cortex or scalp. It is a spontaneous, rhythmic electrical activity signal from the brain cell population that can reflect brain activity and it contains a large amount of information for both diseases and physiological activity [3][4] . In recent years, there have been more and more relevant researches, and some achievements have been made [5][6][7][8][9][10] .
In EEG analysis, filtering is an essential part. The IIR digital filter is an important filter. It can achieve accurate frequency selectivity with a lower order. Over the years, many scholars have done a lot of explorations on IIR filter design [11][12][13][14] . Usually designing IIR digital filter need to design the analog filter firstly, and then transform it into a digital filter. This method has drawbacks such as wide transition band cost, so the filter performance is not ideal enough. Some scholars have also applied particle swarm algorithms to the IIR filters design [15][16][17][18] , but these algorithms may have shortcomings of local optimum or slow convergence. This paper uses an improved particle swarm optimization algorithm to design IIR and applies it to process the brain signal with STM32F4 as the core. The structure of the acquisition system is shown in

IIR digital filter
Transfer function of the IIR filter is described as [19] 1 2 A 0 is the gain, n is the second order number. a k , b k , c k and d k are the filter coefficient.
The cascaded system function of the filter is expressed in polar coordinates as The formula for the frequency response is given by Denote 4k+1 parameters with Φ=(A 0 , r 01 ,θ 01 , r 02 , θ 02 ,…, r 0k , θ 0k , r p1 , θ p1 , r p2 , θ p2 ,…, r pk , θ pk ). Then the amplitude response of the filter can be obtained as The choice of parameters in (5) play important roles in the filter performance.

PSO (particle swarm optimization) is an optimization algorithm proposed by Kenddy and Eberhart etc in
1995 [20] . The algorithm simulates the bird's foraging behavior and treats the solution to the optimization problem as a bird in the search space called a particle. Particles have three properties: position, velocity, and fitness of the objective function [21][22] . The algorithm first initializes a group of particles randomly within the search range, and then iterates continuously until the termination condition is reached. Updating two parameters during the iteration: one is the optimal location of the particle itself; the other is the optimal location of the population. PSO is an intelligent optimization algorithm. Assuming in the D dimensional search space, set S particles, iterate T times, the i particle in D dimension is expressed in X id , the speed is expressed as V id , the best position of the particle is recorded with pBest id , the best location of the population is given by gBest d . Renewing position and speed according to formula (6) and (7), and then we can get (6) and (7), t=1,2,…,T, i=1,2,…,S, d=1,2,…,D; r 1 , r 2 are random numbers that follows U(0,1) distribution; c 1 and c 2 are learning factor (generally set to 2); ѡ is a weighting coefficient (between 0.1 and 0.9), and the algorithm terminates when it reaches the maximum number of iterations or target accuracy.
In order to improve the insufficiency of the algorithm, many scholars have proposed improvement strategies and achieved certain results. For example, the formula for a linear degressive strategy is In (8), ѡ max and ѡmin are the maximum and minimum inertia coefficients, meanwhile, iterMax and iter denote the maximum iteration number and the current iteration number respectively. This improvement can reduce the local optimum in the later period. Ren Wanlong proposed a non-linear adjustment weighting strategy (Weight particle swarm optimizatio-n，WPSO) [23] . The formula is updated to This change of weight makes the speed of particles focus on the global search firstly, and then focus on the local search, which is conducive to the search to the global optimal position. Shang Junna et al. proposed a trigonometric function to improve inertia weight and speed (Speed value particle swarm optimization ， SVPSO) [24] . The improved inertia weight formula is updated as follows In (10) This can better the convergence speed to the optimal solution in the early stage, and can search the optimal solution more accurately in the later stage. In addition, the trigonometric function can prevent large changes in the position of the particles. It tends to be gentle and helps to search a global optimal solution.
Although there are many strategies for improvement, there are still problems such as slow convergence, local optimum, etc.

APSO digital filter design
This paper uses a strategy that the front optimal particle individual extreme replaces the global extreme value and improves pBest to pBest ave (Adaptive particle swarm optimization，APSO) [25] to design IIR digital filter.
This algorithm refers to the characteristics of the geese flight. On the one hand, it substitutes the front optimal particle individual extreme for the global extreme value, so all particles fly in multiple directions, damp the tendency of particles to be identical, and keep the diversity of particles; On the other, the algorithm replaces the individual extreme with the weighted average value of individual extreme value and its present fitness value to enable each particle to use more valuable information from other particles. The algorithm enhances information exchanges among particles. The combination of the two improvements can get a pleased coordination of the contradiction between the search speed and the algorithm accuracy.
The speed and position will be updated by following formula Ideally, this improvement can accelerate the convergence speed, and reduce the probability of falling into a local optimal.
Particle swarm algorithm uses fitness to determine the current position of the particles. In practical applications, the fitness function is to be selected by specific problems. The fitness function of the filter chosen, in this paper, is the minimum error function In (15), the smaller the F is, the better the corresponding filter performance will be. In order to ensure the stability of the filter, each second-order node pole must be within the Z-plane unit circle, and the element value of Φ=(A 0 , r 01 ,θ 01 , r 02 , θ 02 ,…, r 0k , θ 0k , r p1 , θ p1 , r p2 , θ p2 ,…, r pk , θ pk ) can be set within the range of [-1, 1].
The process for using PSO to search the optimal filter parameters is given by Fig 2. start Initialize population, dimensions and other parameters Randomly set particle position x, velocity v Calculate particle fitness F

Simulation
In order to verify the effectiveness of the proposed algorithm in EEG signal processing, a fourth-order IIR digital filter design with passband 0.5Hz-35Hz is used as an example. Firstly, a fourth-order Butterworth type IIR filter is designed in traditional ways. Simulation with fdatool in MATLAB. Amplitude frequency response results are shown in Fig 3. Secondly, the particle swarm optimization algorithm is used to design the filter. The simulation experiment carries out four kinds of particle swarm algorithms. Table 1 shows the results of the four particle swarm optimization algorithms. The amplitude and frequency response results of filter designed by four particle swarm algorithms are shown in Fig 4. The parameters of PSO in the experiment: population size is 50, parametric dimension is 9, evolutionary algebra is 500.   It can be concluded from Table 1 that APSO's indicators have much decided advantage over the other. APSO has smaller standard deviations from fitness, indicating that the algorithm has better robustness and global performance. It deters particles from falling into a local optimum.

Experiments results
This paper uses filters designed by traditional methods and APSO respectively to process EEG signals collected with the EEG acquisition system. The acquisition system is shown in Fig 1. This system selects electrodes of AgCl material, and the EEG signal is input to an analog circuit through a wire with a shielding layer. Finally, data is obtained by A/D converter. The sampling frequency is 250Hz. Results are depicted in Fig 5, Fig 6, Fig 7, Fig 8.  From the comparison of Fig 5 and Fig 7, it can be concluded that there are still some high-frequency noises in EEG signals filtered by the filter designed with the traditional method, but the filtered waveform of the filter that designed by APSO is relatively clean. Fig 6 and Fig  8 indicate that the filter of APSO has a fast attenuation at the stopband, which is superior to the conventional method of designing the filter.

Conclusion
This paper uses four particle swarm optimization intelligent algorithms to design IIR filters, and compared with filters designed by traditional methods. In simulation and experimental results, the filter designed by the APSO algorithm has a further development for performance. Because there are plenty of improved particle swarm algorithms, the particle swarm algorithms still have a lot of room for improvement in the design of filters. The next step is to discuss its improvement to further promote its effectiveness in filter design.