comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal shipping
9 charge). Anyone wanting to incorporate all or part of this software in a
10 commercial product must obtain a license from the Medical Research Council.
11
12 The MRC makes no representations about the suitability of this
13 software for any purpose. It is provided "as is" without express or implied
14 warranty.
15
16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24 /*
25 scales.c
26 ========
27
28 generates double arrays of numbers spaced on arbitrary frequency scales
29
30 */
31
32 #include <math.h>
33
34 #ifndef _STITCH_H_
35 #include "stitch.h"
36 #endif
37 #ifndef _SCALES_H_
38 #include "scales.h"
39 #endif
40
41 double *GenerateScale( min, max, density, base, inverse )
42 double min, max, density, base, (*inverse)() ;
43 {
44 unsigned n_scale = NumberOnScale( min, max, density, base ) ;
45 double *scale = NewArray( double, n_scale+1, "for scale in scales.c" ) ;
46 double scale_start ;
47 int i ;
48
49 if( min != max ) {
50
51 scale_start = base - floor( ( base - min ) * density ) / density ;
52
53 /* fill array scale points 1./density apart */
54
55 for( i=0 ; i < n_scale ; i++ )
56 scale[ i ] = scale_start + i / density ;
57
58 scale[ i++ ] = 0. ;
59 }
60 else {
61 scale[0] = min ;
62 scale[1] = 0. ;
63 }
64
65 /* convert scale space back to units required */
66
67 if( inverse != (double ( * )()) 0 )
68 for( i=0 ; i < n_scale ; i++ )
69 scale[ i ] = inverse( scale[ i ] ) ;
70
71 return ( scale ) ;
72 }
73
74 int NumberOnScale( min, max, density, base )
75 double min, max, density, base ;
76 {
77 if( min != max )
78 return ( ( int ) ( ( floor( ( base - min ) * density ) + 1. + ( floor( ( max - base ) * density ) ) ) ) ) ;
79 else
80 return ( 1 ) ;
81 }
82
83 double *NumberedScale( min, max, channels, inverse )
84 double min, max ;
85 int channels ;
86 double (*inverse)() ;
87 {
88 DeclareNewArray( double, scale, channels+1, "for scale in scales.c" ) ;
89 int chan ;
90
91 scale[ 0 ] = min ;
92 for( chan=1 ; chan < channels ; chan++ )
93 scale[ chan ] = min + chan * (max-min) / ( channels - 1 ) ;
94
95 if( inverse != (double ( * )()) 0 )
96 for( chan=0 ; chan < channels ; chan++ )
97 scale[ chan ] = inverse( scale[ chan ] ) ;
98
99 scale[ channels ] = 0. ;
100
101 return ( scale ) ;
102 }