|
@@ -23,29 +23,6 @@ uint16_t MovingAverageFilter(uint16_t InputData, uint16_t* Array, uint16_t Lengt
|
|
|
return Result;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-滑动中值滤波
|
|
|
-InputData:最新采集值
|
|
|
-Array:缓存队列
|
|
|
-Length:缓存大小
|
|
|
-运行一次后,缓存队列最后一个数据为最新采集值,前面数据依次前移,返回值为缓存队列平均值
|
|
|
-*/
|
|
|
-uint16_t MovingMiddleFilter(uint16_t InputData, uint16_t* Array, uint16_t Length)
|
|
|
-{
|
|
|
- uint16_t Result, i;
|
|
|
-
|
|
|
- Result = GetMiddleData(Array, Length);
|
|
|
-
|
|
|
- for(i=0; i<(Length - 1); i++)
|
|
|
- {
|
|
|
- Array[i] = Array[i+1];
|
|
|
- }
|
|
|
-
|
|
|
- Array[Length - 1] = InputData;
|
|
|
-
|
|
|
- return Result;
|
|
|
-}
|
|
|
-
|
|
|
/*
|
|
|
取平均值
|
|
|
Input:输入数组
|
|
@@ -66,38 +43,6 @@ uint16_t GetAverageData(uint16_t* Input, uint16_t Length)
|
|
|
return Result;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-取中间值
|
|
|
-Input:输入数组
|
|
|
-Length:有效数据长度
|
|
|
-返回值为输入数组平均值
|
|
|
-*/
|
|
|
-uint16_t GetMiddleData(uint16_t* Input, uint16_t Length)
|
|
|
-{
|
|
|
- uint16_t i, Result = 0;
|
|
|
- uint16_t Temp[32];
|
|
|
-
|
|
|
- if(Length > 32)
|
|
|
- {
|
|
|
- return 0xFFFF;
|
|
|
- }
|
|
|
-
|
|
|
- for(i = 0; i < Length; i++)
|
|
|
- {
|
|
|
- Temp[i] = Input[i];
|
|
|
- }
|
|
|
- MinToMax(Temp, Length);
|
|
|
- if(Length % 2 == 0)//长度为偶数,取中间两个数的平均值
|
|
|
- {
|
|
|
- Result = (Temp[(Length >> 1) -1] + Temp[Length >> 1]) >> 1;
|
|
|
- }
|
|
|
- else//长度为奇数,取中间数
|
|
|
- {
|
|
|
- Result = Temp[(Length - 1) >> 1];
|
|
|
- }
|
|
|
- return Result;
|
|
|
-}
|
|
|
-
|
|
|
/*
|
|
|
三段曲线计算
|
|
|
0< InputData < Th1 : y = 1 - (Th1 - InputData) * K1
|
|
@@ -442,24 +387,6 @@ uint8_t CheckArrayIs0(uint8_t* Data, uint16_t Len)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-/*小到达排序*/
|
|
|
-void MinToMax(uint16_t* Input, uint16_t Len)
|
|
|
-{
|
|
|
- uint16_t i, j, Temp;
|
|
|
- for(i=0; i<Len - 1; i++)
|
|
|
- {
|
|
|
- for (j=0; j<Len - 1 - i; j++)
|
|
|
- {
|
|
|
- if (Input[j] > Input[j + 1])
|
|
|
- {
|
|
|
- Temp = Input[j];
|
|
|
- Input[j] = Input[j + 1];
|
|
|
- Input[j + 1] = Temp;//交换
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/*数组填充0*/
|
|
|
void ArrayFillZero(uint16_t* Array, uint16_t Length)
|
|
|
{
|