Several filtering methods for single chip microcomputer to resist interference by software
[Copy link]
1. Limiting filter method (also known as program judgment filter method)
A. Method:
Based on experience, determine the maximum deviation value allowed for two samples (set to A).
Each time a new value is detected, judge:
If the difference between this value and the previous value is <= A, then this value is valid.
If the difference between this value and the previous value is > A, then this value is invalid, abandon this value, and use the previous value to replace this value.
B. Advantages:
It can effectively overcome the pulse interference caused by accidental factors.
C. Disadvantages :
It cannot suppress the periodic interference.
Poor smoothness
2. Median value filtering method
A. Method:
Continuously sample N times (N is an odd number)
Arrange the N sampling values in size and
take the middle value as the current effective value.
B. Advantages:
It can effectively overcome the fluctuation interference caused by accidental factors.
It has a good filtering effect on the slowly changing parameters such as temperature and liquid level.
C. Disadvantages:
It is not suitable for fast changing parameters such as flow and speed.
3. Arithmetic average filtering method
A. Method:
Take N sampling values continuously for arithmetic average calculation
. When the N value is large: the signal smoothness is higher, but the sensitivity is lower.
When the N value is small: the signal smoothness is lower, but the sensitivity is higher.
Selection of N value: general flow, N=12; pressure: N=4
B. Advantages:
It is 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. Disadvantages:
It is not suitable for real-time control with slow measurement speed or fast data calculation speed. It
wastes RAM.
4. Recursive average filtering method (also known as sliding average filtering method)
A. Method:
Take N consecutive 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 average calculation 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. Advantages:
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
5. Median average filtering method (also known as anti-pulse interference average filtering method)
A. Method:
equivalent to "median filtering method" + "arithmetic mean filtering method".
Continuously sample N data, remove a maximum value and a minimum value,
and then calculate the arithmetic mean of N-2 data.
Selection of N value: 3~14
B. Advantages:
combines the advantages of the two filtering methods.
For occasional pulse interference, it can eliminate the sampling value deviation caused by pulse interference.
C. Disadvantages:
slow measurement speed, and like the arithmetic mean filtering method,
it wastes RAM
6. Limiting average filtering method
A. Method:
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. Advantages:
Combining the advantages of the two filtering methods.
For occasional pulse interference, it can eliminate the sampling value deviation caused by pulse interference
. C. Disadvantages:
Relatively waste RAM
7. First-order lag filtering method
A. Method:
Take a=0~1.
The result of this filtering = (1-a)*this sampling value + a*last filtering result
B. Advantages:
It has a good inhibitory effect on periodic interference
and is suitable for occasions with high fluctuation frequency.
C. Disadvantages:
Phase lag, 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.
8. Weighted recursive average filtering method
A. Method:
It 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 time, the greater the weight is.
The larger 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 periods.
C. Disadvantages:
For signals with small pure lag time constants, long sampling periods, and slow changes,
it cannot quickly reflect the severity of the current interference to the system, and the filtering effect is poor.
9. Anti-jitter filtering method
A. Method:
Set a filtering counter
to compare each sampling value with the current effective value:
If the sampling value = the current effective value, the counter is cleared.
If the sampling value <> the current effective value, the counter is +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 clears the counter.
B. Advantages:
It has a good filtering effect for the slowly changing measured parameters,
and can avoid the repeated on/off jump of the controller or the value jitter on the display near the critical value.
C. Disadvantages:
It is not suitable for fast-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.
10. Limiting and de-jittering filtering method
A. Method:
Equivalent to "limiting filtering method" + "de-jittering filtering method".
Limiting first, then de-jittering.
B. Advantages:
Inherits the advantages of "limiting" and "de-jittering".
Improves some defects in "de-jittering filtering method" to avoid introducing interference values into the system.
C. Disadvantages:
Not suitable for fast-changing parameters .
|