1 /*--------------------------------------------------------------
2 Signal processing function library libsgp
3 ( Histogram analysis Rev.20000711 )
4 Written by H.Goto , Feb. 1995
5 Modified by H.Goto, July 2000
6 --------------------------------------------------------------*/
7
8 /*--------------------------------------------------------------------
9 Copyright (C) 1995-2000 Hideaki Goto
10
11 All Rights Reserved
12
13 Permission to use, copy, modify, and distribute this software and
14 its documentation for any purpose is hereby granted without fee,
15 provided that (i) the above copyright notice and this permission
16 notice appear in all copies and in supporting documentation, (ii)
17 the name of the author, Hideaki Goto, may not be used in any
18 advertising or otherwise to promote the sale, use or other
19 dealings in this software without prior written authorization
20 from the author, (iii) this software may not be used for
21 commercial products without prior written permission from the
22 author, and (iv) the notice of the modification is specified in
23 case of that the modified copies of this software are distributed.
24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
26 THE AUTHOR WILL NOT BE RESPONSIBLE FOR ANY DAMAGE CAUSED BY THIS
27 SOFTWARE.
28 --------------------------------------------------------------------*/
29
30
31 #include <stdio.h>
32 #include <math.h>
33
34 #include "sgplib.h"
35
36
sgp_gethistmeani(int * hist,int len)37 double sgp_gethistmeani(int *hist,int len){ /* Get mean posision */
38 int i,sum,hsum;
39 sum = hsum = 0;
40 for ( i=0 ; i<len ; i++ ){
41 sum += hist[i];
42 hsum += i * hist[i];
43 }
44 if ( !sum ) return(0);
45 return( (double)hsum / (double)sum );
46 }
47
48
sgp_gethistsdi(int * hist,int len,double mean)49 double sgp_gethistsdi(int *hist,int len,double mean){
50 int i,h,sum;
51 double d,sd;
52 sd = 0;
53 sum = 0;
54 for ( i=0 ; i<len ; i++ ){
55 h = *hist++;
56 sum += h;
57 d = (double)i - mean;
58 sd += (double)h * (d * d);
59 }
60 if ( !sum ) return(0);
61 return ( sqrt(sd / sum) );
62 }
63
64
sgp_gethistmdi(int * hist,int len,double mean)65 double sgp_gethistmdi(int *hist,int len,double mean){
66 int i,h,sum;
67 double md;
68 md = 0;
69 sum = 0;
70 for ( i=0 ; i<len ; i++ ){
71 h = *hist++;
72 sum += h;
73 md += (double)h * fabs((double)i - mean);
74 }
75 if ( !sum ) return(0);
76 return ( md / sum );
77 }
78
79
80