annotate trunk/matlab/bmm/carfac/CARFAC_SAI.m @ 516:68c15d43fcc8

Added MATLAB code for Lyon's CAR-FAC filter cascade.
author tom@acousticscale.org
date Wed, 15 Feb 2012 21:26:40 +0000
parents
children aa282a2b61bb
rev   line source
tom@516 1 % Copyright 2012, Google, Inc.
tom@516 2 % Author: Richard F. Lyon
tom@516 3 %
tom@516 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
tom@516 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
tom@516 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
tom@516 7 %
tom@516 8 % Licensed under the Apache License, Version 2.0 (the "License");
tom@516 9 % you may not use this file except in compliance with the License.
tom@516 10 % You may obtain a copy of the License at
tom@516 11 %
tom@516 12 % http://www.apache.org/licenses/LICENSE-2.0
tom@516 13 %
tom@516 14 % Unless required by applicable law or agreed to in writing, software
tom@516 15 % distributed under the License is distributed on an "AS IS" BASIS,
tom@516 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tom@516 17 % See the License for the specific language governing permissions and
tom@516 18 % limitations under the License.
tom@516 19
tom@516 20 function [CF, sai] = CARFAC_SAI(CF, k, n_mics, naps, sai)
tom@516 21 % function sai = CARFAC_SAI(CF_struct, n_mics, naps, sai)
tom@516 22 %
tom@516 23 % Calculate the Stabilized Auditory Image from naps
tom@516 24 %
tom@516 25
tom@516 26 threshold_alpha = CF.sai_params.threshold_alpha;
tom@516 27 threshold_jump = CF.sai_params.threshold_jump_factor;
tom@516 28 threshold_offset = CF.sai_params.threshold_jump_offset;
tom@516 29
tom@516 30 sai2 = reshape(sai,CF.sai_params.sai_width * CF.n_ch,n_mics);
tom@516 31 naps2 = reshape(naps,CF.n_samp * CF.n_ch,n_mics);
tom@516 32
tom@516 33 for mic = 1:n_mics
tom@516 34 data = naps(k, :, mic)';
tom@516 35 above_threshold = (CF.sai_state(mic).lastdata > ...
tom@516 36 CF.sai_state(mic).thresholds) & ...
tom@516 37 (CF.sai_state(mic).lastdata > data);
tom@516 38 CF.sai_state(mic).thresholds(above_threshold) = ...
tom@516 39 data(above_threshold) * threshold_jump + threshold_offset;
tom@516 40 CF.sai_state(mic).thresholds(~above_threshold) = ...
tom@516 41 CF.sai_state(mic).thresholds(~above_threshold) * threshold_alpha;
tom@516 42 CF.sai_state(mic).lastdata = data;
tom@516 43
tom@516 44 % Update SAI image with strobe data.
tom@516 45 othermic = 3 - mic;
tom@516 46
tom@516 47 % Channels that are above the threhsold
tom@516 48 above_ch = find(above_threshold);
tom@516 49
tom@516 50 % If we are above the threshold, set the trigger index and reset the
tom@516 51 % sai_index
tom@516 52 CF.sai_state(mic).trigger_index(above_ch) = k;
tom@516 53 CF.sai_state(mic).sai_index(above_ch) = 1;
tom@516 54
tom@516 55 % Copy the right data from the nap to the sai
tom@516 56 chans = (1:CF.n_ch)';
tom@516 57 fromindices = CF.sai_state(mic).trigger_index() + (chans - 1) * CF.n_samp;
tom@516 58 toindices = min((CF.sai_state(mic).sai_index() + (chans - 1) * ...
tom@516 59 CF.sai_params.sai_width), ...
tom@516 60 CF.sai_params.sai_width * CF.n_ch);
tom@516 61 sai2(toindices,mic) = naps2(fromindices,othermic);
tom@516 62
tom@516 63 CF.sai_state(mic).trigger_index(:) = CF.sai_state(mic).trigger_index(:) + 1;
tom@516 64 CF.sai_state(mic).sai_index(:) = CF.sai_state(mic).sai_index(:) + 1;
tom@516 65
tom@516 66 end
tom@516 67
tom@516 68 sai = reshape(sai2,CF.sai_params.sai_width,CF.n_ch,n_mics);
tom@516 69 naps = reshape(naps2,CF.n_samp, CF.n_ch,n_mics);
tom@516 70