1 /* 2 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 3 * Copyright (C) 2005-2015, Anthony Minessale II <anthm@freeswitch.org> 4 * 5 * Version: MPL 1.1 6 * 7 * The contents of this file are subject to the Mozilla Public License Version 8 * 1.1 (the "License"); you may not use this file except in compliance with 9 * the License. You may obtain a copy of the License at 10 * http://www.mozilla.org/MPL/ 11 * 12 * Software distributed under the License is distributed on an "AS IS" basis, 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * for the specific language governing rights and limitations under the 15 * License. 16 * 17 * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 18 * 19 * The Initial Developer of the Original Code is 20 * Anthony Minessale II <anthm@freeswitch.org> 21 * Portions created by the Initial Developer are Copyright (C) 22 * the Initial Developer. All Rights Reserved. 23 * 24 * Contributor(s): 25 * 26 * Dragos Oancea <droancea@yahoo.com> 27 * 28 * switch_estimators.h -- Estimators for Packet Loss, Jitter, RTT , etc 29 * 30 */ 31 32 33 #ifndef SWITCH_ESTIMATORS_H 34 #define SWITCH_ESTIMATORS_H 35 36 37 #include <switch.h> 38 39 40 SWITCH_BEGIN_EXTERN_C 41 42 struct kalman_estimator_s { 43 /* initial values for the Kalman filter */ 44 float val_estimate_last ; 45 float P_last ; 46 /* the noise in the system: 47 The amount of noise in your measurements and the state-transitions 48 (e.g. the standard deviation of the signal noise, and how 'wrong' your simplified model 49 of the state-transitions are) => These are Q and R matrices */ 50 float Q ; /* the process noise covariance matrix */ 51 float R ; /* the measurement noise covariance matrix */ 52 float K; /* P_temp * H^T * (H* P_temp * H^T + R)^-1 */ 53 float P; /* the Kalman gain (calculated) */ 54 float val_estimate; /* x_temp_est + K * (z_measured - H * x_temp_est) */ 55 float val_measured; /* the 'noisy' value we measured */ 56 }; 57 58 struct cusum_kalman_detector_s { 59 /* initial values for the CUSUM Kalman filter */ 60 float val_estimate_last; 61 float val_desired_last; 62 float P_last; 63 float K_last; 64 float delta; 65 float measurement_noise_e; 66 float variance_Re; 67 float measurement_noise_v; 68 float variance_Rv; 69 float g_last; 70 /*constants per model*/ 71 float epsilon; 72 float h; 73 /* for calculating variance */ 74 float last_average; 75 float last_q; 76 float N; /*how many samples we have so far (eg: how many RTCP we received, granted that we can calculate RTT for each one of them)*/ 77 }; 78 79 typedef struct kalman_estimator_s kalman_estimator_t; 80 typedef struct cusum_kalman_detector_s cusum_kalman_detector_t; 81 82 SWITCH_DECLARE(void) switch_kalman_init(kalman_estimator_t *est, float Q, float R); 83 SWITCH_DECLARE(switch_bool_t) switch_kalman_cusum_init(cusum_kalman_detector_t *detect_change, float epsilon,float h); 84 SWITCH_DECLARE(switch_bool_t) switch_kalman_estimate(kalman_estimator_t * est, float measurement, int system_model); 85 SWITCH_DECLARE (switch_bool_t) switch_kalman_cusum_detect_change(cusum_kalman_detector_t * detector, float measurement, float rtt_avg); 86 SWITCH_DECLARE(switch_bool_t) switch_kalman_is_slow_link(kalman_estimator_t * est_loss, kalman_estimator_t * est_rtt); 87 88 SWITCH_END_EXTERN_C 89 #endif 90 91 /* For Emacs: 92 * Local Variables: 93 * mode:c 94 * indent-tabs-mode:t 95 * tab-width:4 96 * c-basic-offset:4 97 * End: 98 * For VIM: 99 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: 100 */ 101