Created
September 13, 2016 12:29
-
-
Save anonymous/7ae54f90fa923d055a5edcc29c9cc3fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
float varVolt; // среднее отклонение (ищем в excel) | |
float varProcess; // скорость реакции на изменение (подбирается вручную) | |
float Pc; | |
float G; | |
float P; | |
float Xp; | |
float Zp; | |
float Xe; | |
} KalmanFilterTypeDef; | |
// Инициализация фильтра | |
void KalmanFilterInit(KalmanFilterTypeDef *Filter, float Volt, float Process) { | |
Filter->varVolt = Volt; // среднее отклонение (ищем в excel) | |
Filter->varProcess = Process; // скорость реакции на изменение (подбирается вручную) | |
Filter->Pc = 0.0; | |
Filter->G = 0.0; | |
Filter->P = 1.0; | |
Filter->Xp = 0.0; | |
Filter->Zp = 0.0; | |
Filter->Xe = 0.0; | |
} | |
// Добавление нового значения | |
float KalmanFilter(KalmanFilterTypeDef *Filter, float NewData) { //функция фильтрации | |
Filter->Pc = Filter->P + Filter->varProcess; | |
Filter->G = Filter->Pc / (Filter->Pc + Filter->varVolt); | |
Filter->P = (1 - Filter->G) * Filter->Pc; | |
Filter->Xp = Filter->Xe; | |
Filter->Zp = Filter->Xp; | |
Filter->Xe = Filter->G * (NewData - Filter->Zp) + Filter->Xp; // "фильтрованное" значение | |
return(Filter->Xe); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment