comparison trunk/matlab/bmm/carfac/CARFAC_GenerateTestData.m @ 700:597913e855fd

Factor out SAI_Run_Segment, and output test_data for comparison with C++ code.
author ronw@google.com
date Thu, 27 Jun 2013 22:28:42 +0000
parents cdb7fb83a03b
children e9855b95cd04
comparison
equal deleted inserted replaced
699:9900ef01df23 700:597913e855fd
32 32
33 % This designates a subdirectory of the C++ CARFAC folder to store the 33 % This designates a subdirectory of the C++ CARFAC folder to store the
34 % test data. 34 % test data.
35 test_data_dir = '../../../carfac/test_data/'; 35 test_data_dir = '../../../carfac/test_data/';
36 36
37 sai_struct = struct('width', 500, ...
38 'future_lags', 250, ...
39 'window_width', 2000, ...
40 'n_window_pos', 2, ...
41 'channel_smoothing_scale', 0);
42
43
37 test_name = 'binaural_test'; 44 test_name = 'binaural_test';
38 samples_to_read = [9000, 9903]; % Trim for a faster test. 45 samples_to_read = [9000, 9903]; % Trim for a faster test.
39 signal = wavread([test_data_dir test_name '.wav'], samples_to_read); 46 signal = wavread([test_data_dir test_name '.wav'], samples_to_read);
40 assert(size(signal, 2) == 1, 'Expected mono signal.'); 47 assert(size(signal, 2) == 1, 'Expected mono signal.');
41 % Construct a binaural signal by delaying the signal between the ears. 48 % Construct a binaural signal by delaying the signal between the ears.
42 itd_offset = 22; % about 1 ms 49 itd_offset = 22; % about 1 ms
43 signal = [signal((itd_offset+1):end), signal(1:(end-itd_offset))] / 10; 50 signal = [signal((itd_offset+1):end), signal(1:(end-itd_offset))] / 10;
44 n_ears = size(signal, 2); 51 n_ears = size(signal, 2);
45 CF_struct = CARFAC_Design(n_ears); 52 CF_struct = CARFAC_Design(n_ears);
46 WriteTestData(test_data_dir, 'binaural_test', signal, CF_struct); 53 WriteTestData(test_data_dir, 'binaural_test', signal, CF_struct, sai_struct);
47 54
48 55
49 test_name = 'long_test'; 56 test_name = 'long_test';
50 samples_to_read = [80001, 82000]; % Trim for a faster test. 57 samples_to_read = [80001, 82000]; % Trim for a faster test.
51 [signal, fs] = wavread([test_data_dir test_name '.wav'], samples_to_read); 58 [signal, fs] = wavread([test_data_dir test_name '.wav'], samples_to_read);
52 assert(size(signal, 2) == 2, 'Expected stereo signal.'); 59 assert(size(signal, 2) == 2, 'Expected stereo signal.');
53 n_ears = size(signal, 2); 60 n_ears = size(signal, 2);
54 CF_struct = CARFAC_Design(n_ears, fs); 61 CF_struct = CARFAC_Design(n_ears, fs);
55 WriteTestData(test_data_dir, 'long_test', signal, CF_struct); 62 WriteTestData(test_data_dir, 'long_test', signal, CF_struct, sai_struct);
56 63
57 64
58 function WriteTestData(test_data_dir, test_name, signal, CF_struct) 65 function WriteTestData(test_data_dir, test_name, signal, CF_struct, sai_struct)
59 % The following section generates data for the binaural test of the C++ 66 % The following section generates data for the binaural test of the C++
60 % version of CARFAC. 67 % version of CARFAC.
61 filename_prefix = [test_data_dir test_name]; 68 filename_prefix = [test_data_dir test_name];
62 69
63 WriteMatrixToFile([filename_prefix '-audio.txt'], signal); 70 WriteMatrixToFile([filename_prefix '-audio.txt'], signal);
71 nap(:,:,ear)); 78 nap(:,:,ear));
72 WriteMatrixToFile([filename_prefix '-matlab-bm' num2str(ear) '.txt'], ... 79 WriteMatrixToFile([filename_prefix '-matlab-bm' num2str(ear) '.txt'], ...
73 bm(:,:,ear)); 80 bm(:,:,ear));
74 end 81 end
75 82
83 ear = 1;
84 sai_struct = SAI_Run_Segment(sai_struct, nap(:,:,ear));
85 WriteMatrixToFile([filename_prefix '-matlab-sai' num2str(ear) '.txt'], ...
86 sai_struct.frame);
87
76 88
77 function WriteMatrixToFile(filename, matrix) 89 function WriteMatrixToFile(filename, matrix)
78 precision_level = 9; 90 precision_level = 9;
79 dlmwrite(filename, matrix, 'precision', precision_level, 'delimiter', ' '); 91 dlmwrite(filename, matrix, 'precision', precision_level, 'delimiter', ' ');