comparison trunk/matlab/bmm/carfac/CARFAC_GenerateTestData.m @ 668:933cf18d9a59

Fourth revision of Alex Brandmeyer's C++ implementation. Fixed more style issues, changed AGC structures to vectors, replaced FloatArray2d with vector<FloatArray>, implemented first tests using GTest to verify coefficients and monaural output against Matlab values (stored in aimc/carfac/test_data/). To run tests, change the path stored in carfac_test.h in TEST_SRC_DIR. Added CARFAC_GenerateTestData to the Matlab branch, fixed stage indexing in CARFAC_Cross_Couple.m to reflect changes in AGCCoeffs and AGCState structs.
author alexbrandmeyer
date Wed, 22 May 2013 21:30:02 +0000
parents
children 7f424c1a8b78
comparison
equal deleted inserted replaced
667:9b719047eca5 668:933cf18d9a59
1 % Author: Alex Brandmeyer
2 %
3 % This Matlab file is part of an implementation of Lyon's cochlear model:
4 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
5 % to supplement Lyon's upcoming book "Human and Machine Hearing"
6 %
7 % Licensed under the Apache License, Version 2.0 (the "License");
8 % you may not use this file except in compliance with the License.
9 % You may obtain a copy of the License at
10 %
11 % http://www.apache.org/licenses/LICENSE-2.0
12 %
13 % Unless required by applicable law or agreed to in writing, software
14 % distributed under the License is distributed on an "AS IS" BASIS,
15 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 % See the License for the specific language governing permissions and
17 % limitations under the License.
18
19 function CARFAC_GenerateTestData()
20 % function GenerateTestData()
21 % This function generates a set of text files in the AIMC repository that
22 % can be used to compare the output of the C++ version of CARFAC with that
23 % of the Matlab version.
24
25 % This designates a subdirectory of the C++ CARFAC folder to store the
26 % test data
27 data_dir = '../../../carfac/test_data/';
28
29 % These are some basic settings for the CARFAC design and test data.
30 n_ears = 1;
31 wav_fn = 'plan.wav';
32
33 seg_len = 441;
34 start_index = 13000;
35 end_index = start_index + seg_len - 1;
36 file_signal = wavread(wav_fn);
37 file_signal = file_signal(start_index:end_index, 1);
38
39 filename = 'file_signal_monaural_test.txt'
40 data = file_signal;
41 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
42
43 % This designs and initializes the CARFAC.
44 CF_struct = CARFAC_Design(n_ears);
45 CF_struct = CARFAC_Init(CF_struct);
46
47
48
49 % Now we go through the coefficient structures and store each set in a text
50 % file.
51
52 % r1 coeffs
53 filename = 'r1_coeffs.txt'
54 data = CF_struct.ears.CAR_coeffs.r1_coeffs;
55 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
56
57 % a0 coeffs
58 filename = 'a0_coeffs.txt'
59 data = CF_struct.ears.CAR_coeffs.a0_coeffs;
60 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
61
62 % c0 coeffs
63 filename = 'c0_coeffs.txt'
64 data = CF_struct.ears.CAR_coeffs.c0_coeffs;
65 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
66
67 % h coeffs
68 filename = 'h_coeffs.txt'
69 data = CF_struct.ears.CAR_coeffs.h_coeffs;
70 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
71
72 % g0 coeffs
73 filename = 'g0_coeffs.txt'
74 data = CF_struct.ears.CAR_coeffs.g0_coeffs;
75 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
76
77 % zr coeffs
78 filename = 'zr_coeffs.txt'
79 data = CF_struct.ears.CAR_coeffs.zr_coeffs;
80 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
81
82 % Now we store the IHC coefficients in an output vector.
83
84 coeff = CF_struct.ears.IHC_coeffs;
85 ihc_coeffs = [coeff.just_hwr; coeff.lpf_coeff; coeff.out_rate; ...
86 coeff.in_rate; coeff.one_cap; coeff.output_gain; ...
87 coeff.rest_output; coeff.rest_cap; coeff.ac_coeff];
88
89 filename = 'ihc_coeffs.txt'
90 data = ihc_coeffs;
91 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
92
93 % For each of the AGC Stages, we store a text file containing all of the
94 % coefficients.
95
96 agc_coeffs = CF_struct.ears.AGC_coeffs
97
98 for stage = 1:4
99 data = zeros(14,1);
100 data(1) = agc_coeffs(stage).n_ch;
101 data(2) = agc_coeffs(stage).n_AGC_stages;
102 data(3) = agc_coeffs(stage).AGC_stage_gain;
103 data(4) = agc_coeffs(stage).decimation;
104 data(5) = agc_coeffs(stage).AGC_epsilon;
105 data(6) = agc_coeffs(stage).AGC_polez1;
106 data(7) = agc_coeffs(stage).AGC_polez2;
107 data(8) = agc_coeffs(stage).AGC_spatial_iterations;
108 data(9) = agc_coeffs(stage).AGC_spatial_FIR(1);
109 data(10) = agc_coeffs(stage).AGC_spatial_FIR(2);
110 data(11) = agc_coeffs(stage).AGC_spatial_FIR(3);
111 data(12) = agc_coeffs(stage).AGC_spatial_n_taps;
112 data(13) = agc_coeffs(stage).AGC_mix_coeffs;
113 data(14) = agc_coeffs(1).detect_scale;
114 filename = ['agc_coeffs_' int2str(stage) '.txt']
115 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
116 end
117
118 % This section of code runs the single segment of data which was selected
119 % and stores the nap, bm, ohc and agc outputs of the CARFAC.
120
121 [CF_struct, nap_decim, nap, bm, ohc, agc] = CARFAC_Run(CF_struct, file_signal);
122
123 filename = 'monaural_test_nap.txt'
124 data = nap;
125 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
126
127 filename = 'monaural_test_bm.txt'
128 data = bm;
129 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
130
131 filename = 'monaural_test_ohc.txt'
132 data = ohc;
133 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');
134
135 filename = 'monaural_test_agc.txt'
136 data = agc;
137 dlmwrite([data_dir filename],data,'precision', 12,'delimiter',' ');