Summary of commonly used algorithms for sensor data in microcontroller development

Publisher:AmpouleLatest update time:2022-12-15 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

sliding mean filter algorithm

Various sensors are used in the embedded development process, such as pressure sensors, light sensors, acceleration sensors, temperature and humidity sensors, angular rate sensors, etc. The data collection process of these sensors is mixed with noise, which makes the sensor measurement accuracy error too large [sensor data fluctuates greatly]. The source of sensor data output noise may be caused by many factors such as vibration, temperature changes, electromagnetic interference, etc. Often we use digital signal processing methods to eliminate or suppress this noise. Commonly used mathematical methods include FFT filtering algorithm, DFT filtering algorithm, Kalman algorithm, median filtering algorithm, average filtering algorithm, sliding mean filtering, least squares method, sorting algorithm, limiting filtering algorithm, high-pass filtering, low-pass filtering, etc. Each algorithm has its own characteristics and application scenarios. Making good use of these mathematical tools can make your products or works more soulful.


This series of articles mainly explains the above various algorithms and application scenarios. The text first introduces the sliding mean filter algorithm.


Take the multi-channel voltage acquisition system project in the practical entry-level STM32 software project as an example to describe sliding mean filtering. Before that, we must clarify why sliding mean filtering is used in ADC acquisition. First, the analog quantity of the acquisition port may be mixed with interference signals of different frequency bands and different peaks. Then the amount of data collected by the ADC will deviate from the original real result. Then the acquisition error can be greatly reduced and the accuracy improved through two means: hardware and digital filtering. Software methods include arithmetic average (which is the sum of N values ​​and then divided by the number of values.), sliding average filter, Kalman, FFT, etc.


The steps to implement the sliding mean filter algorithm are as follows: The first is to acquire sensor data. The ADC + cyclic DMA method is used to collect voltage data, with 5 data as a group, and these data are queued in sequence, that is, the following array. The first entry The data to the queue is flushed continuously, and the purpose of data sliding can be achieved in turn.

Code

The picture shows the sliding mean filtering of the 5-channel ADC sampling values. Every five channels are sequentially averaged. Because the data in ADC_ConvertedValue[] is continuously refreshed by DMA, the sliding of the data is realized.

The picture below shows how MATLAB is used to process the collected data with sliding mean filtering. Blue is the original signal with noise, and red is the processed signal. It can be seen that sliding mean filtering can filter out a large amount of noise [burr].

Simulation renderings

The characteristics of sliding mean filter when used are as follows: it has good suppression effect on periodic interference signals, has high smoothness, is suitable for high-rate signal acquisition, and the algorithm is simple and easy to calculate. Because the ADC acquisition is above 100KHz, this algorithm is suitable for this application scenario.


A large N value will result in low sensitivity. This algorithm is not suitable for large interference signals, that is, when the signal-to-noise ratio is small.


Reference address:Summary of commonly used algorithms for sensor data in microcontroller development

Previous article:C language programming suggestions and techniques are also applicable to the learning of microcontrollers.
Next article:What are the tips and tricks about learning and finding a job with microcontrollers?

Latest Microcontroller Articles
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号