本文是学习记录关于rib源码中使用的kalman滤波,因为整个定位系统存在误差以及不确定性,需要使用kalman滤波进行预测和平滑,在rtklib中使用的是EKF,即扩展kalman滤波,具体关于kalman滤波理论的学习参考这里,同样,本文仅解读代码部分。
首先了解定义函数部分,由于部分定义函数仅适用于矩阵方面,因此将这部分定义函数的解读放在kalman滤波这里。
目录
1、简单矩阵
1.1、mat()
创建一个n*m的矩阵
/* new matrix ------------------------------------------------------------------
* allocate memory of matrix
* args : int n,m I number of rows and columns of matrix
* return : matrix pointer (if n<=0 or m<=0, return NULL)
*-----------------------------------------------------------------------------*/
extern double *mat(int n, int m)
{
double *p;
if (n<=0||m<=0) return NULL;//首先判定n和m是否大于0
if (!(p=(double *)malloc(sizeof(double)*n*m))) {
//这里是为一个n行m列的矩阵开辟内存空间,并同时进行是否开辟正常的判定
fatalerr("matrix memory allocation error: n=%d,m=%d\n",n,m);
}
return p;
}
1.2、imat()
创造一个n*m的整数矩阵,int类型
/* new integer matrix ----------------------------------------------------------
* allocate memory of integer matrix
* args : int n,m I number of rows and columns of matrix
* return : matrix pointer (if n<=0 or m<=0, return NULL)
*-----------------------------------------------------------------------------*/
extern int *imat(int n, int m)
{
int *p;
if (n<=0||m<=0) return NULL;
if (!(p=(int *)malloc(sizeof(int)*n*m))) {
fatalerr("integer matrix memory allocation error: n=%d,m=%d\n",n,m);
}
return p;
}
1.3、 zero()
创造一个n*m的0矩阵
/* zero matrix -----------------------------------------------------------------
* generate new zero matrix
* args : int n,m I number of rows and columns of matrix
* return : matrix pointer (if n<=0 or m<=0, return NULL)
*-----------------------------------------------------------------------------*/
extern double *zeros(int n, int m)
{
double *p;
#if NOCALLOC
if ((p=mat(n,m))) for (n=n*m-1;n>=0;n--) p[n]=0.0;
#else//首先创造一个n*m矩阵,然后通过循环将矩阵的每一个元素的值减到0
if (n<=0||m<=0) return NULL;
if (!(p=(double *)calloc(sizeof(double),n*m))) {
fatalerr("matrix memory allocation error: n=%d,m=%d\n",n,m);
}
#endif//不清楚这部分为什么多个定义
return p;
}
1.4、eye()
创造一个n*n的主对角线元素为1的矩阵
/* identity matrix --------------------