I've been making metal detectors, the transmission coil sine wave signal produces the magnetic field, the change magnetic field again in two receives the coil to produce the same frequency, the phase and the amplitude change signal, the embedded chip through the AD chip module collects after the modulation signal, carries on the filtering processing to the collection signal data, removes the high-frequency part, removes the low-frequency part therefore need to use the C language programming, realizes the Matlab realizes the Watts filter and the Cheby filter. I hope that my algorithm can get good results of the filter to achieve the prototype production.
In the industrial process control system, because the environment of the controlled object is very bad, the interference source is more, instrument, instrument gather information often be disturbed, so in the simulation system, in order to eliminate the interference, the RC filter circuit is often used, but in the automatic detection system composed of industrial control computer, in order to improve the reliability of sampling, The digital filtering method is often used to reduce the influence of false information.
There are many kinds of digital filtering methods, which can be selected according to different measuring parameters. Below gives several commonly used digital filtering methods of C language functions, these functions have a certain versatility, with Turbo C 2.0 compiled, in Advantech ipc-610/386 machine are compiled, suitable for PC and its compatible machine. 1. The signal that the program counts the filter sampling, if because of the frequency of the random interference sensor is unstable and cause serious distortion, this method can be used. The method is: according to the production experience to determine the maximum allowable deviation of two cross sampling x, if two times sampled signal subtraction value is greater than X, indicating that the input is the interference signal, should be removed; with the last sample value as the sample value, if less than, equal to x indicates no interference, this time the sampling value effect. This method is suitable for the sampling of slow changing physical parameters, such as temperature, physical location and other measurement systems.
Program to determine the filtering of the C program function is as follows:
Float Program_detect_filter (float old_new_value[], float X)
{
float Sample_value;
if (Fabs (old_new_value[1]_old_new_value[0]) >x)
SAMPLE_VALUE=OLD_NEW_VALUE[0];
Else
SAMPLE_VALUE=OLD_NEW_VALUE[1];
Retrun (Sample_value);
}
function calls require a one-dimensional array of two elements (Old_new_value[2], which holds the last sampled value (Old_new_value[0],) and the current sampling value (old_new_value[1), and the function Sample_ Value represents a valid sampling value, and x represents the maximum deviation x allowed according to the two sampling that is determined based on experience.
2, Median filter
Median filter is a continuous input to a parameter n times (general N to take odd numbers), select a middle value as the sample value, if the variable change is relatively slow, the effect of this method is relatively good, but the rapid changes in the process of parameters, such as flow, natural gamma, etc., it is not suitable for use.
The C-Program function of median filter is as follows:
Float Middle_filter (float middle_value [], intcount)
{
float sample_value, data;
int I, J;
For (I=1 I for (j=count-1 j>=i,--j) {
if (middle_value[j-1]=middle_value[j]{
DATA=MIDDLE_VALUE[J-1];
MIDDLE_VALUE[J-1]=MIDDLE_VALUE[J]
Middle_value[j]=data;
}
}
Sample_value=middle_value (COUNT-1)/2];
return (Sample_value);
}
The function assumes that a parameter is sampled continuously for 3 times, and if sampled more than once, the function can be modified slightly. 3 sampling values are stored in array middle_value[3], where sample-value represents a valid sampling value, and count represents the number of consecutive samples.
3, sliding arithmetic mean filtering
The sliding arithmetic mean filter is to set a loop queue, in order to store n sampling data, each time data acquisition, first in the queue will be placed in the first collection of data lost, and then put the new data into the team tail, and then the new data, including the arithmetic average value of n data, then get the data of the second sampling. This method is mainly used for smoothing the sampling value of pressure, flow and other periodic pulsation.
The sliding arithmetic mean filter C program function is as follows:
Float Move_average_filtaer (float data_buf[], int count)
{
float sample_vaue,data=0;
int i;
For (I=0;i Data+=data_buf[i];
Sample_value= "/blog/data/count;
return (Sample_value;
}
The function assumption Order holds 5 sampling data data buffer data_buf[5], for more than 5 times the sliding arithmetic average filtering, only then can modify this function slightly, in which sample_value represents the valid data of this time sampling, count indicates the number of times of the data.
4. Slide weighted average filter sliding weighted average filter is to set a data buffer in order to store n times sampled data, every new data is collected, the first data is discarded, then the weighted average value of n data including the new data is obtained, then the valid data of the sampling is gotten. The smoothing effect of the method on impulsive interference is not satisfactory, and it is not suitable for the occasion of serious impulsive interference.
The C program function of the sliding weighted average filter is as follows:
Floa "Move_times_filter (float data _buf [])
{
float Sample_value;
float filter_k[3]={0.3,0.2,0.15 ";
sample_value=filter_k[0]*data_buf[2]+filter_k[1]* (Data_buf[1]
+DATA_BUF[3]) +filter_k[2]* (data_buf[0]+data_buf[4;
return (Sample_value);
}
function hypothesis in order to store 5 sampling data buffer data_buf[5], for more than 5 slip weighted average filtering, only a slight modification of the function, where the data group Filter_k[3] represents the weighting coefficient, the relationship between the three coefficients is filter_k[0]+2* Filter_k[1]+2*filter_k[2]=1, the valid data of this sampling is expressed by sample_value.
5, anti-pulse interference mean filtering
Anti-pulse interference mean filtering is a continuous sampling of n times, remove the maximum and the minimum value, and then the remaining N-2 data average, as the effective value of this sample. This method is suitable for the situation where variable jump is more serious. This kind of filtering also applies the method of calculating edge sampling edge.
Float Max_min_chioce (float x_buffer[],int number
{
int Max_value, Min_value;
float sample_value= "/blog/0.0;
int "I;
Max_value, =x_buffer[o];
MIN_VALUE=X_BUFFER[0];
for (I=1;i) {
if (X_buffer[i]>max_value) max_value=x_buffer[i];
if (X_buffer[i]}
For (i=0 i sample_value= (sample_value_max_value_min_value)/(number-2);
return (Sample_value);
}
The function hypothesis holds the data buffer data_buf[5 for 5 times of continuous sampling], for more than 5 times of the anti pulse interference mean filter, just modify the function slightly, in which the sample_value represents the valid data of the sampling, and number indicates the successive sampling times.
6. Low-Pass digital filter
Low-pass filter is also called the first-order hysteresis filter, the method is the nth sampling after the output value of the filter result is (1-a) by the nth sampling value plus a by the last filter results output value. Visible a<<1. This method is suitable for the filtering of the parameters with slow change process, the C program function is as follows:
Float Low_filter (float low_buf[])
{
float Sample_value;
float x=0.01;
Sample_value= (1_x) *low_buf[1]+x*low buf[0];
Retrun (Sample_value);
}
function hypothesis for the 2nd time after the sampling filter result output value Sampe_valeu, the array low_buf[2] represents the last filter result output value *low_buf[0]) and this time sampling value (low_buf[1), x represents a.
To facilitate the understanding of the above several filtering functions, the following procedure is given to call the above function.
#i nclude
#i nclude
#i nclude
Main ()
{
Folat old_new_buf[2]={1.2,2.6};
Float middle_value[3]={20,12,18};
Float data_average_buf[5]={10,20,20,10,10};
Float data_times_buf[5]={1.4,1.5,1.3,1.2,1.0};
Float data_max_min_buf[5]={1.2,80,1.4,0.2,1.3};
Foat low_buf[2]={1.2,2.0};
float xx;
Xx=program_detect_filter (old_new_buf,1.0};
printf ("The Program Detect filter Value is:%f\n", XX);
Xx=middle_filter (Middle_value, 3);
printf ("The middle filter value is:%f\n:,xx);"
Xx=move_avergae_filter (data_avergae_buf,5);
printf ("The Mover average filter value is:%f\n", XX);
Xx=move_times_filter (DATA_TIME_FUD);
printf ("The Move Times filter Value is:%f\n", XX);
Xx=max_min_choice (data_max_min_buf,5);
printf ("The Max-min filter Value is:%f\n", XX);
Xx=low_filter (LOW_BUF);
printf ("The Low filter Value is:%f\n", XX);
}
Run the execution program, the screen shows:
The program detect filter value is:1.200000
The middle filter value is:18.000000
The move average filter value is:14.000000
The Move Times filter value is:1.310000
The Max_min filter value is:1.366666
The Low filter value is:1.992000
This article refers to the notification address: http://patton.spaces.eepw.com.cn/articles/trackback/item/22983
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