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