tom@455: % Copyright 2012, Google, Inc. tom@455: % Author: Richard F. Lyon tom@455: % tom@455: % This Matlab file is part of an implementation of Lyon's cochlear model: tom@455: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" tom@455: % to supplement Lyon's upcoming book "Human and Machine Hearing" tom@455: % tom@455: % Licensed under the Apache License, Version 2.0 (the "License"); tom@455: % you may not use this file except in compliance with the License. tom@455: % You may obtain a copy of the License at tom@455: % tom@455: % http://www.apache.org/licenses/LICENSE-2.0 tom@455: % tom@455: % Unless required by applicable law or agreed to in writing, software tom@455: % distributed under the License is distributed on an "AS IS" BASIS, tom@455: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tom@455: % See the License for the specific language governing permissions and tom@455: % limitations under the License. tom@455: tom@455: function signal_vecs = SmoothDoubleExponential(signal_vecs, ... tom@455: polez1, polez2, fast_matlab_way) tom@455: % function signal_vecs = SmoothDoubleExponential(signal_vecs, ... tom@455: % polez1, polez2, fast_matlab_way) tom@455: % tom@455: % Smooth the input column vectors in signal_vecs using forward tom@455: % and backwards one-pole smoothing filters, backwards first, with tom@455: % approximately reflecting edge conditions. tom@455: % tom@455: % It will be done with Matlab's filter function if "fast_matlab_way" tom@455: % is nonzero or defaulted; use 0 to test the algorithm for how to do it tom@455: % in sequential c code. tom@455: tom@455: if nargin < 4 tom@455: fast_matlab_way = 1; tom@455: % can also use the slow way with explicit loop like we'll do in C++ tom@455: end tom@455: tom@455: if fast_matlab_way tom@455: [junk, Z_state] = filter(1-polez1, [1, -polez1], ... tom@455: signal_vecs((end-10):end, :)); % initialize state from 10 points tom@455: [signal_vecs(end:-1:1), Z_state] = filter(1-polez2, [1, -polez2], ... tom@455: signal_vecs(end:-1:1), Z_state*polez2/polez1); tom@455: signal_vecs = filter(1-polez1, [1, -polez1], signal_vecs, ... tom@455: Z_state*polez1/polez2); tom@455: else tom@455: npts = size(signal_vecs, 1); tom@455: state = zeros(size(signal_vecs, 2)); tom@455: for index = npts-10:npts tom@455: input = signal_vecs(index, :); tom@455: state = state + (1 - polez1) * (input - state); tom@455: end tom@455: % smooth backward with polez2, starting with state from above: tom@455: for index = npts:-1:1 tom@455: input = signal_vecs(index, :); tom@455: state = state + (1 - polez2) * (input - state); tom@455: signal_vecs(index, :) = state; tom@455: end tom@455: % smooth forward with polez1, starting with state from above: tom@455: for index = 1:npts tom@455: input = signal_vecs(index, :); tom@455: state = state + (1 - polez1) * (input - state); tom@455: signal_vecs(index, :) = state; tom@455: end tom@455: end dicklyon@462: