annotate trunk/matlab/bmm/carfac/SmoothDoubleExponential.m @ 523:2b96cb7ea4f7

Major AGC improvements mostly
author dicklyon@google.com
date Thu, 01 Mar 2012 19:49:24 +0000
parents 68c15d43fcc8
children 101289a936be
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 signal_vecs = SmoothDoubleExponential(signal_vecs, ...
tom@516 21 polez1, polez2, fast_matlab_way)
tom@516 22 % function signal_vecs = SmoothDoubleExponential(signal_vecs, ...
tom@516 23 % polez1, polez2, fast_matlab_way)
tom@516 24 %
tom@516 25 % Smooth the input column vectors in signal_vecs using forward
tom@516 26 % and backwards one-pole smoothing filters, backwards first, with
tom@516 27 % approximately reflecting edge conditions.
tom@516 28 %
tom@516 29 % It will be done with Matlab's filter function if "fast_matlab_way"
tom@516 30 % is nonzero or defaulted; use 0 to test the algorithm for how to do it
tom@516 31 % in sequential c code.
tom@516 32
tom@516 33 if nargin < 4
tom@516 34 fast_matlab_way = 1;
tom@516 35 % can also use the slow way with explicit loop like we'll do in C++
tom@516 36 end
tom@516 37
tom@516 38 if fast_matlab_way
tom@516 39 [junk, Z_state] = filter(1-polez1, [1, -polez1], ...
tom@516 40 signal_vecs((end-10):end, :)); % initialize state from 10 points
tom@516 41 [signal_vecs(end:-1:1), Z_state] = filter(1-polez2, [1, -polez2], ...
tom@516 42 signal_vecs(end:-1:1), Z_state*polez2/polez1);
tom@516 43 signal_vecs = filter(1-polez1, [1, -polez1], signal_vecs, ...
tom@516 44 Z_state*polez1/polez2);
tom@516 45 else
tom@516 46 npts = size(signal_vecs, 1);
tom@516 47 state = zeros(size(signal_vecs, 2));
tom@516 48 for index = npts-10:npts
tom@516 49 input = signal_vecs(index, :);
tom@516 50 state = state + (1 - polez1) * (input - state);
tom@516 51 end
tom@516 52 % smooth backward with polez2, starting with state from above:
tom@516 53 for index = npts:-1:1
tom@516 54 input = signal_vecs(index, :);
tom@516 55 state = state + (1 - polez2) * (input - state);
tom@516 56 signal_vecs(index, :) = state;
tom@516 57 end
tom@516 58 % smooth forward with polez1, starting with state from above:
tom@516 59 for index = 1:npts
tom@516 60 input = signal_vecs(index, :);
tom@516 61 state = state + (1 - polez1) * (input - state);
tom@516 62 signal_vecs(index, :) = state;
tom@516 63 end
tom@516 64 end
dicklyon@523 65