工具库的意义:
- 多个算法可使用同一工具库, 不用重复造轮子
- 将所用到的函数定义为结构体成员 方便使用及访问
typedef struct
{
void(*find_maxinfloatotfloat) (float*, int32_t, int32_t, float*, int32_t*);
}basic_mathfunc_t;
void Find_MaxInFloatOtFloat(float * datain, int32_t st_pos, int32_t ed_pos, float * res, int32_t *pos)
{
float resss = -2000000000.0f;
int32_t pos_1 = 0;
for (int32_t i = st_pos; i <= ed_pos; i++)
{
if (resss < datain[i])
{
resss = datain[i];
pos_1 = i;
}
}
if (res != NULL)
{
*res = resss;
}
if (pos != NULL)
{
*pos = pos_1;
}
}
void Basic_MathFuncReg(basic_mathfunc_t *basic_mathfunc_s)
{
basic_mathfunc_s->find_maxinfloatotfloat = Find_MaxInFloatOtFloat;
}
使用:
static basic_mathfunc_t basic_mathfunc_s;
Basic_MathFuncReg(basic_mathfunc_s);
basic_mathfunc_s->find_maxinfloatotfloat(datain, 0, 10, &max_val, &max_pos);
拓展:
在信号处理中, 常用的工具有:
- 最大值查找
- 最小值查找
- 均值查找
- std计算
- 求和
- fir滤波器
- 中值滤波
- 一维均值滤波
- iir陷波器
- 小波分解 与重构
- 形态学滤波
- 线性拟合
- 误差计算
- fft
- 窗
- RMS
- 等