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