public static double [ ] averageSmooth ( double [ ] values , int lookAhead ) throws Exception { int size = values . length ; double [ ] newValues = new double [ values . length ] ; for ( int i = 0 ; i < lookAhead ; i ++ ) { newValues [ i ] = values [ i ] ; } for ( int i = lookAhead ; i < size - lookAhead ; i ++ ) { double sum = 0.0 ; int k = 0 ; for ( int l = - lookAhead ; l <= lookAhead ; l ++ ) { double value = values [ i + l ] ; if ( ! isNovalue ( value ) ) { sum = sum + value ; k ++ ; } } newValues [ i ] = sum / k ; } for ( int i = size - lookAhead ; i < size ; i ++ ) { newValues [ i ] = values [ i ] ; } return newValues ; }
Smooth an array of values with an averaging moving window .