Mercurial > hg > aimc
comparison trunk/matlab/bmm/carfac/SmoothDoubleExponential.m @ 516:68c15d43fcc8
Added MATLAB code for Lyon's CAR-FAC filter cascade.
author | tom@acousticscale.org |
---|---|
date | Wed, 15 Feb 2012 21:26:40 +0000 |
parents | |
children | 2b96cb7ea4f7 |
comparison
equal
deleted
inserted
replaced
454:49b7b984e957 | 516:68c15d43fcc8 |
---|---|
1 % Copyright 2012, 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 signal_vecs = SmoothDoubleExponential(signal_vecs, ... | |
21 polez1, polez2, fast_matlab_way) | |
22 % function signal_vecs = SmoothDoubleExponential(signal_vecs, ... | |
23 % polez1, polez2, fast_matlab_way) | |
24 % | |
25 % Smooth the input column vectors in signal_vecs using forward | |
26 % and backwards one-pole smoothing filters, backwards first, with | |
27 % approximately reflecting edge conditions. | |
28 % | |
29 % It will be done with Matlab's filter function if "fast_matlab_way" | |
30 % is nonzero or defaulted; use 0 to test the algorithm for how to do it | |
31 % in sequential c code. | |
32 | |
33 if nargin < 4 | |
34 fast_matlab_way = 1; | |
35 % can also use the slow way with explicit loop like we'll do in C++ | |
36 end | |
37 | |
38 if fast_matlab_way | |
39 [junk, Z_state] = filter(1-polez1, [1, -polez1], ... | |
40 signal_vecs((end-10):end, :)); % initialize state from 10 points | |
41 [signal_vecs(end:-1:1), Z_state] = filter(1-polez2, [1, -polez2], ... | |
42 signal_vecs(end:-1:1), Z_state*polez2/polez1); | |
43 signal_vecs = filter(1-polez1, [1, -polez1], signal_vecs, ... | |
44 Z_state*polez1/polez2); | |
45 else | |
46 npts = size(signal_vecs, 1); | |
47 state = zeros(size(signal_vecs, 2)); | |
48 for index = npts-10:npts | |
49 input = signal_vecs(index, :); | |
50 state = state + (1 - polez1) * (input - state); | |
51 end | |
52 % smooth backward with polez2, starting with state from above: | |
53 for index = npts:-1:1 | |
54 input = signal_vecs(index, :); | |
55 state = state + (1 - polez2) * (input - state); | |
56 signal_vecs(index, :) = state; | |
57 end | |
58 % smooth forward with polez1, starting with state from above: | |
59 for index = 1:npts | |
60 input = signal_vecs(index, :); | |
61 state = state + (1 - polez1) * (input - state); | |
62 signal_vecs(index, :) = state; | |
63 end | |
64 end |