annotate matlab/bmm/carfac/CARFAC_SAI.m @ 645:3f01a136c537

DISALLOW_COPY_AND_ASSIGN in CARFAC classes and fix a few funny indentations.
author ronw@google.com
date Tue, 11 Jun 2013 17:59:08 +0000
parents 1d720e7fffdf
children
rev   line source
tom@513 1 % Copyright 2012 Google Inc. All Rights Reserved.
tom@455 2 % Author: Richard F. Lyon
tom@455 3 %
tom@455 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
tom@455 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
tom@455 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
tom@455 7 %
tom@455 8 % Licensed under the Apache License, Version 2.0 (the "License");
tom@455 9 % you may not use this file except in compliance with the License.
tom@455 10 % You may obtain a copy of the License at
tom@455 11 %
tom@455 12 % http://www.apache.org/licenses/LICENSE-2.0
tom@455 13 %
tom@455 14 % Unless required by applicable law or agreed to in writing, software
tom@455 15 % distributed under the License is distributed on an "AS IS" BASIS,
tom@455 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tom@455 17 % See the License for the specific language governing permissions and
tom@455 18 % limitations under the License.
tom@455 19
dicklyon@456 20 function [sai_frame, sai_state, naps] = CARFAC_SAI(naps, k, sai_state, SAI_params)
dicklyon@456 21 % function sai = CARFAC_SAI(naps, k, sai_state, SAI_params)
tom@455 22 %
dicklyon@474 23 % ...work in progress...
dicklyon@474 24 %
dicklyon@456 25 % Calculate the Stabilized Auditory Image from naps;
dicklyon@456 26 % I think this is a binaural SAI by Steven Ness
dicklyon@456 27 %
dicklyon@456 28 % k seems to be a time index; it's an incremental update of the images...
dicklyon@456 29 % but this doesn't sound like a proper incremental approach...
tom@455 30 %
tom@455 31
dicklyon@474 32 [n_samp, n_ch, n_ears] = size(naps);
tom@455 33
dicklyon@456 34 if nargin < 4
dicklyon@456 35 SAI_params = struct( ...
dicklyon@456 36 'frame_jump', 200, ...
dicklyon@456 37 'sai_width', 500, ...
dicklyon@456 38 'threshold_alpha', 0.99, ...
dicklyon@456 39 'threshold_jump_factor', 1.2, ...
dicklyon@456 40 'threshold_jump_offset', 0.1};
dicklyon@456 41 end
tom@455 42
dicklyon@456 43 threshold_alpha = SAI_params.threshold_alpha;
dicklyon@456 44 threshold_jump = SAI_params.threshold_jump_factor;
dicklyon@456 45 threshold_offset = SAI_params.threshold_jump_offset;
tom@455 46
dicklyon@474 47 sai2 = reshape(sai_state.sai, SAI_params.sai_width * n_ch, n_ears);
dicklyon@474 48 naps2 = reshape(naps, n_samp * n_ch, n_ears);
tom@455 49
dicklyon@474 50 for ear = 1:n_ears
dicklyon@474 51 data = naps(k, :, ear)';
dicklyon@474 52 above_threshold = (sai_state(ear).lastdata > ...
dicklyon@474 53 sai_state(ear).thresholds) & ...
dicklyon@474 54 (sai_state(ear).lastdata > data);
dicklyon@474 55 sai_state(ear).thresholds(above_threshold) = ...
dicklyon@456 56 data(above_threshold) * threshold_jump + threshold_offset;
dicklyon@474 57 sai_state(ear).thresholds(~above_threshold) = ...
dicklyon@474 58 sai_state(ear).thresholds(~above_threshold) * threshold_alpha;
dicklyon@474 59 sai_state(ear).lastdata = data;
dicklyon@456 60
dicklyon@456 61 % Update SAI image with strobe data.
dicklyon@474 62 otherear = 3 - ear;
dicklyon@456 63
dicklyon@456 64 % Channels that are above the threhsold
dicklyon@456 65 above_ch = find(above_threshold);
dicklyon@456 66
dicklyon@456 67 % If we are above the threshold, set the trigger index and reset the
dicklyon@456 68 % sai_index
dicklyon@474 69 sai_state(ear).trigger_index(above_ch) = k;
dicklyon@474 70 sai_state(ear).sai_index(above_ch) = 1;
dicklyon@456 71
dicklyon@456 72 % Copy the right data from the nap to the sai
dicklyon@456 73 chans = (1:n_ch)';
dicklyon@474 74 fromindices = sai_state(ear).trigger_index() + (chans - 1) * n_samp;
dicklyon@474 75 toindices = min((sai_state(ear).sai_index() + (chans - 1) * sai_params.sai_width), sai_params.sai_width * n_ch);
dicklyon@474 76 sai2(toindices,ear) = naps2(fromindices, otherear);
dicklyon@456 77
dicklyon@474 78 sai_state(ear).trigger_index(:) = sai_state(ear).trigger_index(:) + 1;
dicklyon@474 79 sai_state(ear).sai_index(:) = sai_state(ear).sai_index(:) + 1;
dicklyon@456 80 end
tom@455 81
tom@455 82
dicklyon@474 83 sai_frame = reshape(sai2,sai_params.sai_width,n_ch,n_ears);
dicklyon@456 84 sai_state.sai = sai; % probably this is not exactly what we want to store as state...
tom@455 85
tom@455 86