Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pprz_stat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Gautier Hattenberger (ENAC)
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef PPRZ_STAT_H
28 #define PPRZ_STAT_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include "std.h"
35 
45 static inline float variance_float(float *array, int nb)
46 {
47  float me = 0.;
48  float see = 0.;
49  for (int i = 0; i < nb; i++) {
50  me += array[i];
51  see += array[i] * array[i];
52  }
53  me /= nb;
54  return (see / nb - me * me);
55 }
56 
66 static inline int32_t variance_int(int32_t *array, int nb)
67 {
68  float me = 0;
69  float see = 0;
70  for (int i = 0; i < nb; i++) {
71  me += (float)array[i];
72  see += (float)(array[i] * array[i]);
73  }
74  me /= nb;
75  return (see / nb - me * me);
76 }
77 
78 #ifdef __cplusplus
79 } /* extern "C" */
80 #endif
81 
82 #endif /* PPRZ_STAT_H */
static int32_t variance_int(int32_t *array, int nb)
Compute the variance of an array of values (integer).
Definition: pprz_stat.h:66
static float variance_float(float *array, int nb)
Compute the variance of an array of values (float).
Definition: pprz_stat.h:45
signed long int32_t
Definition: types.h:19