...
#define A 10 //A value can be adjusted according to actual conditions
char value; //value is a valid value
char filter()
{
char new_value; //new value is the current sampling value
new value=get_ad();
if ((new_value-value>A)‖(value-new_value>A)
return value;
return new_value;
}
///////////////////////////Median value filtering/////////////////////////
#define N 11 //N value can be adjusted according to actual situation
char filter()
{
char value_buf[N];
char count,i,j,temp;
for (count=0;count
value_buf[count]=get_ad(); //Get sampling value
delay();
}
for (j=0;j
for (i=0;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[(N-1)/2]; //Take the middle value
}
////////////////////////////Arithmetic average filtering//////////////////////
#define N 12
char filter()
{
int sum=0;
for(count=0;count
sum+=get_ad();
delay();
}
return (char)(sum/N);
}
/////////////////////Extremum average filtering ///////////////////////
#define N 11 //N value can be adjusted according to actual situation
int sum=0;
char filter()
{
char value_buf[N];
char count,i,j,temp;
for (count=0;count
value_buf[count]=get_ad(); //Get the sample value
delay();
}
for (j=0;j
for (i=0;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(count=1;count<(N-1);count++) //Remove the first and last number
{
sum+=value_buf[count];
delay();
}
return (char)(sum/(N-2));
}
////////////////////Moving average filter (recursive average filter)////////////
#define N 12
char value_buf[N];
char i=0;
char filter()
{
char count;
int sum=0;
value_buf[i++]=get_ad();
if(i=N) i=0;
for (count=0;count
return (char)(sum/N)
}
///////////////////////Weighted average filtering//////////////////////
#define N 12
char code jq[N]={1,2,3,4,5,6,7,8,9,10,11,12};//Weighting coefficient table
char code sum_jq=1+2+3+4+5+6+7+8+9+10+11+12;
char filter()
{
char count;
char value_buf[N];
int sum=0;
for (count=0;count
delay();
}
for (count=0;count
return (char)(sum/sum_jq);
}
///////////////////////////Low-pass filter////////////////////////
#define a 0.25
char value; //value is the existing value
char filter()
{
char new_value; //new value is the current sampling value
new_value=get_ad();
return (a*new_value+(1-a)*value);
}
Previous article:LCD12864 driver, serial mode
Next article:Touch screen ADS7846/7843 driver
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Questions about DAC zero scale and midscale
- Downloading files will cause the wireless mouse to freeze?
- [D-Gesture Recognition Device] Design Report Sharing of Topic D
- About FlexRay Communication Test
- Thank yourself
- Please advise on the design of a circulating water lamp
- Please recommend a domestic DC to DC chip
- How to get started with microcontrollers/embedded systems
- Raspberry Pi Windows IoT Development——by bigbat
- Solving MSP430 IFG1 &= ~OFIFG (clear oscillator failure flag)