Comparison of Several Software Filtering Algorithms in DSP[Copy link]
The first method is the limiting filter method (also known as the program judgment filter method). A method determines the maximum deviation allowed between two samples based on experience (set to A). Each time a new value is detected, it is judged: If the difference between the current value and the previous value is <= A, then the current value is valid. If the difference between the current value and the previous value is > A, then the current value is invalid, and the current value is discarded and replaced by the previous value. B Advantage: It can effectively overcome the pulse interference caused by accidental factors. C Disadvantage: It cannot suppress the periodic interference and poor smoothness. The second method is the median value filter method. A method samples N times continuously (N is an odd number). Arrange the N sampling values in order of size and take the middle value as the effective value of this time. B Advantage: It can effectively overcome the fluctuation interference caused by accidental factors. It has a good filtering effect on the measured parameters with slow changes in temperature and liquid level. C Disadvantage: It is not suitable for fast-changing parameters such as flow and speed. The third method is the arithmetic average filter method. A Method: Take N sampling values continuously and perform arithmetic averaging. When N value is large: signal smoothness is higher, but sensitivity is lower. When N value is small: signal smoothness is lower, but sensitivity is higher. Selection of N value: general flow, N=12; pressure: N=4 B Advantage: Suitable for filtering signals with general random interference. The characteristic of such signals is that there is an average value, and the signal fluctuates around a certain numerical range. C Disadvantage: Not applicable to real-time control with slow measurement speed or fast data calculation speed. It wastes RAM. The fourth method is recursive average filtering method (also known as sliding average filtering method). A method: Treat the continuous N sampling values as a queue. The length of the queue is fixed to N. Each time a new data is sampled, it is put at the end of the queue and the original data at the head of the queue is discarded. (First-in-first-out principle) Perform arithmetic averaging on the N data in the queue to obtain a new filtering result. Selection of N value: flow, N=12; pressure: N=4; liquid level, N=4~12; temperature, N=1~4 B Advantage: Good suppression of periodic interference, high smoothness, suitable for high-frequency oscillation systems. C Disadvantages: Low sensitivity; Poor suppression of occasional pulse interference; Difficult to eliminate sampling value deviation caused by pulse interference; Not suitable for occasions with severe pulse interference; Relatively wasteful of RAM; The fifth method: Median average filtering method (also known as anti-pulse interference average filtering method); A method is equivalent to "median filtering method" + "arithmetic average filtering method"; Continuously sample N data, remove a maximum value and a minimum value, and then calculate the arithmetic average of N-2 data; Selection of N value: 3~14; B advantage: Combination of the advantages of the two filtering methods; For occasional pulse interference, it can eliminate the sampling value deviation caused by pulse interference; C disadvantage: Slow measurement speed, like the arithmetic average filtering method, it wastes RAM; The sixth method: Limiting average filtering method; A method is equivalent to "limiting filtering method" + "recursive averaging filtering method"; Each new data sampled is first limited and then sent to the queue for recursive averaging filtering; B advantage: Combination of the advantages of the two filtering methods; For occasional pulse interference, it can eliminate the sampling value deviation caused by pulse interference; C disadvantage: Relatively wasteful of RAM; The seventh method: First-order lag filtering method; A Method: Take a=0~1. The result of this filtering = (1-a) * this sampling value + a * the result of the last filtering. B. Advantages: It has a good inhibitory effect on periodic interference and is suitable for occasions with high fluctuation frequency. C. Disadvantages: Phase lag and low sensitivity. The degree of lag depends on the value of a. It cannot eliminate interference signals whose filtering frequency is higher than 1/2 of the sampling frequency. The eighth method: Weighted recursive average filtering method. A method is an improvement on the recursive average filtering method, that is, different weights are given to data at different times. Usually, the closer the data is to the current moment, the greater the weight is. The greater the weight coefficient given to the new sampling value, the higher the sensitivity, but the lower the signal smoothness. B. Advantages: It is suitable for objects with large pure lag time constants and systems with short sampling cycles. C. Disadvantages: For signals with small pure lag time constants, long sampling cycles, and slow changes, it cannot quickly reflect the severity of the current interference to the system, and the filtering effect is poor. The ninth method: De-jitter filtering method. A method: Set a filter counter to compare each sampling value with the current effective value: If the sampled value = the current effective value, the counter is cleared. If the sampled value <> the current effective value, the counter is added by 1, and it is determined whether the counter is >= the upper limit N (overflow). If the counter overflows, the current value replaces the current effective value and the counter is cleared. B Advantages: It has a better filtering effect on the slowly changing measured parameters, and can avoid repeated on/off jumps of the controller near the critical value or numerical jitter on the display. C Disadvantages: It is not suitable for rapidly changing parameters. If the value sampled at the time when the counter overflows happens to be an interference value, the interference value will be imported into the system as an effective value. The 10th method: Limiting and de-jittering filtering method A Method is equivalent to "limiting filtering method" + "de-jittering filtering method". Limit first and then de-jitter. B Advantages: It inherits the advantages of "limiting" and "de-jittering", improves some defects in the "de-jittering filtering method", and avoids introducing interference values into the system. C Disadvantages: It is not suitable for rapidly changing parameters. The 11th method: IIR digital filter A Method determines the signal bandwidth and filters it. Y(n) = a1*Y(n-1) + a2*Y(n-2) + ... + ak*Y(nk) + b0*X(n) + b1*X(n-1) + b2*X(n-2) + ... + bk*X(nk) B Advantages High pass, low pass, band pass, band stop are arbitrary. Simple design (using matlab) C Disadvantages Large amount of calculation