10 software filtering methods

Publisher:BeaLaity0170Latest update time:2015-02-02 Source: laogu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Limiting filter method (also known as program judgment filter method)
    A. Method:
        Based on experience, determine the maximum deviation allowed between two samples (set to A).
        Every time a new value is detected, make a judgment:
        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 order 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 measured parameters with slow changes in temperature and liquid level.
    C. Disadvantages:
        It is not suitable for fast-changing parameters such as flow rate and speed.

3. Arithmetic average filtering method
    A. Method:
        Continuously take N sampling values ​​for arithmetic averaging.
        When the N value is large: the signal smoothness is high, but the sensitivity is low.
        When the N value is small: the signal smoothness is low, but the sensitivity is high.
        Selection of N value: For general flow, N=12; pressure: N=4
    B. Advantages:
        Suitable for filtering signals with random interference.
        Such signals are characterized by an average value, and the signal fluctuates around a certain range of values.
    C. Disadvantages:
        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 data at the head of the original queue is discarded. (First-in-first-out principle)
        Perform arithmetic average operation on the N data in the queue to obtain a new filtering result
        . The selection of N values: 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,
        and wastes RAM.
        
5. Median average filtering method (also known as anti-pulse interference average filtering method)
    A. Method:
        Equivalent to "median filter method" + "arithmetic average filter method".
        Continuously sample N data, remove a maximum value and a minimum value,
        and then calculate the arithmetic average of N-2 data
        . Selection of N value: 3~14
    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: The measurement speed is slow, and         it is more wasteful of RAM
        like the arithmetic average filter method. 6. Limiting average filter method     A. Method:         Equivalent to "limiting filter method" + "recursive average filter method".         Each new data sampled is first limited and         then sent to the queue for recursive average 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:         It is more wasteful of 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:         Good suppression effect on periodic interference.         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 with a filtering frequency 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:
        Suitable for objects with large pure lag time constants
        and systems with short sampling cycles.
    C. Disadvantages:
        For signals with small pure lag time constants, long sampling cycles, and slow changes,
        they cannot quickly reflect the severity of the current interference to the system, and the filtering effect is poor.

9. De-jitter filtering method
    A. Method:
        Set a filter 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 will replace the current effective value and the counter will be cleared.
    B. Advantages:
        It has a better filtering effect for the slowly changing measured parameters,
        which can avoid the controller being overloaded near the critical value. Repeated on/off jumps or jitter on the display
    C. Disadvantages:
        Not suitable for fast-changing parameters
        If the sampled value happens to be the interference value when the counter overflows, the interference value will be imported
into the system as a valid 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 importing interference values ​​into the system
    C. Disadvantages:
        Not suitable for fast-changing parameters
The sample program (JKRL) of 10 software filtering methods
 

assumes that data is read from 8-bit AD (if it is a higher-bit AD, the data type can be defined as int), and the subroutine is get_ad();

1. Limited auxiliary filtering
/* The A value can be adjusted according to the actual situation.
    value is a valid value, and new_value is the current sampling value.  
    The filtering program 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 filtering method
/* The N value can be adjusted according to the actual situation.
    The sorting adopts the bubble method */
#define N 11

char filter()
{
   char value_buf[N];
   char count,i,j,temp;
   for ( count=0;count    {
      value_buf[count] = get_ad();
      delay();
   }
   for (j=0;j    {
      for (i=0;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 average filtering method
/*
*/

#define N 12

char filter()
{
   int sum = 0;
   for ( count=0;count    {
      sum + = get_ad();
      delay();
   }
   return (char)(sum/N);
}

4. Recursive average filtering method (also known as sliding average filtering 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       sum = value_buf[count];
   return (char)(sum/N);
}

5. Median value average filtering method (also known as 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    {
      value_buf[count] = get_ad();
      delay();
   }
   for (j=0;j    {
      for (i=0;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       sum += value[count];
   return (char)(sum/(N-2));
}

6. Limiting average filtering method
/*
*/  
Refer to subroutines 1 and 3

7. First-order lag filtering method
/* To speed up the program processing, assume the 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 the weighted coefficient table and exists in the program storage area. */

#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    {
      value_buf [count] = get_ad();
      delay();
   }
   for (count=0,count       sum += value_buf[count]*coe[count];
   return (char)(sum/sum_coe);
}

9 , Anti-bounce 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 de-jittering filtering method
/*
*/
Omitted Refer to subroutines 1 and 9 

Reference address:10 software filtering methods

Previous article:Design of Temperature Detection System Based on ADμC812
Next article:msp430 software installation cracking process

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号