#define A 10
char value;
char filter()
{
char new_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
char filter()
{
char value_buf[N];
char count,i,j,temp;
for (count=0;count
value_buf[count]=get_ad();
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];
}
////////////////////////////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
int sum="0";
char filter()
{
char value_buf[N];
char count,i,j,temp;
for (count=0;count
value_buf[count]=get_ad();
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++)
{
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
char value;
char filter()
{
char new_value;
new_value=get_ad();
return (a*new_value+(1-a)*value);
}
Previous article:How to use the SST MCU P4 port
Next article:Common functions of single-chip microcomputers (filtering, character processing, etc.)
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Please answer my question: What is the role of capacitor in this synchronous buck circuit?
- 【Resistors】How to quickly read the color ring? Calculate the resistance value?
- MSP432 Serial Port Settings
- Practice together in 2021 + tomorrow will be better
- TMS320C66x dual loop and multiple loop optimization summary
- Can anyone share the third-party extension library of mixly?
- [Domestic RISC-V Linux Board Fang·Starlight VisionFive Trial Report] Successfully communicated with DWIN screen
- Looking for unboxing test of AWR1642BOOST
- What happens when a low-speed AD collects a high-frequency signal? (Those who have tried it or done a circuit experiment are welcome to come in!)
- 【RT-Thread Reading Notes】Chapter 7-10 Reading Notes