Commonly used digital Filter algorithm

Source: Internet
Author: User
Tags arithmetic constant valid
Commonly used digital Filter algorithm

1th Method: Limiting Filter method (also called program Judgment Filter method)

A method: According to experience, determine the maximum allowable deviation of two samples (set to a), each time the new value is detected: If this value and the difference between the last value <=a, then this value is valid, if this value and the difference between the last value >a, then this value is invalid, discard this value, with the last value instead of this value.

B Advantages: It can effectively overcome the impulse interference caused by accidental factors.

C Disadvantage: Can not suppress the periodic interference, smoothness of the poor.

2nd Method: Median Value Filter Method

A method: Continuous sampling n times (n odd), the n sampling values are arranged by size, and the median value is the valid value.

B Advantages: It can effectively overcome the fluctuation disturbance caused by accidental factors, and has good filtering effect on the measured parameters with slow change of temperature and liquid level.

C Disadvantage: The flow rate, speed and other fast changing parameters are not appropriate.

3rd method: Arithmetic mean filter method

A method: To take n sampled values for arithmetic averaging operation, when n value is large: signal smoothness is higher, but the sensitivity is low, when n value is small: signal smoothness is low, but sensitivity is high. N-Value selection: General flow, n=12; pressure: n=4.

B Advantages: It is suitable for filtering the signal with random interference, so that the signal is characterized by an average value, and the signal moves up and down near a certain range of values.

C Disadvantage: For the measurement speed is slow or require the data calculation speed of the real-time control is not applicable, compared to waste ram.

4th Method: Recursive average filter method (also called sliding Average filter method)

A method: The continuous fetch n sampled values as a queue, the length of the queue is fixed to n, each time sampling to a new data into the team tail, and discard the original team First data (FIFO principle). The new filtering results can be obtained by arithmetic averaging of n data in the queue. N value selection: flow, n=12; pressure: n=4, surface, n=4~12; temperature, n=1~4.

B Advantages: the periodic interference has a good inhibition, high smoothness, suitable for high-frequency oscillation system.

C Disadvantage: Low sensitivity, the impact of the occasional impulse interference is poor, not easy to eliminate due to pulse interference caused by the sampling value deviation, not suitable for the pulse interference is more serious occasions, compared to waste of RAM.

5th method: Median value averaging filter method (also known as anti-pulse interference averaging filter method)

A method: Equivalent to "median filter" + "Arithmetic average filter", continuously sampling n data, removing a maximum value and a minimum value, and then calculating the arithmetic mean value of N-2 data. Selection of n values: 3~14.

B Advantages: Combining the advantages of two filtering methods, for accidental impulse interference, it can eliminate the sampling value deviation caused by impulse interference.

C Disadvantage: The measurement speed is slow, and the arithmetic average filter method, the comparison wasted RAM.

The 6th method: The limit Amplitude Average filter method

A method: Equivalent to the "limit filtering method" + "recursive average filter", each sampling to the new data first to limit the processing, and then into the queue for the recursive average filter processing.

B Advantages: Combining the advantages of two filtering methods, for accidental impulse interference, it can eliminate the sampling value deviation caused by impulse interference.

C Cons: Compare wasted RAM.

7th method: First-order hysteresis filter Method

A method: Take a=0~1, this filter result = (1-a) * This sample value +a* the last filter result.

B Advantages: the periodic interference has a good inhibition, suitable for high fluctuation frequency occasions.

C Disadvantage: Phase lag, low sensitivity, the degree of lag depends on the value of a, can not eliminate the filter frequency than the sampling frequency of 1/2 of the interference signal.

The 8th method: Weighted Recursive average filtering method

A method: It is the improvement of the recursive average filter method, that is, different time data to different right, usually, the closer to the current moment of data, the greater the right, the greater the weight of the new sampling value, the higher the sensitivity, but the lower the signal smoothness.

B Advantages: It is suitable for the object with large pure lag time constant and the system with short sampling period.

C Disadvantage: For the pure lag time constant is small, the sampling period is longer, slow change of the signal, can not quickly reflect the system is currently affected by the severity of the interference, poor filtering effect.

The 9th method: The method of eliminating chattering filter

A method: Set a filter counter to compare each sample value to the current valid value: If the sample value = Current valid value, the counter is zeroed. If the sample value <> current valid value, then counter +1, and determine whether the counter >= upper limit n (overflow), if the counter overflow, then the current value is replaced by this time, and clear the counter.

B Advantages: For the slow change of the measured parameters have a better filtering effect, you can avoid the critical value of the controller's repeated on/off runout or the display of numerical jitter.

C Disadvantage: For fast changing parameters is not appropriate, if the counter overflow at the time the sampled value is exactly the interference value, then the interference value as a valid value into the system.

10th method: Amplitude-limiting anti-jitter filtering method

A method: Equivalent to the "limit filtering method" + "anti-jitter Filtering method", the first limit amplitude after the shake.

B Advantages: Inherit the "Limit" and "anti-shake" advantages, improve the "anti-jitter filter" in some of the shortcomings, to avoid the interference value into the system.

C Cons: Not suitable for fast changing parameters.

11th Method: IIR Digital Filter

A method: Determine the signal bandwidth, filter it. Y (n) = A1*y (n-1) + a2*y (n-2) + ... + ak*y (n-k) + b0*x (n) + b1*x (n-1) + b2*x (n-2) + ... + bk*x (n-k).

B Advantages: High-pass, low-pass, band-pass, with resistance arbitrary. Simple design (with MATLAB).

C Cons: Large computational capacity.

Part of the program:

1. Filter with limited pair
/* A value can be adjusted according to the actual situation
Value is a valid value, New_value is the current sampled value
The filter returns a valid actual value */

#define A 10
char value;
Char filter ()
{
Char New_value;
New_value = Get_ad ();
if ((New_value-value > A) | | (Value-new_value > A)
return value;
return new_value;

}

2, Median value filter method
/* N value can be adjusted according to the actual situation
Sort by bubbling 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>value_buf[i+1])
{
temp = Value_buf;
Value_buf = value_buf[i+1];
VALUE_BUF[I+1] = temp;
}
}
}
Return value_buf[(N-1)/2];
}

3, arithmetic average filter 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 average filter method (also known as the sliding Average filter method)
/*
*/

#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 value averaging filter method (also known as anti-pulse interference averaging filter 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>value_buf[i+1])
{
temp = Value_buf;
Value_buf = 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, the limit amplitude average filter method
/*
*/
Refer to sub-programs 1, 3


7, first-order hysteresis filter method
/* for Expedited program processing the assumption base 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 weighted table, and there is a program store. */

#define N 12
Char code Coe[n] = {1,2,3,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, anti-shake filter 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 anti-jitter filtering method
/*
*/

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.