annotate matlab/bmm/carfac/SmoothDoubleExponential.m @ 610:01986636257a

Second check-in of Alex Brandmeyer's C++ implementation of CARFAC. Addressed style issues and completed implementation of remaining functions. Still needs proper testing of the output stages against the MATLAB version, and runtime functions need improvements in efficiency.
author alexbrandmeyer
date Thu, 16 May 2013 17:33:23 +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
tom@455 20 function signal_vecs = SmoothDoubleExponential(signal_vecs, ...
tom@455 21 polez1, polez2, fast_matlab_way)
tom@455 22 % function signal_vecs = SmoothDoubleExponential(signal_vecs, ...
tom@455 23 % polez1, polez2, fast_matlab_way)
tom@455 24 %
tom@455 25 % Smooth the input column vectors in signal_vecs using forward
tom@455 26 % and backwards one-pole smoothing filters, backwards first, with
tom@455 27 % approximately reflecting edge conditions.
tom@455 28 %
tom@455 29 % It will be done with Matlab's filter function if "fast_matlab_way"
tom@455 30 % is nonzero or defaulted; use 0 to test the algorithm for how to do it
tom@455 31 % in sequential c code.
tom@455 32
tom@455 33 if nargin < 4
tom@455 34 fast_matlab_way = 1;
tom@455 35 % can also use the slow way with explicit loop like we'll do in C++
tom@455 36 end
tom@455 37
tom@455 38 if fast_matlab_way
tom@455 39 [junk, Z_state] = filter(1-polez1, [1, -polez1], ...
tom@455 40 signal_vecs((end-10):end, :)); % initialize state from 10 points
tom@455 41 [signal_vecs(end:-1:1), Z_state] = filter(1-polez2, [1, -polez2], ...
tom@455 42 signal_vecs(end:-1:1), Z_state*polez2/polez1);
tom@455 43 signal_vecs = filter(1-polez1, [1, -polez1], signal_vecs, ...
tom@455 44 Z_state*polez1/polez2);
tom@455 45 else
tom@455 46 npts = size(signal_vecs, 1);
tom@455 47 state = zeros(size(signal_vecs, 2));
tom@455 48 for index = npts-10:npts
tom@455 49 input = signal_vecs(index, :);
tom@455 50 state = state + (1 - polez1) * (input - state);
tom@455 51 end
tom@455 52 % smooth backward with polez2, starting with state from above:
tom@455 53 for index = npts:-1:1
tom@455 54 input = signal_vecs(index, :);
tom@455 55 state = state + (1 - polez2) * (input - state);
tom@455 56 signal_vecs(index, :) = state;
tom@455 57 end
tom@455 58 % smooth forward with polez1, starting with state from above:
tom@455 59 for index = 1:npts
tom@455 60 input = signal_vecs(index, :);
tom@455 61 state = state + (1 - polez1) * (input - state);
tom@455 62 signal_vecs(index, :) = state;
tom@455 63 end
tom@455 64 end
dicklyon@462 65