, Limited Average Filtering Method A. Method: It is equivalent to "Limited Filtering Method" + "Recursive Average Filtering Method" Each time the new data is sampled, it is first limited. Then send it to the queue for recursive average filteringB. 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:
Relatively wasteful RAM
7、First-order lag filtering methodA. 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 suppression effect on periodic interference and is suitable for occasions with high fluctuation frequency
C. Disadvantages:
Phase lag and low sensitivity
The degree of lag depends on the size of the a value
It cannot eliminate the interference signal whose filtering frequency is higher than 1/2 of the sampling frequency
8、Weighted recursive average filtering methodA、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 constant and systems with short sampling period
C、Disadvantages:
For signals with small pure lag time constant, long sampling period and slow change, it cannot quickly reflect the severity of the current interference of the system, and the filtering effect is poor
9. Anti-jitter filtering method A. Method: Set a filter counter and 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 added by 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 valid value and the counter will be cleared. 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 jitter of the value 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 a valid value.
10、Amplitude limiting and de-jittering filtering methodA. Method:
Equivalent to "amplitude limiting filtering method" + "de-jittering filtering method". Limit first, then de-jittering
B. Advantages:
Inherits the advantages of "amplitude limiting" and "de-jittering"
Improves some defects in the "de-jittering filtering method" to avoid importing interference values into the system
C. Disadvantages:
For fast changing parameters, it is not suitable
11、IIR Digital filterA. Method:
Determine the signal bandwidth, filter it.
Y(n) = a1*Y(n-1) + a2*Y(n-2) + ... + ak*Y(nk) + b0*X(n) + b1*X(n-1) + b2*X(n-2) + ... + bk*X(nk) B. Advantages: high pass, low pass, band pass, band stop are arbitrary. Simple design (using matlab) C. Disadvantages: large amount of calculation. C Program Sample for Software Filtering Example programs for 11 software filtering methods Assume that data is read from an 8-bit AD (if it is a higher-bit AD, the data type can be defined as int), the subroutine is get_ad(); 1, limited sub-filter /* The value of A can be adjusted according to actual conditions. value is a valid value, 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;
else return new_value;
}
2, median filtering method/* N The value can be adjusted according to the actual situation. The sorting method uses 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;jMethod: Determine the signal bandwidth, and filter it. Y(n) = a1*Y(n-1) + a2*Y(n-2) + ... + ak*Y(nk) + b0*X(n) + b1*X(n-1) + b2*X(n-2) + ... + bk*X(nk) B. Advantages: High pass, low pass, band pass, band stop are arbitrary. Simple design (using matlab) C. Disadvantages: large amount of calculation. C Program Sample for Software Filtering Example programs for 11 software filtering methods Assume that data is read from an 8-bit AD (if it is a higher-bit AD, the data type can be defined as int), the subroutine is get_ad(); 1, limited sub-filter /* The value of A can be adjusted according to actual conditions. value is a valid value, 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;
else return new_value;
}
2, median filtering method/* The N value can be adjusted according to the actual situation, and the sorting method uses the bubble method*/
[ align=left]#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;jMethod: Determine the signal bandwidth, and filter it. Y(n) = a1*Y(n-1) + a2*Y(n-2) + ... + ak*Y(nk) + b0*X(n) + b1*X(n-1) + b2*X(n-2) + ... + bk*X(nk) B. Advantages: High pass, low pass, band pass, band stop are arbitrary. Simple design (using matlab) C. Disadvantages: large amount of calculation. C Program Sample for Software Filtering Example programs for 11 software filtering methods Assume that data is read from an 8-bit AD (if it is a higher-bit AD, the data type can be defined as int), the subroutine is get_ad(); 1, limited sub-filter /* The value of A can be adjusted according to actual conditions. value is a valid value, 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;
else return new_value;
}
2, median filtering method/* N The value can be adjusted according to the actual situation. The sorting method uses 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;jtemp;
for ( count=0;count { value_buf[count] = get_ad(); delay();
}
[align=left ]for (j=0;jtemp;for ( count=0;count { value_buf[count] = get_ad(); delay();
}
[align=left ]for (j=0;j{
if" align][align="left]{
for" 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 mean filtering Method/*
*/
#define N 12 char filter()
{
int sum = 0;
for ( count=0;count
{
if" (j="0;j<N-1;j++)" )="" +="get_ad();" 12[="" =="" [="" [align="left]int" align]="" align][align="left]{
sum" align]
4、递推平均滤波法(又称滑动平均滤波法)/*
*/
#define' char="" count="0;count<N;count++)" count,i,j;[="" count;="" delay();[="" filter()[="" get_ad();="" i="0;
" if="" int="" n="" n);[="" return="" sum="0;
value_buf[i++]" value_buf[count]="get_ad();" value_buf="" value_buf[n];="" value_buf[n];[="" {="" 冒泡法[="">value_buf[i+1] )
{
temp = value_buf; value_buf = value_buf[i+1]; value_buf[i+1 ] = temp;
}
}
}
for ( count=0;count
{
count++;
if" #define="" (="" (100-a)*value="" (char)(sum="" (count="0,count" (n-2));[="" (value="" *="" +="" 100,a="0~100" 12="" 12[="" 1、3[="" 50[="" =="" [="" [align="left]char" 参考子程序" a="" a*new_value;[="" align][align="left]}
" align]
6、限幅平均滤波法/*
*/
略' char="" code="" coe="" coe[n]="{1,2,3,4,5,6,7,8,9,10,11,12};
" count="0;count<N;count++)" count;[="" delay();[="" filter()[="" get_ad();="" int="" n="" new_value="get_ad();
return" new_value;="" new_value;[="" return="" sum="value_buf[count];" sum_coe="1+2+3+4+5+6+7+8+9+10+11+12;
" sum_coe);[="" value;[="" value_buf[count]="get_ad();" value_buf[n];="" while="" {="" 数组为加权系数表,存在程序存储区。*="">=N) return new_value; delay();new_value = get_ad();}return value;}10、Amplitude limiting and de-jittering filtering method/***/omitted Reference subroutine 1、9
11,IIR Filter exampleint BandpassFilter4(int InputAD4)
{
int ReturnValue; int ii; RESLO=0; RESHI=0;
MACS=*PdelIn;
OP2=1068; //FilterCoeff4[4]; MACS=*(PdelIn+1);
OP2=8; //FilterCoeff4[3]; MACS=*(PdelIn+2);
OP2=-2001;//FilterCoeff4[2]; MACS=*(PdelIn+3);
OP2=8; //FilterCoeff4[1]; MACS=InputAD4;
OP2=1068; //FilterCoeff4[0];
MACS=*PdelOu;
OP2=-7190;//FilterCoeff4[8]; MACS=*(PdelOu+1);
OP2=-1973; //FilterCoeff4[7]; MACS=*(PdelOu+2);
OP2=-19578;//FilterCoeff4[6]; MACS=*(PdelOu+3);
OP2=-3047; //FilterCoeff4[5];
*p=RESLO;
*(p+1)=RESHI;
mytestmul<<=2; ReturnValue=*(p+1); for (ii=0;ii<3;ii++)
{
DelayInput[ii]=DelayInput[ii+1]; DelayOutput[ii]=DelayOutput[ii+1];
}
DelayInput[3]=InputAD4; DelayOutput[3]=ReturnValue;
// if (ReturnValue<0)
// {
// ReturnValue=-ReturnValue;
// }
return ReturnValue;
}