Mercurial > hg > aim92
diff filter/scales.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filter/scales.c Fri May 20 15:19:45 2011 +0100 @@ -0,0 +1,102 @@ +/* + Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989 + =========================================================================== + + Permission to use, copy, modify, and distribute this software without fee + is hereby granted for research purposes, provided that this copyright + notice appears in all copies and in all supporting documentation, and that + the software is not redistributed for any fee (except for a nominal shipping + charge). Anyone wanting to incorporate all or part of this software in a + commercial product must obtain a license from the Medical Research Council. + + The MRC makes no representations about the suitability of this + software for any purpose. It is provided "as is" without express or implied + warranty. + + THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE + A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY + DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/* + scales.c + ======== + + generates double arrays of numbers spaced on arbitrary frequency scales + +*/ + +#include <math.h> + +#ifndef _STITCH_H_ +#include "stitch.h" +#endif +#ifndef _SCALES_H_ +#include "scales.h" +#endif + +double *GenerateScale( min, max, density, base, inverse ) +double min, max, density, base, (*inverse)() ; +{ + unsigned n_scale = NumberOnScale( min, max, density, base ) ; + double *scale = NewArray( double, n_scale+1, "for scale in scales.c" ) ; + double scale_start ; + int i ; + + if( min != max ) { + + scale_start = base - floor( ( base - min ) * density ) / density ; + + /* fill array scale points 1./density apart */ + + for( i=0 ; i < n_scale ; i++ ) + scale[ i ] = scale_start + i / density ; + + scale[ i++ ] = 0. ; + } + else { + scale[0] = min ; + scale[1] = 0. ; + } + + /* convert scale space back to units required */ + + if( inverse != (double ( * )()) 0 ) + for( i=0 ; i < n_scale ; i++ ) + scale[ i ] = inverse( scale[ i ] ) ; + + return ( scale ) ; +} + +int NumberOnScale( min, max, density, base ) +double min, max, density, base ; +{ + if( min != max ) + return ( ( int ) ( ( floor( ( base - min ) * density ) + 1. + ( floor( ( max - base ) * density ) ) ) ) ) ; + else + return ( 1 ) ; +} + +double *NumberedScale( min, max, channels, inverse ) +double min, max ; +int channels ; +double (*inverse)() ; +{ + DeclareNewArray( double, scale, channels+1, "for scale in scales.c" ) ; + int chan ; + + scale[ 0 ] = min ; + for( chan=1 ; chan < channels ; chan++ ) + scale[ chan ] = min + chan * (max-min) / ( channels - 1 ) ; + + if( inverse != (double ( * )()) 0 ) + for( chan=0 ; chan < channels ; chan++ ) + scale[ chan ] = inverse( scale[ chan ] ) ; + + scale[ channels ] = 0. ; + + return ( scale ) ; +}