Ad acquisition Filtering Algorithm

Source: Internet
Author: User

The collected basic filtering algorithms:

In theory, the signal collected by the microcontroller from the/D chip is the quantitative signal. However, due to the mutual interference of the circuit, the noise of the power supply, and the electromagnetic interference, the analog input signal of the/D chip will overlay the cyclic or non-cyclic interference signal, and be attached to the quantization value, causing a certain deterioration of the signal. Considering the real-time and security of data collection, it is sometimes necessary to perform soft processing on the collected data to minimize the impact of interference signals. This process is called data collection filtering.

The following describes ten data collection filtering methods and programming examples. These 10 methods have different performance for different noise and Sampling Signals, providing a wide selection space for different applications. When selecting these methods, you must understand the main types of noise in the circuit, including:

* Whether the noise is random or periodic

* Noise frequency

* The sampling signal type is block-to-block or slow-to-slow.

* In addition, you must consider the resources available to the system.

Through the analysis of noise and sampling performance, we can select the most appropriate method and determine reasonable parameters to achieve good results.

At present, there are 10 main methods used for data collection and filtering. These 10 methods are all processed in the time domain. Compared with the IIR or FIR filter designed from the frequency domain, their implementation is simple, the computation is small, and the performance can meet the application requirements in most scenarios.

1. Limit filtering method (also known as the program judgment filtering method)
A. Method:
Based on experience, determine the maximum deviation allowed by the two samples (set to)
When a new value is detected:
If the difference between the current value and the previous value is <= A, the current value is valid.
If the difference between the current value and the previous value is> A, the current value is invalid. Discard this value and replace this value with the previous value.
B. Advantages:
Can effectively overcome impulsive interference caused by accidental factors
C. Disadvantages
It cannot suppress periodic interference.
Poor Smoothness

2. Central value filtering method
A. Method:
Continuous Sampling n times (N is an odd number)
Sort n sample values by size
The median value is the valid value.
B. Advantages:
It can effectively overcome the fluctuation interference caused by accidental factors.
Good filtering effect on tested parameters with slow changes in temperature and Liquid Level
C. Disadvantages:
Inefficient at parameters with fast changes such as traffic and speed. 3. arithmetic mean Filtering
A. Method:
N consecutive sample values for arithmetic mean Operations
Large N value: high signal smoothness, but low sensitivity
N value is relatively small: the signal smoothness is low, but the sensitivity is high.
N Value Selection: general traffic, n = 12; pressure: N = 4
B. Advantages:
Suitable for filtering signals with random interference.
In this way, the signal has an average value, and the signal fluctuates up and down near a certain value range.
C. Disadvantages:
It is not applicable to real-time control of slow measurement speed or fast data computing speed.
Resource Access Management (RAM) is a waste of resources.

4. Recursive mean filtering (also known as moving average filtering)
A. Method:
Regard n consecutive sample values as a queue
The queue length is fixed to n.
Each time a new data is sampled and put at the end of the team, the first data of the original team is discarded. (first-in-first-out principle)
Perform arithmetic mean operations on N data in the queue to obtain new filtering results.
N Value Selection: traffic, n = 12; pressure: N = 4; liquid level, n = 4 ~ 12; temperature, n = 1 ~ 4
B. Advantages:
Excellent anti-Periodic Interference and High smoothness
Suitable for high-frequency oscillating systems
C. Disadvantages:
Low sensitivity
Ineffective suppression of occasional impulsive interference
It is difficult to eliminate the sample value Deviation Caused by pulse interference.
It is not applicable to scenarios with severe pulse interference.
Resource Access Management (RAM) is a waste of resources.

5. Median average filtering method (also known as the average filtering method for anti-pulse interference)
A. Method:
It is equivalent to "median value filtering method" + "arithmetic mean filtering method"
Samples n data records consecutively, removing one maximum value and one minimum value.
Then calculate the arithmetic mean of N-2 data
N Value Selection: 3 ~ 14
B. Advantages:
Integrates the advantages of the two filter methods
The sample value Deviation Caused by impulse interference can be eliminated.
C. Disadvantages:
Slow measurement speed, same as the arithmetic mean Filtering Method
Resource Access Management (RAM) is a waste of resources.
6. amplitude limiting average filtering method
A. Method:
It is equivalent to "limit filtering" + "recursive average filtering"
The new data sampled at each time is first limited,
Send it to the queue for Recursive average filtering
B. Advantages:
Integrates the advantages of the two filter methods
The sample value Deviation Caused by impulse interference can be eliminated.
C. Disadvantages:
Relatively wasteful ram7, first-order lagging Filtering Method
A. Method:
Obtain a = 0 ~ 1
Filter result = (1-A) * sample value + A * last filter result
B. Advantages:
It can effectively suppress periodic interference.
Suitable for scenarios with high volatility
C. Disadvantages:
Phase lagging, low sensitivity
The degree of lag depends on the size of value.
The interference signal with a filtering frequency greater than the sampling frequency of 1/2 cannot be eliminated.

8. Weighted recursive average filtering method
A. Method:
Is an improvement of the recursive average filtering method, that is, different weights are applied to data at different time points.
Generally, the closer the data is to the current time, the larger the permission is obtained.
The greater the weight given to the new sample value, the higher the sensitivity, but the lower the signal Smoothness
B. Advantages:
Suitable for objects with large pure lag time constants
And systems with short sampling periods
C. Disadvantages:
Signals with low pure lag time constants, long sampling periods, and slow changes
The current interference severity of the system cannot be quickly reflected. The filtering effect is poor.
A. Method:
Set a filter counter
Compare the value of each sample with the current valid value:
If the sample value = the current valid value, the counter is cleared.
If the sampling value is <> the current valid value, the counter is + 1 and determines whether the counter is greater than or equal to n (overflow)
If the counter overflows, replace the current valid value with this value and clear the counter.
B. Advantages:
It provides better filtering effects for tested parameters with slow changes,
It can avoid repeated on/off beats or numerical jitter on the monitor near the critical value.
C. Disadvantages:
Not suitable for rapidly changing parameters
If the sampled value that overflows from the counter happens to be an interference value, the interference value is imported as a valid value to the system.
10. amplitude limiting and deshake Filtering
A. Method:
It is equivalent to "limit filtering" + "deshake filtering"
First limit, then deshake
B. Advantages:
It inherits the advantages of "limiting" and "shake-free ".
Some defects in the "Shake-free filtering" method are improved to avoid importing interference values into the system.
C. Disadvantages:
Not suitable for rapidly changing parameters
Assume that data is read from the 8-bit AD (if it is a higher AD, the data type can be defined as INT), and the subroutine is get_ad (); 1. subfilter

# Define a 10 char value; char filter ()
{
Char new_value;
New_value = get_ad ();
If (new_value-value> A) | (value-new_value>)
Return value;
Return new_value;

} 2. Median value filtering method

# Define N 11 char filter ()
{
Char value_buf [N];
Char count, I, j, temp;
For (COUNT = 0; count <n; count ++)
{
Value_buf [count] = get_ad ();
Delay ();
}
For (j = 0; j <N-1; j ++)
{
For (I = 0; I <n-J; I ++)
{
If (value_buf [I]> value_buf [I + 1])
{
Temp = value_buf [I];
Value_buf [I] = value_buf [I + 1];
Value_buf [I + 1] = temp;
}
}
}
Return value_buf [(N-1)/2];
} 3. arithmetic mean filtering method # define N 12 char filter ()
{
Int sum = 0;
For (COUNT = 0; count <n; count ++)
{
Sum + = get_ad ();
Delay ();
}
Return (char) (sum/N );
} 4. Recursive mean filtering (also known as moving average filtering)

# Define N 12 char value_buf [N];
Char I = 0; char filter ()
{
Char count;
Int sum = 0;
Value_buf [I ++] = get_ad ();
If (I = N) I = 0;
For (COUNT = 0; count <n, Count ++)
Sum = value_buf [count];
Return (char) (sum/N );
} 5. Median average filtering method (also known as the Anti-pulse interference average filtering method)

# Define N 12 char filter ()
{
Char count, I, J;
Char value_buf [N];
Int sum = 0;
For (COUNT = 0; count <n; count ++)
{
Value_buf [count] = get_ad ();
Delay ();
}
For (j = 0; j <N-1; j ++)
{
For (I = 0; I <n-J; I ++)
{
If (value_buf [I]> value_buf [I + 1])
{
Temp = value_buf [I];
Value_buf [I] = value_buf [I + 1];
Value_buf [I + 1] = temp;
}
}
}
For (COUNT = 1; count <N-1; count ++)
Sum + = value [count];
Return (char) (sum/(N-2 ));
} 6. Average limit Filtering Method
 
For more information, see subprograms 1, 37. First-order lag filtering # define a 50 char value; char filter ()
{
Char new_value;
New_value = get_ad ();
Return (100-a) * value + A * new_value;
} 8. Weighted recursive mean filtering method # define N 12 char code COE [N] = };
Char code sum_coe = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12; char filter ()
{
Char count;
Char value_buf [N];
Int sum = 0;
For (COUNT = 0, count <n; count ++)
{
Value_buf [count] = get_ad ();
Delay ();
}
For (COUNT = 0, count <n; count ++)
Sum + = value_buf [count] * COE [count];
Return (char) (sum/sum_coe );
} 9. deshake filtering method # define N 12 char filter ()
{
Char COUNT = 0;
Char new_value;
New_value = get_ad ();
While (value! = New_value );
{
Count ++;
If (count> = N) return new_value;
Delay ();
New_value = get_ad ();
}
Return value;
}

Ad acquisition Filtering Algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.