10 simple digital filtering methods

Source: Internet
Author: User

1. subfilter
/* The a value can be adjusted according to the actual situation.
Value is a valid value, and new_value is the current sample value.
FilterProgramReturns the actual valid value */
# 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. Central value filtering method
/* The N value can be adjusted according to the actual situation.
Sort by Bubble 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
/*
*/

# 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 average filtering method for anti-pulse interference)
/*
*/
# 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. amplitude limiting average filtering method
/*
*/
For details, refer to subprograms 1 and 3.

7. First-order lagging Filtering Method
/* To accelerate the processing speed of the program, assume that the base number is 100, a = 0 ~ 100 */

# Define a 50

Char value;

Char filter ()
{
Char new_value;
New_value = get_ad ();
Return (100-a) * value + A * new_value;
}

8. Weighted recursive average filtering method
/* The CoE array is a weighting coefficient table, which exists in the program storage area. */

# Define N 12

Char code COE [N] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
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;
}

10. amplitude limiting and jitter Filtering
/*
*/
For details, refer to subprograms 1 and 9.

 


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 traffic, speed, and other rapidly changing parameters

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:
Resource Access Management (RAM) is a waste of resources.

7. 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 system's current interference severity cannot be quickly reflected, and the filtering effect is poor.

9. deshake Filtering Method
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 the interference value, the interference value is treated as a valid value guide.
Inbound System

10. amplitude limiting and jitter 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

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/bird67/archive/2008/11/28/3401553.aspx

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.