A detailed introduction to several digital filtering design principles

Data acquisition, also known as data acquisition, uses a device that collects data from outside the system and inputs it to an interface inside the system. Data collection techniques are widely cited in various fields. For example, the camera and the microphone are all data acquisition tools. The collected data is various physical quantities that have been converted into electrical signals, such as temperature, water level, wind speed, pressure, etc., and may be analog or digital. Today, with the rapid development of the Internet industry, data collection has been widely used in the Internet and distributed fields, and important changes have taken place in the field of data collection.

There are various noises in data acquisition. There are many ways to filter out noise, both digital and analog. Here we use a microcontroller and C language to design and develop a digital filtering system.

For the random interference that often occurs in the data acquisition system of single-chip microcomputer, the data acquisition process is simulated by manual input, and several digital filtering algorithms of single-chip microcomputer which overcome the random interference are verified, and the corresponding C program is given. The median value filtering and median average filtering algorithm programs have been improved. At the same time, these filtering algorithms are compared, and the specific scope and precautions of each algorithm are pointed out. In addition, we used proteus to simulate and verify these filtering methods. In addition, we also use AD and DA to collect and output data.

1 Digital Filter Design Principle

There are many kinds of digital filtering methods here, we can choose several of them to design, such as median filtering, arithmetic average filtering, weighted average filtering and so on. So I will introduce them in detail below.

1.1 Median filtering

The median value filtering is to first continuously sample a parameter for N times (generally N takes an odd number), and then arrange the N times of sample values ​​from small to large, taking the intermediate value as the current sampled value.

This filtering method is actually a sorting method, and I am using bubble sorting here. Since the data of the former is larger than the latter data in the sorting of the bubble method, the exchange of the two data is performed.

The sample program of the algorithm is as follows:

#define N 11 //The value of N can be adjusted according to the actual situation. char filter() { char value_buf[]; char count,i,j,k,temp; for(count=0;count

The median value filtering can effectively overcome the pulse interference caused by the accidental factors or the error caused by the sampler instability. This algorithm can receive good filtering effects on measured parameters such as temperature and liquid level, but it is not suitable for median filtering for data such as flow rate and pressure.

1.2 arithmetic average filtering

The arithmetic average filtering method is suitable for filtering signals with general random interference. This signal is characterized by the fact that the signal itself fluctuates up and down around a range of values, as is often the case when measuring flow and level. The arithmetic average filtering method is to find such a Y according to the input N sample data, so that the sum of the squares of the deviation between Y and each sample value is the smallest.

The subroutine that implements this algorithm is as follows:

#define N 12 char filter() { int count; int sum=0; for(count=0; count arithmetic mean filtering is applied to filter signals that generally have random interference. This signal is characterized by an average value. The signal fluctuates up and down around a certain range of values. In this case, it is obviously inaccurate to take only one sampled value. The smoothing procedure of the arithmetic average filtering on the signal depends entirely on N, and when N is large, the smoothness High, but low sensitivity; when N is small, the smoothness is low, but the sensitivity is high. N should be selected according to the specific situation, so as to occupy less calculation time and achieve the best effect.

1.3 Weighted average filtering

In the arithmetic average filtering and the moving average filtering, the weights of the N sampling values ​​in the output result are equal, taking 1/N. With such a filtering algorithm, hysteresis is introduced for a time-varying signal, and the larger the value of N, the more severe the hysteresis. In order to increase the weight of the new sampled data in the moving average to improve the sensitivity of the system to the interference in the current sampled value, weighted average filtering can be used, which is an improvement of the moving average filtering algorithm.

The weighted average filtering is to multiply successive N times of sampling values ​​by different weighting systems and then add and sum. The weighting system is generally small and large to highlight the effect of several subsequent samples, and strengthen the system to identify the trend of parameter changes. Each weighting system is a fraction less than one and satisfies the constraint that the sum is equal to one. Thus, the accumulated sum after the weighting operation is the effective sample value.

For the convenience of calculation, each weighting coefficient is an integer, and the sum is 256. The accumulated sum after the weighting operation is divided by 256, that is, the effective sample value is obtained after the low byte is discarded. The specific sample program is as follows:

// The code array is a weighted system table with a ROM area. #define N 12 char code jq[N]={1,2,3,4,5,6,7,8,9,10,11,12}; char code sum_jp=1+2+3+4+5 +6+7+8+9+10+11+12; char filter_5() { char count; char value_buf[N]; int sum=0; for(count=0;count which is equivalent to "median value filtering" Combined with the "arithmetic average filtering method", it continuously samples N data, then removes a maximum value and a minimum value, and finally calculates the arithmetic mean of N-2 data. The selection of the general N value: 3-14.

The specific algorithm is as follows:

#define N 12 char filter() { char count,i,j; char value_buf[N]; int sum=0; for (count=0;countvalue_buf[i+1] ) { temp = value_buf[i]; value_buf[ i] = value_buf[i+1]; value_buf[i+1] = temp; } } } for(count=1; count This filtering method is compatible with the advantages of the moving average filtering algorithm and the median filtering algorithm, so For slow-changing signals, or for fast-changing signals, better filtering results can be achieved.

1.5 limiting filter

The basic principle of limiting filtering is to subtract the sampled values ​​Yn and Yn-1 of two adjacent moments (n and n-1), find the difference, express it as an absolute value, and then divide the difference twice. The maximum deviation value ΔY allowed for sampling is compared. If the difference between the two sample values ​​exceeds the maximum allowable deviation value ΔY, random interference is considered to occur, and the last sample value Yn is considered illegal and should be rejected. After Yn is removed, Yn-1 can be used instead of Yn; if the maximum allowable deviation range is not exceeded, the current sample value is considered valid. It can be expressed by the following formula:

|Yn-Yn-1|≤ΔY; then Yn is valid

|Yn-Yn-1|>ΔY; then Yn-1 is valid

The sample program of this algorithm is as follows:

#define A 10 //A value can adjust char data according to the actual situation; //The last data char filter_1() { char datanew; //New data variable datanew=get_data(); //Get new data //filter algorithm If ((datanew-data)A)||(data-datanew)A) return data; return datanew; }

The algorithm is mainly used to process data with relatively slow changes, such as temperature, location of objects, and so on. The key to the selection of Δy of the maximum deviation value during use is usually obtained empirically, and the value of ΔY, that is, ΔY=VmaxT, may be determined according to the maximum possible change speed Vmax of the output parameter and the sampling period T.

Portable Solar Panel

Portable Solar Panel,Portable Solar Charger,Portable Solar Power,Portable Solar

suzhou whaylan new energy technology co., ltd , https://www.whaylan.com

This entry was posted in on