Regarding low-pass filtering, let’s first look at the definition on Baidu Encyclopedia.
The formula for algorithm implementation is as follows:
y(n) = q*x(n) + (1-q)*y(n-1)
Where Y(n) is the output, x(n) is the input, y(n-1) is the last output value, and q is the filter coefficient. The value range is 0--1.
That is to say, if q=0.5, this formula means taking 50% of the current sampling value plus 50% of the previous sampling value as the current sampling result. In other words, each sampling result is related to the previous sampling result.
Take a look at the implementation of C code in the microcontroller
//Parameter: com is the original value of the sample
//Return value: iData sample value after first-order filtering
unsigned int lowV( unsigned int com )
{
static unsigned int iLastData; //Last value
unsigned int iData; //this calculation value
float dPower = 0.1; //Filter coefficient
iData = (com * dPower) + (1 - dPower) * iLastData; //Calculation
iLastData = iData; //Store this data
return iData; //Return data
}
//Main function
void main( void )
{
while( 1 )
{
val1 = ReadVol_CH3() ; // Read AD sampling value
val3 = lowV( val1 ); // The sampled value passes through the first-order filtering algorithm
printf("A%drn",val1); // print sampling value
printf("B%drn",val3); // Print the sample value after filtering algorithm
}
}
The input voltage is sampled through the ADC, and then the sampled value is filtered through a first-order filter. The sampled value and the value after the first-order filter are printed out through the serial port.
Through the serial port waveform display software, you can see the sampling results are:
When the filter coefficient q=0.1, the current sampling data accounts for 10% of the sampling result, and the previous sampling data accounts for 90% of the sampling result. That is to say, when the sampling data changes suddenly, it has little impact on the sampling result, and the sampled waveform is relatively smooth.
It can also be seen from the waveforms above that the blue waveform is the original data waveform, which has a relatively large fluctuation range, and the orange waveform is the waveform after the first-order filtering algorithm, which is relatively stable.
When the q value is changed to 0.5, take a look at the sampling situation.
It can be seen that when the filter coefficient increases to 0.5, the influence of the current sampling data and the previous sampling data on the result is 50% respectively. From the waveform, it can be seen that the waveform after filtering also fluctuates, but the fluctuation range is a little smaller than that of the original waveform.
Continue to increase the q value to 0.9 and look at the sampling situation.
It can be seen from the waveform that after the sampling coefficient is increased, the sampling data this time accounts for 90% of the influence on the sampling result. The waveform after the first-order filtering is basically synchronized with the original waveform, and the real-time performance is better, but the stability is slightly worse.
By comparing different filter coefficients, we found that:
The smaller the filter coefficient, the more stable the filtering result, but the lower the sensitivity;
The larger the filter coefficient, the higher the sensitivity, but the more unstable the filtering result.
In practical applications, appropriate filter coefficients are selected according to different needs to meet system requirements.
Previous article:MCU ADC sampling algorithm ---- Kalman filter
Next article:MCU ADC sampling algorithm ---- effective value sampling method
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- GD32E231 Learning 2: GPIO drive OLED and TC0 timing interrupt
- I need help with a power supply simulation question
- Smart home security integrated solution terminal
- Low Power Methodology Manual - For System-on-Chip Design
- Xilinx platform DDR3 design tutorial comprehensive chapter_Chinese version tutorial.pdf
- Ofweek Talent Network recruitment and job search results, let's talk about it
- EEWorld invites you to disassemble (fifth issue): dismantle power strips to learn circuits
- The first pit of domestic FPGA chip Sipeed Tang Nano 4K running routine
- Summary of Common Protection Circuits for Power Supply Circuits
- A flaw in the MSP430F672x, 673x microcontrollers