annotate filter/formulae.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
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
tomwalters@0 3 ===========================================================================
tomwalters@0 4
tomwalters@0 5 Permission to use, copy, modify, and distribute this software without fee
tomwalters@0 6 is hereby granted for research purposes, provided that this copyright
tomwalters@0 7 notice appears in all copies and in all supporting documentation, and that
tomwalters@0 8 the software is not redistributed for any fee (except for a nominal shipping
tomwalters@0 9 charge). Anyone wanting to incorporate all or part of this software in a
tomwalters@0 10 commercial product must obtain a license from the Medical Research Council.
tomwalters@0 11
tomwalters@0 12 The MRC makes no representations about the suitability of this
tomwalters@0 13 software for any purpose. It is provided "as is" without express or implied
tomwalters@0 14 warranty.
tomwalters@0 15
tomwalters@0 16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
tomwalters@0 17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
tomwalters@0 18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
tomwalters@0 19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
tomwalters@0 20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
tomwalters@0 21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
tomwalters@0 22 */
tomwalters@0 23
tomwalters@0 24 /*
tomwalters@0 25
tomwalters@0 26 formulae.c
tomwalters@0 27 ==========
tomwalters@0 28
tomwalters@0 29 Functions from : Moore and Glasberg, Formulae describing frequency
tomwalters@0 30 selectivity as a function or frequency and level, and their use in
tomwalters@0 31 calculating excitation paterns. Hearing reserch, 28 (1987) 209-225
tomwalters@0 32
tomwalters@0 33 */
tomwalters@0 34
tomwalters@0 35 #include <math.h>
tomwalters@0 36 #include <stdio.h>
tomwalters@0 37 #include "../glib/options.h"
tomwalters@0 38
tomwalters@0 39 #ifndef _FORMULAE_H_
tomwalters@0 40 #include "formulae.h"
tomwalters@0 41 #endif
tomwalters@0 42
tomwalters@0 43 /* latest erb function circa. 1989 from BBG & CJM */
tomwalters@0 44
tomwalters@0 45 /* derived from erb = 24.7 * ( 4.37e-3 * f + 1 ) */
tomwalters@0 46
tomwalters@0 47
tomwalters@0 48 static double limit = 24.7 ; /* limit = k1 */
tomwalters@0 49 static double Q = 9.265 ; /* Q = 1. / ( k1 * k2 ) */
tomwalters@0 50
tomwalters@0 51
tomwalters@0 52 void SetErbParameters( new_limit, new_Q )
tomwalters@0 53 double new_limit, new_Q ;
tomwalters@0 54 {
tomwalters@0 55 limit = new_limit ;
tomwalters@0 56 Q = new_Q ;
tomwalters@0 57
tomwalters@0 58 return ;
tomwalters@0 59 }
tomwalters@0 60
tomwalters@0 61
tomwalters@0 62 double Erb( frequency )
tomwalters@0 63 double frequency ;
tomwalters@0 64 {
tomwalters@0 65 return ( limit + frequency / Q ) ;
tomwalters@0 66 }
tomwalters@0 67
tomwalters@0 68 /* integrate 1/erb(f) to get erb based scale */
tomwalters@0 69
tomwalters@0 70 double ErbScale( frequency )
tomwalters@0 71 double frequency ;
tomwalters@0 72 {
tomwalters@0 73 return ( log( 1. + frequency / Q / limit ) * Q ) ;
tomwalters@0 74 }
tomwalters@0 75
tomwalters@0 76
tomwalters@0 77 double FofErbScale( E )
tomwalters@0 78 double E ;
tomwalters@0 79 {
tomwalters@0 80 return ( ( exp( E / Q ) - 1 ) * Q * limit ) ;
tomwalters@0 81 }
tomwalters@0 82
tomwalters@0 83
tomwalters@0 84 double poly( coefts, x )
tomwalters@0 85 double *coefts, x ;
tomwalters@0 86 {
tomwalters@0 87 double *cptr = coefts ;
tomwalters@0 88 double power = 1 ;
tomwalters@0 89 double value = 0 ;
tomwalters@0 90
tomwalters@0 91 while( *cptr != 0. ) {
tomwalters@0 92 value += *cptr++ * power ;
tomwalters@0 93 power *= x ;
tomwalters@0 94 }
tomwalters@0 95
tomwalters@0 96 return ( value ) ;
tomwalters@0 97 }
tomwalters@0 98
tomwalters@0 99 double dBAudiogram( frequency )
tomwalters@0 100 double frequency ;
tomwalters@0 101 {
tomwalters@0 102 static double audiogram_polynomial_coeficients[] = {
tomwalters@0 103 2661.8, -3690.1, 1917.4, -440.77, 37.706, 0. } ;
tomwalters@0 104
tomwalters@0 105 return ( poly( audiogram_polynomial_coeficients, log10( frequency ) ) ) ;
tomwalters@0 106 }
tomwalters@0 107
tomwalters@0 108 double Audiogram( frequency )
tomwalters@0 109 double frequency ;
tomwalters@0 110 {
tomwalters@0 111 return ( pow( 10., -dBAudiogram( frequency ) / 20. ) ) ;
tomwalters@0 112 }
tomwalters@0 113
tomwalters@0 114
tomwalters@0 115 /* old versions of above */
tomwalters@0 116
tomwalters@0 117 static double erb_a = { 6.23e-6 },
tomwalters@0 118 erb_b = { 93.39e-3 },
tomwalters@0 119 erb_c = { 28.52 } ;
tomwalters@0 120
tomwalters@0 121 /* erb rate function coeficients */
tomwalters@0 122
tomwalters@0 123 static double erb_k1 = { 11.17 },
tomwalters@0 124 erb_k2 = { 0.312 },
tomwalters@0 125 erb_k3 = { 14.675 },
tomwalters@0 126 erb_k4 = { 43.0 } ;
tomwalters@0 127
tomwalters@0 128 static double b0 = { 2661.8 },
tomwalters@0 129 b1 = { 3690.1 },
tomwalters@0 130 b2 = { 1917.4 },
tomwalters@0 131 b3 = { 440.77 },
tomwalters@0 132 b4 = { 37.706 } ;
tomwalters@0 133
tomwalters@0 134 double OldErb( f )
tomwalters@0 135 double f ;
tomwalters@0 136 {
tomwalters@0 137 return ( erb_a * f * f + erb_b * f + erb_c ) ;
tomwalters@0 138 }
tomwalters@0 139
tomwalters@0 140 double OldErbScale( f )
tomwalters@0 141 double f ;
tomwalters@0 142 {
tomwalters@0 143 double fkHz ;
tomwalters@0 144
tomwalters@0 145 fkHz = f / 1000. ;
tomwalters@0 146
tomwalters@0 147 return ( erb_k1 * log( ( fkHz + erb_k2 ) / ( fkHz + erb_k3 ) ) + erb_k4 ) ;
tomwalters@0 148 }
tomwalters@0 149
tomwalters@0 150 double OldFofErbScale( E )
tomwalters@0 151 double E ;
tomwalters@0 152 {
tomwalters@0 153 double tmp ;
tomwalters@0 154
tomwalters@0 155 tmp = exp( ( E - erb_k4 ) / erb_k1 ) ;
tomwalters@0 156
tomwalters@0 157 return ( ( erb_k2 - erb_k3 * tmp ) / ( tmp - 1.0 ) * 1000. ) ;
tomwalters@0 158 }
tomwalters@0 159