annotate matlab/bmm/carfac/smooth1d.m @ 655:8a2b0cbd7a64

Move design of SAI out of SAI_Run.m
author ronw@google.com
date Thu, 27 Jun 2013 20:47:02 +0000
parents 47c488dc7a01
children
rev   line source
dicklyon@629 1 % Copyright 2010, Google, Inc.
dicklyon@629 2 % Author Richard F. Lyon
dicklyon@629 3 %
dicklyon@629 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@629 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@629 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@629 7 %
dicklyon@629 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@629 9 % you may not use this file except in compliance with the License.
dicklyon@629 10 % You may obtain a copy of the License at
dicklyon@629 11 %
dicklyon@629 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@629 13 %
dicklyon@629 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@629 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@629 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@629 17 % See the License for the specific language governing permissions and
dicklyon@629 18 % limitations under the License.
dicklyon@629 19
dicklyon@629 20 function cols = smooth1d(cols, scale)
dicklyon@629 21 % smooth1d - Smooth the columns of the input.
dicklyon@629 22 %
dicklyon@629 23 % output = smooth1d(input, smoothing_factor)
dicklyon@629 24 %
dicklyon@629 25 % Smooth the columns of input using a one-pole smoothing filter, using the
dicklyon@629 26 % provided smoothing factor.
dicklyon@629 27 %
dicklyon@629 28 % TODO(dross, dicklyon): make this code satisfy the google3 Matlab style.
dicklyon@629 29
dicklyon@629 30 [nr, nc, nl] = size(cols);
dicklyon@629 31 if nr == 1
dicklyon@629 32 if nl == 1
dicklyon@629 33 cols = cols';
dicklyon@629 34 [nr, nc, nl] = size(cols);
dicklyon@629 35 else
dicklyon@629 36 disp('error in shape passed to smooth1d')
dicklyon@629 37 end
dicklyon@629 38 end
dicklyon@629 39
dicklyon@629 40 if scale==0
dicklyon@629 41 polez = 0; % no smoothing at all
dicklyon@629 42 return;
dicklyon@629 43 else
dicklyon@629 44 % this coefficient matches the curvature at DC of a discrete Gaussian:
dicklyon@629 45 t = scale^2;
dicklyon@629 46 polez = 1 + 1/t - sqrt((1+1/t)^2 - 1); % equiv. to the one below
dicklyon@629 47 % polez = 1 + 1/t - sqrt((2/t) + 1/t^2); % equiv. to the one above
dicklyon@629 48 % polez is Z position of real pole
dicklyon@629 49 end
dicklyon@629 50
dicklyon@629 51 [x, state] = filter(1-polez, [1, -polez], cols);
dicklyon@629 52 cols = cols(end:-1:1,:);
dicklyon@629 53 [cols, state] = filter(1-polez, [1, -polez], cols, state);
dicklyon@629 54 cols = cols(end:-1:1,:);
dicklyon@629 55 [cols, state] = filter(1-polez, [1, -polez], cols, state);
dicklyon@629 56
dicklyon@629 57 return