Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

rv_stat.h

Go to the documentation of this file.
00001 // 
00002 // author="Tony Kirke" *
00003 // Copyright(c) 2001 Tony Kirke
00004 // SPUC - Signal processing using C++ - A DSP library
00005 /* 
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 #ifndef STATC
00021 #define STATC
00022 #include <spuc.h>
00023 namespace SPUC {
00025 template <class Numeric> class rv_stat
00026 {
00027  protected:
00028   double count;
00029   Numeric av;
00030   Numeric sq;
00031   Numeric min_abs;
00032   Numeric max_abs;
00033 
00034  public:
00035   // Constructor
00036   rv_stat() {
00037         count = 0;
00038         av = 0;
00039         sq = 0;
00040         min_abs = MXLONG;
00041         max_abs = 0;
00042   }
00043   void update(Numeric x) {
00044         count += 1.0;
00045         av += x;
00046         sq += x*x;
00047         min_abs = MIN(ABS(min_abs),x);
00048         max_abs = MAX(ABS(max_abs),x);
00049   }  
00050   inline Numeric average() { if (count>0) return(av/count); else return(0);}
00051   inline Numeric mean_sq() { if (count>0) return(sq/count); else return(0); }
00052   inline Numeric rms() { return(sqrt(sq/count)); }
00053   inline Numeric var() { 
00054         if (count>0) return( sq/count - (av*av/(count*count))); 
00055         else    return(0); }
00056   inline Numeric std() { return(sqrt(var())); } 
00057   inline Numeric minimum() { return(min_abs); }
00058   inline Numeric maximum() { return(max_abs); }
00059 };
00060 }
00061 #endif

Generated on Fri Sep 16 11:02:28 2005 for spuc by  doxygen 1.4.4