Ten methods for filtering PLC analog inputs!
Thread Content
1. Limiting filter method (also known as programmed judgment filter method)A. Method: Based on empirical judgment, a maximum allowable deviation value between two samples is determined (denoted as A). Each time a new value is detected, it is checked: if the difference between this value and the previous value exceeds A, then this value is considered invalid; it is discarded and the previous value is used in its place.
B. Advantages: It can effectively overcome pulse interference caused by accidental factors.
C. Disadvantages: It cannot suppress periodic interference, and the smoothing effect is poor.
2. Median filter method
A. Method: N consecutive samples are taken (with N being an odd number). These N sample values are arranged in order from largest to smallest, and the middle value is taken as the valid value for this instance.
B. Advantages: It can effectively counteract fluctuating interference caused by accidental factors, and it provides a good filtering effect for measured parameters whose values change slowly, such as temperature and liquid level.
C. Disadvantages: It is not suitable for parameters that change rapidly, such as flow rate and speed.
3. Arithmetic average filter method
A. Method: N consecutive sample values are taken and their arithmetic average is calculated. When N is large, the signal has a higher degree of smoothing but lower sensitivity; when N is small, the signal has less smoothing but higher sensitivity. Selection of N: For general flow rates, N=12; Pressure: N=4 B. Advantages: Suitable for filtering signals that are subject to random disturbances; such signals have an average value and fluctuate around a certain range. C. Disadvantages: Not suitable for real-time control applications where measurement speed is low or fast data processing is required; it also consumes a significant amount of RAM. 4. Recursive average filtering method (also known as moving average filtering). A. Method: Treats N consecutive sampled values as a queue with a fixed length of N. Each time a new data point is sampled, it is added to the end of the queue, while the data at the beginning of the queue is removed (FIFO principle). The arithmetic average of the N values in the queue gives the new filtered result. Selection of N: For flow rates, N=12 ; Pressure: N=4 ; Liquid level, N=4~12 ; Temperature, N=1~4. B. Advantages: Provides good suppression of periodic interference; high smoothness. Suitable for systems with high-frequency oscillations. C. Disadvantages: Low sensitivity; poor suppression of occasional pulsed interference; difficult to eliminate sampling value deviations caused by pulsed interference; not suitable for situations with severe pulsed interference; relatively wasteful of RAM. 5. Median average filtering method (also known as pulse-interference-resistant average filtering method). A. Method: Equivalent to “median filtering method” + “arithmetic average filtering method”. N data points are sampled sequentially, one maximum value and one minimum value are removed, and then the arithmetic average of the remaining N-2 data points is calculated. The appropriate value for N is 3~14. B. Advantages: Combines the advantages of the two filtering methods; can eliminate sampling value deviations caused by occasional pulsed interference. C. Disadvantages: Slower measurement speed, similar to arithmetic average filtering; relatively wasteful of RAM. 6. Clamping average filtering method. A. Method: Equivalent to “clamping filtering method” + “recursive average filtering method”. Each newly sampled data point is first clamped before being fed into the queue for recursive average filtering. B. Advantages: Combines the advantages of the two filtering methods; can eliminate sampling value deviations caused by occasional pulsed interference. C. Disadvantages: Relatively wasteful of RAM. 7. First-order lag filtering method. A. Method: Set a=0~1. The result of this filtering step = (1-a) * current sampled value + a * previous filtering result. B. Advantages: Provides good suppression of periodic interference; suitable for situations with high fluctuation frequencies. C. Disadvantages: Phase lag and low sensitivity; the degree of lag depends on the value of a; cannot eliminate interference signals with a frequency higher than half of the sampling frequency. 8. Weighted recursive average filtering method. A. Method: An improvement on the recursive average filtering method, where different weights are assigned to data from different times; generally, the greater the proximity to the current time, the larger the weight assigned. The larger the weight coefficient assigned to the new sample value, the higher the sensitivity, but the lower the smoothness of the signal. B. Advantages: Suitable for systems with large pure delay time constants and short sampling periods. C. Disadvantages: For signals with small pure delay time constants, long sampling periods, and slow changes, it is unable to quickly reflect the severity of the disturbances affecting the system, resulting in poor filtering performance. 9. Debouncing filtering method A. Method: A filtering counter is set up; each sampled value is compared with the current effective value. If the sampled value equals the current effective value, the counter is reset. If it differs, the counter is incremented by 1, and it is checked whether the counter value is greater than or equal to the upper limit N (overflow). If the counter overflows, the current sampled value replaces the current effective value, and the counter is reset. B. Advantages: Provides good filtering performance for slowly changing measured parameters, and helps prevent repeated on/off switching of the controller or fluctuations in the values displayed on the monitor near critical values. C. Disadvantages: Not suitable for rapidly changing parameters. If the value sampled at the time of counter overflow happens to be an interference value, that interference value will be introduced into the system as a valid value. 10. Clamping debouncing filtering method A. Method: It combines the “clamping filtering method” and the “debouncing filtering method” – clamping is performed first, followed by debouncing. B. Advantages: It retains the advantages of both clamping and debouncing, while addressing some of the shortcomings of the debouncing filtering method, thereby preventing interference values from being introduced into the system. C. Disadvantages: Not suitable for rapidly changing parameters