当前位置:网站首页>Common software numerical filtering methods (I) have been applied
Common software numerical filtering methods (I) have been applied
2022-06-25 12:37:00 【haoming Hu】
MCU acquisition adc data , It is inevitable that the data will have great jitter at some time , At this time, a suitable numerical filtering algorithm is very good solution!
Bubble sort
Let's review the bubble sort first , Because many algorithms sort the data before processing , Here we won't explain what bubble sorting is , direct copy The following code is OK .
for (j = 0; j <11; j++) // The array length is 11
{
for (i = 0; i < 11-j-1; 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;
}
}
}
Median filtering
Continuous sampling N Time (N Take an odd number ) hold N The secondary sampling values are arranged according to the size, and the middle value is taken as the current effective value , It can effectively overcome the fluctuation interference caused by accidental factors 、 The measured parameters with slow change of liquid level have good filtering effect , But it's not absolute , Depending on your interval . The drawback is that it is not practical for high-speed signals , The comparison is to get the data first , Reprocessing .
Code : Here are all for the length 11 An array of .
float filter(float value_buf[])
{
int ii;
float x ,temp;
int i,j;
for (j = 0; j <11; j++)
{
for (i = 0; i < 11-j-1; 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[5];
}
Arithmetic average filtering
This is actually mean filtering , Continuous access N Sample values are arithmetic averaged .N When it's worth more : High signal smoothness , But the sensitivity is low ,N It's worth less : The signal smoothness is low , But the sensitivity is high , It is suitable for filtering signals with random interference
The characteristic of such a signal is that it has an average value , The signal fluctuates up and down near a certain range of values , However, it is not applicable to the real-time control with slow measurement speed or fast data calculation speed , More wasteful RAM.
To calculate the average value, there is no code posted here , This is too easy , The reason for this is that it will be used later .
Median average filtering method ( It is also called the average filtering method of anti pulse interference )
amount to “ Median filtering ”+“ Arithmetic average filtering ” Continuous sampling N Data , Take out a maximum and a minimum , And then calculate N-2 The arithmetic mean of data . For occasional impulsive interference , It can eliminate the sampling value deviation caused by pulse interference , The disadvantage is that the measurement speed is slow , It's the same as arithmetic average filtering , More wasteful RAM.
Code :
float filter2(float value_buf[])
{
int ii;
float x ,temp;
int i,j;
float sum=0;
for (j = 0; j <11; j++)
{
for (i = 0; i < 11-j-1; 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(ii=1;ii<10;ii++){
sum = sum+value_buf[ii];
}
return (sum/9);
}
In general , If there is enough time , A two-layer filter is recommended , That is to take 11 Secondary median value , Form an array , Then the array is filtered by the mean of the middle finger , The resulting data is basically very smooth !
In addition, there are many filtering methods to understand :
- Limiting filtering ( It is also called program judgment filtering method )
- Recursive average filtering ( It is also called moving average filtering method )*********** It is necessary to study
- Limiting average filtering method
- First order lag filtering
- Weighted recursive average filtering method
- Dithering filtering method
- The method of limiting amplitude and eliminating dithering
边栏推荐
- Explain AHP in human language (very detailed principle + simple tool implementation)
- Why should Apple change objc_ Type declaration for msgsend
- laravel 9
- Penetration tool environment - Installation of sqlmap
- Network | indicators and test methods to measure the quality of the network
- Learning notes 2022 overview | automatic graph machine learning, describing AGML methods, libraries and directions
- ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order
- 2022 meisai topic C idea sharing + translation
- JQ dynamic setting radio does not take effect when selected
- SDN system method | 9 Access network
猜你喜欢
What is the primordial universe
Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection
QT TCP UDP network communication < theory >
[论]Learning Dynamic and Hierarchical Traffic Spatiotemporal Features with Transformer
(4) Pyqt5 tutorial -- > Custom signal and slot (super winding...)
Matlab simulation of m-sequence
Why do we do autocorrelation analysis? Explain application scenarios and specific operations
(6) Pyqt5--- > window jump (registration login function)
High performance + million level Excel data import and export
K8s, docker compose install MySQL 8.0.18
随机推荐
Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities
Wechat forbids sharing
ARM V7 连续加载/存储
Qt5 multi thread operation implemented by object base class and use of movetothread method
Penetration tool environment -- use of cknife Chinese kitchen knife
Arm V7 coprocessor
Micro engine remote attachment 7 Niu cloud upload
Zhangxiaobai's way of penetration (VIII) - detailed operation steps of SQL injection - Boolean blind injection of blind injection
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the summary function to obtain the summary statistical information
If you also want to be we media, you might as well listen to Da Zhou's advice
JQ verifies whether the input color is legal
Renrenyue -- renrenyue system development source code sharing
Network | indicators and test methods to measure the quality of the network
GPS NMEA protocol, 0183 positioning data format dual mode positioning: gnxxx gps+bd full version
Mind mapping video
sudo: ulimit: command not found
Zhengzheng e-commerce source code -- Zhengzheng advertising e-commerce system development source code sharing
PHP appends the same elements to a two-dimensional array
R language uses GLM function to build Poisson logarithmic linear regression model, processes three-dimensional contingency table data to build saturation model, and poisgof function of epidisplay pack
PHP takes the difference set of two arrays