comparison trunk/matlab/bmm/carfac/CARFAC_Transfer_Functions.m @ 528:741187dc780f

More updates
author dicklyon@google.com
date Sat, 10 Mar 2012 05:05:35 +0000
parents bef16790194e
children fb60ea429bb8
comparison
equal deleted inserted replaced
527:bef16790194e 528:741187dc780f
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 % See the License for the specific language governing permissions and 17 % See the License for the specific language governing permissions and
18 % limitations under the License. 18 % limitations under the License.
19 19
20 function [complex_transfns_freqs, ... 20 function [complex_transfns_freqs, ...
21 stage_numerators, stage_denominators] = ... 21 stage_numerators, stage_denominators] = CARFAC_Transfer_Functions( ...
22 CARFAC_Transfer_Functions(CF, freqs, to_channels, from_channels) 22 CF, freqs, to_channels, from_channels)
23 % function [complex_transfns_freqs, ... 23 % function [complex_transfns_freqs, ...
24 % stage_z_numerators, stage_z_denominators] = ... 24 % stage_numerators, stage_denominators] = CARFAC_Transfer_Functions( ...
25 % CARFAC_Transfer_Functions(CF, freqs, to_channels, from_channels) 25 % CF, freqs, to_channels, from_channels)
26 % Return transfer functions as polynomials in z (nums & denoms); 26 % Return transfer functions as polynomials in z (nums & denoms);
27 % And evaluate them at freqs if it's given, to selected output, 27 % And evaluate them at freqs if it's given, to selected output,
28 % optionally from selected starting points (from 0, input, by default). 28 % optionally from selected starting points (from 0, input, by default).
29 % complex_transfns_freqs has a row of complex gains per to_channel. 29 % complex_transfns_freqs has a row of complex gains per to_channel.
30 30
61 end 61 end
62 if nargin < 4 || isempty(from_channels) 62 if nargin < 4 || isempty(from_channels)
63 from_channels = 0; % tranfuns from input, called channel 0. 63 from_channels = 0; % tranfuns from input, called channel 0.
64 end 64 end
65 if length(from_channels) == 1 65 if length(from_channels) == 1
66 from_channels = from_channels * ones(length(to_channels)); 66 from_channels = from_channels * ones(1,length(to_channels));
67 end 67 end
68 % Default to cum gain of 1 (log is 0), from input channel 0: 68 % Default to cum gain of 1 (log is 0), from input channel 0:
69 from_cum = zeros(length(to_channels), length(z_row)); 69 from_cum = zeros(length(to_channels), length(z_row));
70 not_input = from_channels > 0; 70 not_input = from_channels > 0;
71 from_cum(not_input, :) = cum_log_gains(from_channels(not_input), :); 71 from_cum(not_input, :) = cum_log_gains(from_channels(not_input), :);
86 % dot product of each poly row with each [z2; z; 1] col: 86 % dot product of each poly row with each [z2; z; 1] col:
87 gains = (numerators * zz) ./ (denominators * zz); 87 gains = (numerators * zz) ./ (denominators * zz);
88 88
89 89
90 function [stage_numerators, stage_denominators] = ... 90 function [stage_numerators, stage_denominators] = ...
91 CARFAC_Rational_Functions(CF, chans) 91 CARFAC_Rational_Functions(CF)
92 % function [stage_z_numerators, stage_z_denominators] = ... 92 % function [stage_z_numerators, stage_z_denominators] = ...
93 % CARFAC_Rational_Functions(CF, chans) 93 % CARFAC_Rational_Functions(CF, chans)
94 % Return transfer functions of all stages as rational functions. 94 % Return transfer functions of all stages as rational functions.
95 95
96 if nargin < 2 96 n_ch = CF.n_ch;
97 n_ch = CF.n_ch; 97 coeffs = CF.filter_coeffs;
98 chans = 1:n_ch; 98 min_zeta = CF.filter_params.min_zeta;
99
100 a0 = coeffs.a_coeffs;
101 c0 = coeffs.c_coeffs;
102
103 % get r, adapted if we have state:
104 r = coeffs.r_coeffs;
105 if isfield(CF, 'filter_state')
106 state = CF.filter_state;
107 zB = state.zB_memory; % current extra damping
108 r = r - c0 .* zB;
99 else 109 else
100 n_ch = length(chans); 110 zB = 0;
101 end 111 end
102 coeffs = CF.filter_coeffs; 112
103 r = coeffs.r_coeffs(chans); 113 a = a0 .* r;
104 a = coeffs.a_coeffs(chans) .* r; 114 c = c0 .* r;
105 c = coeffs.c_coeffs(chans) .* r;
106 r2 = r .* r; 115 r2 = r .* r;
107 h = coeffs.h_coeffs(chans); 116 h = coeffs.h_coeffs;
108 g = coeffs.g_coeffs(chans); 117 g0 = coeffs.g_coeffs;
118 g = g0 .* (1 + coeffs.gr_coeffs .* (1 - r).^2);
119
109 stage_denominators = [ones(n_ch, 1), -2 * a, r2]; 120 stage_denominators = [ones(n_ch, 1), -2 * a, r2];
110 stage_numerators = [g .* ones(n_ch, 1), g .* (-2 * a + h .* c), g .* r2]; 121 stage_numerators = [g .* ones(n_ch, 1), g .* (-2 * a + h .* c), g .* r2];
111 122
112 123
113 %% example 124 %% example