SCANDLE Auditory Periphery Model Programmer's Guide

27
SCANDLE Auditory Periphery Model Programmer’s Guide Version 4.0 25 May 2011 contact: [email protected] 1. Introduction ........................................................................................................................ 2 2. Matlab Quick-Start (Windows) .......................................................................................... 4 3. Basilar Membrane Model ................................................................................................... 5 4. Payton’s Inner Hair Cell Model........................................................................................ 10 5. Meddis’ Inner Hair Cell Model ........................................................................................ 17 6. Rate Map........................................................................................................................... 21 7. Cochlear Model ................................................................................................................ 22 8. References ........................................................................................................................ 23 9. Appendix: Correction to Coefficient ................................................................................ 24

Transcript of SCANDLE Auditory Periphery Model Programmer's Guide

SCANDLE Auditory Periphery Model Programmer’s Guide Version 4.0 25 May 2011 contact: [email protected]

1. Introduction ........................................................................................................................ 2

2. Matlab Quick-Start (Windows) .......................................................................................... 4

3. Basilar Membrane Model ................................................................................................... 5

4. Payton’s Inner Hair Cell Model ........................................................................................ 10

5. Meddis’ Inner Hair Cell Model ........................................................................................ 17

6. Rate Map........................................................................................................................... 21

7. Cochlear Model ................................................................................................................ 22

8. References ........................................................................................................................ 23

9. Appendix: Correction to Coefficient ................................................................................ 24

1. Introduction

The purpose of this document is to introduce the auditory periphery code that will be used in

the SCANDLE project. First, three sub-modules are described:

C

In C, the structure of each sub-module is the same (replacing XX with BM, PHC or RM):

A set of options is created and initialized using XX_InitOptions.

A state is allocated using XX_AllocState.

The state is initialized using XX_InitState. (It can be reset to the initial state at any

point later in the program.)

The routine is called using XX_Run. This function never modifies the original options,

but does modify the state. This state can then be passed back into the XX_Run

function, allowing invocations to be chained one after the other, with the model state

being preserved between calls.

Once the routine has finished the memory allocated to the state structure is freed by

calling XX_FreeState. (It is not necessary to free the options structure, unless you

allocated the memory using malloc.)

Matlab

In Matlab, the structure of each sub-module is the same (replacing XX with bm, phc or rm):

A set of options (opt) is created using XX_defaults.

The initial state (st) is set to the empty matrix [].

The function is called using [out, st] = XX_mex(in, opt, st).

Specific examples of each are given below.

BM

basilar membrane

model

PHC

Payton hair cell

model

RM

A simple “rate map”

hair cell model

MHC

Meddis hair cell

model

Buffered Cochlea Model (C only)

A full cochlea model has been implemented in C in the files cochlea.c and cochlea.h. A

full description of this model is given below.

History of Changes

The code from Andreas’ group (originally authored by Weimin Liu) was supplied to

Beibei Jiang at the University of Plymouth.

12 May 2009: Beibei Jiang wrote incorporated the C program into a .mex file which

could be called from Matlab and corrected a coefficient of the basilar membrane filter

model. (See Appendix below, describing this change.)

14 October 2009: Robert Mill, at the University of Plymouth, o separated the C code into separate ANSI C modules that do not rely on Matlab o wrote a series of .mex files which act as interfaces to Matlab (and

accompanying Matlab files) o fully parameterised the code in both C and Matlab so that no parameters were

―hard-wired‖ o wrote a routine to set the Payton inner hair cell model to its equilibrium state

prior to calls o authored this document.

21 September 2010: Robert Mill, at the University of Plymouth o modified some of the source code to bring it into line with new developments

elsewhere (i.e., in the transient and adaptive gain control modules) o the Matlab-to-C data conversion routines have been changed from macros to

functions, and the standard data type for integers is now 32 bits not 16 o this documentation was updated to reflect these changes

25 May 2011: Robert Mill, at the University of Plymouth o added support for Ray Meddis’ inner hair cell model o updated this documentation to include the new MHC model (including

references) o added the option of using the MHC model cochlea.c.

2. Matlab Quick-Start (Windows)

First, export (or copy) the entirety of the New Model folder from the SVN to a local

directory. It should contain five subfolders: C, Docs, Etc, Examples, Mex.

Adding Paths and Compilation

Before using any of the Matlab routines you must add the appropriate paths. You can run the

addpaths script (in the root directory) to do this.

addpaths

If you wish to recompile the mex routines, then issue the following at the Matlab command

prompt. You should only need to do this once.

!del Mex\*.mexw32

mex -IC\ -IMex\ -outdir Mex\ Mex\bm_mex.c C\bm_model.c Mex\mat2c_util.c

mex -IC\ -IMex\ -outdir Mex\ Mex\mhc_mex.c C\mhc_model.c Mex\mat2c_util.c

mex -IC\ -IMex\ -outdir Mex\ Mex\phc_mex.c C\phc_model.c Mex\mat2c_util.c

mex -IC\ -IMex\ -outdir Mex\ Mex\rm_mex.c C\rm_model.c Mex\mat2c_util.c

To test the code is working properly, run the following script, which creates a 100 ms tone at

500 Hz, computes the output of the model (from its equilibrium) and displays the results.

Quickstart

This file can be used as a template for any other kind of processing. Note that it is not

recommended that a sampling rate less than 50 kHz is used. (A sample rate of 100 kHz is

even more preferable.)

Note: the quickstart code does not test the Meddis hair cell model. For that, see the

example files mhc_mex_eg1.m and mhc_mex_eg2.m.

3. Basilar Membrane Model

Model Overview

The basilar membrane (BM) model is an implementation of that of Liu et al. (1992) and

consists of a cascade of first-order, low-pass filters, the majority of which branch into

cascades of two second-order, band-pass filters. A diagram of the model is provided below.

The inputs are fed at the left-hand side of the diagram, which represents the base of the

cochlea; the outputs are read from the taps along the bottom of the diagram, which represent

points spaced along the BM between its base and apex.

Options

The options of the model are supplied in a C structure of type BM_Options (defined in

bm_model.h), which has the fields tabulated below.

ID Description Default

n_ch Number of channels 30

d_dt Sampling interval 10-5

d_fbase Resonator frequency at the base 8000

d_fapex Resonator frequency at the apex 100

d_qbase Low-pass filter and resonator tuning at the base 4

d_qapex Low-pass filter and resonator tuning at the apex 0.5

s s s p p p p

q

r

q

r

q

r

q

r

1st order low-pass I.I.R.

2nd

order band-pass I.I.R.

(two in cascade)

IN

OUT OUT OUT OUT

base apex

The code fragment below shows how one would create a default options structure in C, which

uses 40 channels instead of 30.

#include “bm_model.h”

/* .. */

BM_Options s_bmo;

BM_InitOptions( &s_bmo);

s_bmo.n_ch = 40;

State

The state of the BM model consists solely of pre-computed filter coefficients and delayed

filter inputs and outputs held in a C structure of type BM_State (defined in bm_model.h).

ID Description Length

dp_cs Pointer to pre-filter coefficients (s) 6

dp_zs Pointer to delayed pre-filter values (s) 3

dp_cp Pointer to coefficients of low-pass filters (p) 2 × n_ch

dp_zp Pointer to delayed values of low-pass filters (p) n_ch

dp_cq Pointer to coefficients1 of band-pass filters (q) 4 × n_ch

dp_zq Pointer to delayed values of band-pass filters (q) 2 × n_ch

dp_zr Pointer to delayed values of band-pass filters (r) 2 × n_ch

To allocate the memory for a state use:

BM_State *sp_bms = BM_AllocState( &s_bmo );

Initially, the memory is allocated but not initialised. To set the values in sp_bms so that they

correspond to the initial state of the filterbank (for options specified in s_bmo) use

BM_InitState( sp_bms, &s_bmo );

Once the routine has finished, the memory must be freed before exiting as follows:

BM_FreeState( sp_bms );

sp_bms = 0;

1 Note that the coefficients used for r are the same as those used for q.

Run

Once an options structure has been initialised and a state structure has been populated—either

using the exit values from an earlier run or the initial values computed using

BM_InitState—the routine itself is run using:

BM_Run( dp_in, dp_out, n_in, sp_bms, &s_bmo );

where dp_in is a pointer to an array of n_in double-precision values corresponding to the

input signal; dp_out is a pointer to an array of n_in × n_ch double-precision values

corresponding to the filterbank output. The memory for both input and output must be

allocated in advance, e.g., using malloc.

Example

The following code first creates a buffer of 500 samples, which an unspecified piece of code

is designed to fill (shown in red), and then runs the basilar membrane model from an initial

state using default options.

/* bm_example.c */

#include "bm_model.h"

#include <stdlib.h>

#define N_LEN 500 /* length of buffer */

void main( int argc, char **argv )

{

const int n_in = N_LEN; /* signal length */

double d_in[N_LEN]; /* signal buffer */

double *dp_out; /* pointer to output buffer */

BM_Options s_bmo; /* model options */

BM_State *sp_bms; /* pointer to model state */

/**

* Code to generate input signal goes here...

*/

/* Use default options */

BM_InitOptions( &s_bmo );

/* Allocate space for state variables */

sp_bms = BM_AllocState( &s_bmo );

/* Set state to initial state */

BM_InitState( sp_bms, &s_bmo );

/* Allocate space for output */

dp_out = malloc( s_bmo.n_ch*n_in * sizeof( *dp_out ) );

/* Run model */

BM_Run( &d_in, dp_out, n_in, sp_bms, &s_bmo );

/**

* Code to do something with output goes here...

*/

/* Free space allocated to output */

free( dp_out );

dp_out = 0;

/* Free state */

BM_FreeState( sp_bms );

sp_bms = 0;

}

/* end of file */

Calling the Routine from Matlab

The basilar membrane routine can be called from Matlab using the bm_mex wrapper function.

The function takes two arguments, a signal (as a column vector of doubles) and an options

structure, which contains the same fields as described in the ―Options‖ section above.

(Omitting the options structure causes the routine to use the default options.) The Matlab

function bm_defaults returns an options structure containing default parameters.

The following example shows how the algorithm can be used to process a 5000 Hz tone of

5 ms duration.

% bm_mex_eg1.m

% Generate signal

frq = 5000;

fs = 100000.0;

dur = 5e-3;

ts = (0:dur*fs-1)'/fs;

x = 0.5*cos(2*pi*frq*ts);

% Set routine options

opt = bm_defaults;

opt.d_dt = 1/fs;

opt.n_ch = int32(30);

% Run routine

Y = bm_mex(x, opt);

% Display output

figure; imagesc(ts*1e3, 1:30, Y);

xlabel 'Time (ms)'

ylabel 'Channel'

% end of file %

For processing longer signals, it is advisable to chain calls to the function by passing the

algorithm state in and out of the bm_mex function. The code below demonstrates how a 5000

Hz tone of five seconds duration can be processed by splitting it into one-second blocks. The

algorithm state is passed in the variable z. (The routine treats [] as indicating the initial

state.)

% bm_mex_eg2.m

% Generate signal

frq = 5000;

fs = 100000.0;

dur = 5;

ts = (0:dur*fs-1)'/fs;

x = 0.5*cos(2*pi*frq*ts);

% Set routine options

opt = bm_defaults;

opt.d_dt = 1/fs;

opt.n_ch = int32(30);

% Reserve space for output and set initial state

Y = zeros(30, dur*fs);

z = [];

% Run routine for one-second blocks

for n = 1:5

% Display progress

disp(['Frame ' int2str(n) ' of 5.']);

% Compute start and end of block

st = (n - 1)*fs + 1;

en = n*fs;

% Store output in larger matrix

[Yp, z] = bm_mex(x(st:en), opt, z);

Y(:, st:en) = Yp;

end

% Display output

figure; imagesc(ts, 1:30, Y);

xlabel 'Time (s)'

ylabel 'Channel'

% end of file %

4. Payton’s Inner Hair Cell Model

Basic Structure

The inner hair cell model is based on the model presented by Payton (1988) and Brachman

(1980). The model takes as input the basilar membrane displacement and returns as output a

quantity relating to the probability of an action potential at the post-synaptic auditory nerve

cell. All processing is within-channel; there is no data flow across channels.

The flow diagram shown below represents the processing that is modelled at a single location

on the basilar membrane. The input signal is the output from the BM model. The input signal

is scaled and subjected to a half-wave rectification and logarithmic compression.

The adaptation stage is modelled using a reservoirs of substance (e.g., neurotransmitter).

Neurotransmitter is released from a subset of 1024 ―immediately-active‖ sites. The number of

sites that are depleted is proportional to the magnitude of the compressed BM output, so the

compressed BM output must be appropriately scaled and clipped into the range 0 – 1024. The

response of the model is proportional to the total amount of transmitter released from

immediately-active sites in that time step. Following depletion, the immediately-active sites

are replenished from a ―local store‖, and the local store is replenished from a ―global store‖.

Options

The options that govern the behaviour of the are tabulated below. With the exception of the

sampling rate and the number of channels, the options agree with the values used originally

by Payton (1988, Table II). The options of the model are supplied in a C structure of type

PHC_Options (defined in phc_model.h).

half-wave

rectification

static

compression

1024

1023

2

1

local sto

re

glo

bal sto

re

response

input

from BM

output

from IHC data flow

replenishes

ID Description Default

n_ch Number of channels 30

d_dt Sampling interval 10-5

Half-wave rectification, compression and smoothing:

d_offset Offset added to stimulus 0.0677

d_reflevel Reference stimulus level 0.0002

d_scale Scaling constant 3.972

d_saturate Saturated rate 950

d_slope Slope (sites / dB) 1.499

d_s0 Slope initiation level 16.5880

d_lptau Time constant of low-pass filter following compression 10-4

Adaptation:

d_flo_a Rate of flow out of immediately-active sites 3936

d_fli_a Rate of flow into immediately-active sites 1559.2

d_flo_l Rate of flow out of local store 0.15225

d_fli_l Rate of flow into local store 127.52

d_flo_g Rate of flow out of global store 283.2320

d_fli_g Rate of flow into global store 102.4

d_nonl Initial state of low-pass filter in hair cell non-linearity 0

d_a0 Initial transmitter in each active immediate site 0

d_b0 Initial transmitter in each inactive immediate site 0

d_l0 Initial transmitter in local store 0

d_g0 Initial transmitter in global store 1

The code fragment below shows how one would create a default options structure in C, which

uses 40 channels instead of 30.

#include “phc_model.h”

/* .. */

PHC_Options s_phco;

PHC_InitOptions( &s_phco );

s_phco.n_ch = 40;

State

The state of the Payton hair cell model contains a single filter memory (for the low-pass filter

following compression) and a record of how much transmitter is left in every reservoir. It is

held in a C structure of type PHC_State (defined in phc_model.h).

ID Description Length

d_cu Filter coefficient 1

dp_zu Pointer to delayed filter memory n_ch

dp_response Pointer to response of each channel at current time step n_ch

dp_active Pointer to amounts of substance in immediately-active

sites 1024 × n_ch

dp_local Pointer to amounts of substance in local stores n_ch

dp_global Pointer to amounts of substance in global stores n_ch

To allocate the memory for a state use:

PHC_State *sp_phcs = PHC_AllocState( &s_phco );

Initially, the memory is allocated but not initialised. To set the values in sp_phcs so that they

correspond to the initial state of the hair cell (for options specified in s_phco) use

PHC_InitState( sp_phcs, &s_phco );

Once the routine has finished, the memory must be freed before exiting as follows:

PHC_FreeState( sp_phcs );

sp_phcs = 0;

Run

Once an options structure has been initialised and a state structure has been populated—either

using the exit values from an earlier run or the initial values computed using

PHC_InitState—the routine itself is run using:

PHC_Run( dp_in, dp_out, n_in, sp_phcs, &s_phco );

where dp_in is a pointer to an array of n_in × n_ch double-precision values corresponding to

the output of the basilar membrane routine; dp_out is a pointer to an array of n_in × n_ch

double-precision values corresponding to the hair cell output. The memory in which the

output is to be stored must be allocated in advance, e.g., using malloc.

Example

The following code extends the code given earlier for the basilar membrane model. It first

creates a buffer of 500 samples, which an unspecified piece of code is designed to fill (shown

in red), and then runs the basilar membrane model from an initial state using default options,

and the hair cell model from an initial state, also using default options.

/* phc_example.c */

#include "bm_model.h"

#include "phc_model.h"

#include "stdlib.h"

#define N_LEN 500 /* length of buffer */

void main( int argc, char **argv )

{

const int n_in = N_LEN; /* signal length */

double d_in[N_LEN]; /* signal buffer */

double *dp_bm_out; /* pointer to output of BM routine */

double *dp_phc_out; /* pointer to output of PHC routine */

BM_Options s_bmo; /* BM model options */

PHC_Options s_phco; /* PHC model options */

BM_State *sp_bms; /* pointer to BM model state */

PHC_State *sp_phcs; /* pointer to PHC model state */

/**

* Code to populate input signal goes here...

*/

/* Use default options for both BM and hair cell */

BM_InitOptions( &s_bmo );

PHC_InitOptions( &s_phco );

/* Allocate space for state variables */

sp_bms = BM_AllocState( &s_bmo );

sp_phcs = PHC_AllocState( &s_phco );

/* Set state to initial state */

BM_InitState( sp_bms, &s_bmo );

PHC_InitState( sp_phcs, &s_phco );

/* Allocate space for output from BM and PHC */

dp_bm_out = malloc( s_bmo.n_ch*n_in * sizeof( *dp_bm_out ) );

dp_phc_out = malloc( s_phco.n_ch*n_in * sizeof( *dp_phc_out ) );

/* Run models */

BM_Run( &d_in, dp_bm_out, n_in, sp_bms, &s_bmo );

PHC_Run( dp_bm_out, dp_phc_out, n_in, sp_phcs, &s_phco );

/**

* Code to do something with output goes here...

*/

/* Free space for output */

free( dp_bm_out );

free( dp_phc_out );

dp_bm_out = dp_phc_out = 0;

/* Free state */

BM_FreeState( sp_bms );

BM_FreeState( sp_phcs );

sp_bms = sp_phcs = 0;

}

/* end of file */

Calling the Routine from Matlab

The inner hair cell routine can be called from Matlab using the phc_mex wrapper function.

The function takes two arguments, a signal (as a column vector of doubles) and an options

structure, which contains the same fields as described in the ―Options‖ section above.

(Omitting the options structure causes the routine to use the default options.) The Matlab

function phc_defaults returns an options structure containing default parameters.

The following example shows how the algorithm can be used to process a 5000 Hz tone of

5 ms duration.

% phc_mex_eg1.m

% Generate signal

frq = 5000;

fs = 100000.0;

dur = 5e-3;

ts = (0:dur*fs-1)'/fs;

x = 0.5*cos(2*pi*frq*ts);

% Set routine options (BM)

bm_opt = bm_defaults;

bm_opt.d_dt = 1/fs;

bm_opt.n_ch = int32(30);

% Set routine options (PHC)

phc_opt = phc_defaults;

phc_opt.d_dt = 1/fs;

phc_opt.n_ch = int32(30);

phc_opt = phc_equil(phc_opt);

% Run routine

bm_out = bm_mex(x, bm_opt);

phc_out = phc_mex(bm_out, phc_opt);

% Display output

figure; imagesc(ts*1e3, 1:30, phc_out);

xlabel 'Time (ms)'

ylabel 'Channel'

% end of file %

(The function phc_equil sets the model to its equilibrium state—see section below.)

As with the basilar membrane routines, for processing longer signals, it is advisable to chain

calls to the function by passing the algorithm states in and out of the bm_mex and phc_mex

functions. The code below demonstrates how a 5000 Hz tone of five seconds duration can be

processed by splitting it into one-second blocks. The state of the basilar membrane and inner

hair cell algorithms are passed in the variables bm_z and phc_z, respectively. (Caution: it may

take a while to run at this sampling frequency.)

% phc_mex_eg2.m

% Generate signal

frq = 5000;

fs = 100000.0;

dur = 5;

ts = (0:dur*fs-1)'/fs;

x = 0.5*cos(2*pi*frq*ts);

% Set routine options (BM)

bm_opt = bm_defaults;

bm_opt.d_dt = 1/fs;

bm_opt.n_ch = int32(30);

% Set routine options (PHC)

phc_opt = phc_defaults;

phc_opt.d_dt = 1/fs;

phc_opt.n_ch = int32(30);

phc_opt = phc_equil(phc_opt);

% Reserve space for final output and set initial states

Y = zeros(30, dur*fs);

bm_z = [];

phc_z = [];

% Run routine for one-second blocks

for n = 1:5

% Display progress

disp(['Frame ' int2str(n) ' of 5.']);

% Compute start and end of block

st = (n - 1)*fs + 1;

en = n*fs;

% Run BM simulation followed by PHC simulation

[bm, bm_z] = bm_mex(x(st:en), bm_opt, bm_z);

[Yp, phc_z] = phc_mex(bm, phc_opt, phc_z);

% Store output in larger matrix

Y(:, st:en) = Yp;

end

% Display output

figure; imagesc(ts, 1:30, Y);

xlabel 'Time (s)'

ylabel 'Channel'

% end of file %

Equilibrium State

In the default options of the Payton hair cell state, all the ―transmitter‖ in every hair cell

resides in the global store. When a zero signal is received from the basilar membrane model,

the adaptation state receives a non-zero input on account of the static non-linearity, which

causes the contents of the global store to flood into the local store, and from there to the

immediate stores. The result in the output of the model is a transient change, as the hair cell

models settle into their equilibrium state.

To avoid this situation, a routine has been included called phc_equil, which takes a set of

options and then sets the following five fields, such that the model is already in its

equilibrium state on start-up.

d_nonl Initial state of low-pass filter in hair cell non-linearity

d_a0 Initial transmitter in each active immediate site

d_b0 Initial transmitter in each inactive immediate site

d_l0 Initial transmitter in local store

d_g0 Initial transmitter in global store

The code to achieve this in Matlab is as follows.

phco = phc_defaults;

% change options from defaults here if desired

phco = phc_equil(phco);

Equilibrium State in C

There is currently no function to set the equilibrium state in C. However, a Matlab-based

workaround is possible.

/* Set the initial options */

PHC_Options s_phco;

PHC_InitOptions( &s_phco );

/* Modify options of your choice */

s_phco.n_ch = 12;

s_phco.d_dt = 0.00005;

/* Set equilibrium state explicitly, using values

* returned by Matlab.

*/

s_phco.d_nonl = /* value here */

s_phco.d_a0 = /* value here */

s_phco.d_b0 = /* value here */

s_phco.d_l0 = /* value here */

s_phco.d_g0 = /* value here */

5. Meddis’ Inner Hair Cell Model

Basic Structure

This inner hair cell model was presented by Meddis (1986, 1988). Some advice concerning

implementation is given by Ostergaard (1990), and the reader should also refer to this. The

Meddis hair cell model processes each output channel of a basilar membrane model

separately. Within-channel processing is divided into two stages carried out in series.

The BM displacement (here, designated 𝑠) is fed through a static non-linearity

(representing the change in permeability due to hair motion). This function has the

form

𝑘 =

𝑔 𝑠 𝑡 + 𝐴

𝑠 𝑡 + 𝐴 + 𝐵, 𝑠 𝑡 + 𝐴 > 0

0, otherwise

where 𝐴, 𝐵 and 𝑔 are parameters.

The displacement of the hair modulates a dynamical system, which describes the

transfer of a transmitter ―substance‖ between different states in the cell. This system is

governed by the equations

𝑑𝑞

𝑑𝑡= 𝑦 𝑚 − 𝑞 + 𝑥𝑤 + 𝑘𝑞

𝑑𝑐

𝑑𝑡= 𝑘𝑞 − 𝑙𝑐 − 𝑟𝑐

𝑑𝑤

𝑑𝑡= 𝑟𝑐 − 𝑥𝑤

where 𝑘, 𝑞, 𝑐, and 𝑤 are dynamic variables, and the remaining quantities are constant

parameters. These parameters represent the amounts of transmitter substance at

variable locations in the cell / synapse. The dynamics can be understood in terms of

the following well-known diagram (Meddis, 1986, Fig. 10):

The model has been described thoroughly and the original papers give an accessible

description (i.e., Meddis, 1986, 1988), so it is not necessary to repeat this information here.

Options

The options that govern the behaviour of the are tabulated below. With the exception of the

sampling rate and the number of channels, the final (default) parameters were taken from the

Meddis (1988) paper, as reported in Ostergaard (1990, Table II, left column). The parameters

and state variables in the model are labelled as in the original papers. The options of the

model are supplied in a C structure of type MHC_Options (defined in mhc_model.h).

ID Description Default

n_ch Number of channels 30

d_dt Sampling interval 10-5

Static non-linearity (permeability):

d_g Modulates release rate 5

d_A [no physical correspondence] 300

d_B [no physical correspondence] 2000

Synaptic dynamics:

d_m Scales overall transmitter in system 1.0

d_l Rate transmitter in cleft is lost 2580

d_r Rate transmitter in cleft is recovered for reprocessing 6580

d_x Rate transmitter is reprocessed and becomes free 66.31

d_y Rate transmitter is replenished 5.05

The code fragment below shows how one would create a default options structure in C, which

uses 40 channels instead of 30.

#include “mhc_model.h”

/* .. */

MHC_Options s_mhco;

MHC_InitOptions( &s_mhco );

s_mhco.n_ch = 40;

State

The state of the Meddis hair cell model contains a record of how much transmitter is left in

every reservoir. It is held in a C structure of type MHC_State (defined in mhc_model.h).

ID Description Length

dp_c Quantity of transmitter in the cleft n_ch

dp_q Quantity of free transmitter n_ch

dp_w Quantity of transmitter being reprocessed n_ch

To allocate the memory for a state use:

MHC_State *sp_mhcs = MHC_AllocState( &s_mhco );

Initially, the memory is allocated but not initialised. The procedure used to initial the state

variables to their initial values is described in Ostergaard (1990). (There is no need to call a

separate initialisation routine as there is with the Payton hair cell.) To set the values in

sp_mhcs so that they correspond to the initial state of the hair cell use

MHC_InitState( sp_mhcs, &s_mhco );

Once the routine has finished, the memory must be freed before exiting as follows:

MHC_FreeState( sp_mhcs );

sp_mhcs = 0;

Run

Once an options structure has been initialised and a state structure has been populated—either

using the exit values from an earlier run or the initial values computed using

MHC_InitState—the routine itself is run using:

MHC_Run( dp_in, dp_out, n_in, sp_mhcs, &s_mhco );

where dp_in is a pointer to an array of n_in × n_ch double-precision values corresponding to

the output of the basilar membrane routine; dp_out is a pointer to an array of n_in × n_ch

double-precision values corresponding to the hair cell output. The memory in which the

output is to be stored must be allocated in advance, e.g., using malloc.

Calling the Routine from Matlab

The inner hair cell routine can be called from Matlab using the mhc_mex wrapper function.

The function takes two arguments, a signal (as a column vector of doubles) and an options

structure, which contains the same fields as described in the ―Options‖ section above.

(Omitting the options structure causes the routine to use the default options.) The Matlab

function mhc_defaults returns an options structure containing default parameters.

The following example shows how the algorithm can be used to process a 5000 Hz tone of

5 ms duration.

% mhc_mex_eg1.m

% Generate signal

frq = 5000;

fs = 100000.0;

dur = 5e-3;

ts = (0:dur*fs-1)'/fs;

dB = 70;

x = 10^(dB/20 - 1.35) * 3.7 * cos(2*pi*frq*ts);

% Set routine options (BM)

bm_opt = bm_defaults;

bm_opt.d_dt = 1/fs;

bm_opt.n_ch = int32(30);

% Set routine options (MHC)

mhc_opt = mhc_defaults;

mhc_opt.d_dt = 1/fs;

mhc_opt.n_ch = int32(30);

% Run routines

bm_out = bm_mex(x, bm_opt);

mhc_out = mhc_mex(bm_out, mhc_opt);

% Display output

figure; imagesc(ts*1e3, 1:30, mhc_out);

xlabel 'Time (ms)'

ylabel 'Channel'

% end of file %

As with the basilar membrane routines, for processing longer signals, it is advisable to chain

calls to the function by passing the algorithm states in and out of the bm_mex and mhc_mex

functions. To see how this is done, refer to mhc_mex_eg2.m.

Note: The Meddis hair-cell is (obviously) non-linear in terms of its input/output relations.

The model is scaled in such a way that BM samples having a root mean square of unity are

assumed to correspond to a tone at 30 dB SPL.

6. Rate Map

The rate map module is the most straight forward of all the modules and is provided as a fast

alternative to the Payton hair cell. It simply half-wave rectifies the signal, applies one of three

static nonlinearities (linear, log10 or cube root) specified by the user, and then runs the signal

through a low-pass filter.

Options

The options of the rate map are as follows.

ID Description Default

n_ch number of channels 30

en_compress RM_CM_None (0), RM_CM_Log10 (1) or

RM_CM_Cuberoot (2)

(2)

d_dt Sampling interval (seconds) 10-5

d_tau Time constant on smoothing filter (seconds) 0.008

The usage of the rate map follows the same conventions as the basilar membrane and Payton

hair cell routines.

7. Cochlear Model

The cochlear model provides a buffered reader for a basilar membrane and hair cell model

pair which reads from a file of doubles. The following code creates a basilar membrane

model paired with a rate-map, reads the value of the hair cell at time 100 ms into a buffer in

response to the signal in the file test.data, and exits.

CochleaModel *sp_cm;

double dp_buffer[30];

/* Create cochlea model

* sampling interval = 0.1 ms

* buffer length = 10 ms

*/

sp_cm = CM_CreateCochlea( 0.1, 10, CM_IHC_RateMap );

/* Does file open OK? */

if( CM_OpenFile( sp_cm, “test.data” ) )

{

/* Read output at 100 ms */

double *dp_frame = CM_GetFrameAtTime( sp_cm, 100 );

memcpy( dp_buffer, dp_frame, 30*sizeof( *dp_frame ) );

}

/* Close file */

CM_OpenFile( sp_cm );

/* Destroy the cochlea */

CM_DestroyCochlea( sp_cm );

This function allows random access to the output of the cochlear model. However, it is

optimized for calls ordered for ascending times. To use the Payton or Meddis hair cell instead

of a rate map, replace CM_IHC_RateMap with CM_IHC_Payton or CM_IHC_Meddis,

respectively.

8. References

W. Liu, A. G. Andreou and M. H. Goldstein (1992), Voiced-Speech Representation by an

Analog Silicon Model of the Auditory Periphery, IEEE Trans. Neural. Net., 3(3), p477.

K. L. Payton (1988), Vowel processing by a model of the auditory periphery: A comparison

to eighth-nerve responses, J. Acoust. Soc. Am. 83(1), pp. 145—162.

R. Meddis (1986), Simulation of mechanical to neural transduction in the auditory receptor,

J. Acoust. Soc. Am., 79(3), pp. 702—711.

R. Meddis (1988), Simulation of auditory-neural transduction: Further studies, J. Acoust. Soc.

Am., 83(3), pp. 1056—1063.

P. Ostergaard (1990), Implementation details of a computation model of the inner hair-

cell/auditory-nerve synapse, J. Acoust. Soc. Am., 87(4), pp. 1813—1816.

9. Appendix: Correction to Coefficient

12 May 2009

[email protected]

A mistake/typo in one of filter coefficients is found in C code. The detail is shown below.

I. Deduction

According to the transfer function in Page 481 of the paper Liu et al 1992, 2nd

order band-

pass filter transfer function is

2

0

2

3

0

3

0

)(

ss

ssH

Q

Q , [1]

where 0 is BF, Q3 is Quality factor. In C code, Q3 is written as q.

Mapping from s-space to z-space using bilinear transformation,

1

12

z

z

Ts

s

, [2]

where Ts is sampling period, in C code, Ts is written as dt.

Bring [2] to [1],

2

0

2 )1

12()

1

12(

)1

12(

)(

3

0

3

0

z

z

Tz

z

T

z

z

TzH

s

Q

s

s

Q

= 2

002

0

)1

12()

1

12(

)1

12(

z

z

dtqz

z

dt

z

z

dtq [ To be consistent with the notations in C code ]

= 2

002

0

1

12)

1

12(

1

12

z

z

qdtz

z

dt

z

z

qdt

= 2

2

2

002

0

)1(

)1(

1

12)

1

12(

1

12

z

z

z

z

qdtz

z

dt

z

z

qdt

= 22

0

202

2

20

)1()1(2

)1(4

)1(2

zzqdt

zdt

zqdt

=

)12(22

)12(4

22

22

00202

2

020

zzqdt

zqdt

zzdt

qdtz

qdt

=

)24

()28

()24

(

22

2

00

2

2

02

22

00

2

020

qdtdtz

dtz

qdtdt

qdtz

qdt

= 22

00

2

12

02

2

00

2

200

)24

()28

()24

(

22

zqdtdt

zdtqdtdt

zqdtqdt

=

2

2

00

2

2

00

21

2

00

2

2

02

2

2

00

2

0

2

00

2

0

24

)24

(

24

)28

(

1

24

2

24

2

z

qdtdt

qdtdtz

qdtdt

dt

z

qdtdt

qdt

qdtdt

qdt

= 21

2

)3()2(1

)2()1(

zaza

zbb

II. Code Section

Matching to filter coefficients in the C code,

b(1) = secondp[id][3]

b(2) = secondp[id][4]

a(1) = 1

-a(2) = secondp[id][1]

-a(3) = secondp[id][2]

The code shows below,

void initialize(fbase, fapex, qbase, qapex, dt)

double fbase, fapex, qbase, qapex, dt;

{ int fid; double finc, qinc, w0, q, c, tmp;

extern double pow();

/* setting up the filter parameters */

finc=pow(fapex/fbase, 1.0/29.0); qinc=(qapex-qbase)/29.0;

w0=2.0*3.141593*fbase; q=qbase;

for (fid=1; fid<=30; fid++)

{ c=2.0/dt/w0; firstv[fid]=0.0;

firstp[fid][1]=(c-1.0)/(1.0+c); // bb:

firstp[fid][2]=firstp[fid][3]=1.0/(1.0+c);

c=2.0*w0/(q*dt); tmp=4.0/(dt*dt)+c+w0*w0;

secondp[fid][1]= (8.0/(dt*dt)-2.0*w0*w0)/tmp;

// secondp[fid][2]= (c-2.0*w0*w0-4.0/(dt*dt))/tmp; wrong, therefore was commented

secondp[fid][2]= (c-w0*w0-4.0/(dt*dt))/tmp; correct

}

III. Test Results

Response to the sound ―rad.wav‖ is shown below.

Wrong Result (notice constant response on high frequencies)

After correcting