Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 #ifndef PPRZ_STAT_H
24 #define PPRZ_STAT_H
25 
26 #include "std.h"
27 
37 static inline float variance_float(float * array, int nb) {
38  float me = 0.;
39  float see = 0.;
40  for (int i = 0; i < nb; i++) {
41  me += array[i];
42  see += array[i]*array[i];
43  }
44  me /= nb;
45  return (see/nb - me*me);
46 }
47 
57 static inline int32_t variance_int(int32_t * array, int nb) {
58  float me = 0;
59  float see = 0;
60  for (int i = 0; i < nb; i++) {
61  me += (float)array[i];
62  see += (float)(array[i]*array[i]);
63  }
64  me /= nb;
65  return (see/nb - me*me);
66 }
67 
68 
69 #endif
70 
static int32_t variance_int(int32_t *array, int nb)
Compute the variance of an array of values (integer).
Definition: pprz_stat.h:57
static float variance_float(float *array, int nb)
Compute the variance of an array of values (float).
Definition: pprz_stat.h:37
signed long int32_t
Definition: types.h:19