comparison toolboxes/AudioInpaintingToolbox/Experiments/MissingSampleTopologyExperiment/MissingSampleTopologyExperiment.m @ 138:56d719a5fd31 ivand_dev

Audio Inpaintin Toolbox
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Thu, 21 Jul 2011 14:27:47 +0100
parents
children
comparison
equal deleted inserted replaced
137:9207d56c5547 138:56d719a5fd31
1 function MissingSampleTopologyExperiment(expParam)
2 % For a total number of missing samples C in a frame, create several
3 % configuration of B holes with length A, where A*B=C (i.e. the total
4 % number of missing samples is constant). Test several values of C, several
5 % solvers. For each C, test all possible combination of (A,B) such that
6 % A*B=C.
7 % Note that for each combination (A,B), a number of frames are tested at
8 % random and SNR results are then averaged.
9 %
10 % Usage: MissingSampleTopologyExperiment(expParam)
11 %
12 %
13 % Inputs:
14 % - expParam is an optional structure where the user can define
15 % the experiment parameters.
16 % - expParam.soundDir: path to sound directory. All the .wav files
17 % in this directory will be tested at random.
18 % - expParam.destDir: path to store the results.
19 % - expParam.N: frame length
20 % - expParam.NFramesPerHoleSize: number of frames to use for each
21 % testing configuration (A,B). Results are then averaged.
22 % - expParam.totalMissSamplesList: list of all tested values C for
23 % the total number of missing samples in a frame
24 % - expParam.solvers: list of solvers with their parameters
25 %
26 % -------------------
27 %
28 % Audio Inpainting toolbox
29 % Date: June 28, 2011
30 % By Valentin Emiya, Amir Adler, Maria Jafari
31 % This code is distributed under the terms of the GNU Public License version 3 (http://www.gnu.org/licenses/gpl.txt).
32
33 if ~isdeployed
34 addpath('../../Problems/');
35 addpath('../../Solvers/');
36 addpath('../../Utils/');
37 addpath('../../Utils/dictionaries/');
38 addpath('../../Utils/evaluation/');
39 % addpath('../../Utils/TCPIP_SocketCom/');
40 % javaaddpath('../../Utils/TCPIP_SocketCom');
41 dbstop if error
42 close all
43 end
44
45 %% Set parameters
46 if nargin<1
47 expParam = [];
48 end
49 % Path to audio files
50 if ~isfield(expParam,'soundDir'),
51 expParam.soundDir = '../../Data/testSpeech8kHz_from16kHz/';
52 end
53 if ~isfield(expParam,'destDir'),
54 expParam.destDir = '../../tmp/missSampTopoExp/';
55 end
56 if ~exist(expParam.destDir,'dir')
57 mkdir(expParam.destDir)
58 end
59
60
61 % frame length
62 if ~isfield(expParam,'N'),
63 expParam.N = 512;
64 expParam.N = 256;
65 warning('AITB:N','Frame length=256 is used to have faster computations. Recommended frame length is 512 at 8kHz.');
66 end
67
68 % Number of random frames to test
69 if ~isfield(expParam,'NFramesPerHoleSize'),
70 expParam.NFramesPerHoleSize = 20;
71 warning('AITB:NFrames','expParam.NFramesPerHoleSize = 20 is used to have faster computations. Recommended value: several hundreds.');
72 end
73
74 % Number of missing samples: which numbers to test?
75 if ~isfield(expParam,'totalMissSamplesList')
76 expParam.totalMissSamplesList = [12,36,60,120,180,240];
77 expParam.totalMissSamplesList = [12,36];
78 warning('AITB:Miss','expParam.totalMissSamplesList = [12,36] is used to have faster computations. Recommended list: expParam.totalMissSamplesList = [12,36,60,120,180,240].');
79 end
80
81 % Choose the solver methods you would like to test: OMP, L1, Janssen
82 if ~isfield(expParam,'solvers'),
83 nSolver = 0;
84 nSolver = nSolver+1;
85 expParam.solvers(nSolver).name = 'OMP-G';
86 expParam.solvers(nSolver).inpaintFrame = @inpaintFrame_OMP_Gabor; % solver function
87 expParam.solvers(nSolver).param.N = expParam.N; % frame length
88 expParam.solvers(nSolver).param.OMPerr = 0.001;
89 expParam.solvers(nSolver).param.sparsityDegree = expParam.solvers(nSolver).param.N/4;
90 expParam.solvers(nSolver).param.D_fun = @Gabor_Dictionary; % Dictionary (function handle)
91 expParam.solvers(nSolver).param.redundancyFactor = 2; % Dictionary redundancy
92 expParam.solvers(nSolver).param.wa = @wRect; % Analysis window
93
94 nSolver = nSolver+1;
95 expParam.solvers(nSolver).name = 'Janssen';
96 expParam.solvers(nSolver).inpaintFrame = @inpaintFrame_janssenInterpolation; % solver function
97 expParam.solvers(nSolver).param.N = expParam.N; % frame length
98 end
99
100
101
102
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 soundDir = expParam.soundDir;
105 wavFiles = dir([soundDir '*.wav']);
106 wavFiles = arrayfun(@(x)[soundDir x.name],wavFiles,'UniformOutput',false);
107
108 %% Draw a list of random frames
109 % Choose an audio file at random
110 frameParam.kFrameFile = randi(length(wavFiles),expParam.NFramesPerHoleSize);
111
112 % For each audio file, find maximum mean energy among all frames
113 [dum fs] = wavread([soundDir wavFiles{1}],'size');
114 Ne = round(512/16000*fs);
115 E2m = zeros(length(wavFiles),1);
116 for kf = 1:length(wavFiles)
117 x=wavread(wavFiles{kf});
118 xm = filter(ones(Ne,1)/Ne,1,abs(x.^2));
119 E2m(kf) = 10*log10(max(xm));
120 end
121
122 % Choose the location of a frame at random, with a minimum energy
123 maxDiffE2m = 10;
124 frameParam.kFrameBegin = NaN(expParam.NFramesPerHoleSize,1);
125 for kf = 1:expParam.NFramesPerHoleSize
126 siz = wavread(wavFiles{frameParam.kFrameFile(kf)},'size');
127 while true
128 frameParam.kFrameBegin(kf) = randi(siz(1)-expParam.N+1);
129 x = wavread(wavFiles{frameParam.kFrameFile(kf)},[0,expParam.N-1]+frameParam.kFrameBegin(kf));
130 E2m0 = 10*log10(mean(abs(x.^2)));
131 if E2m(frameParam.kFrameFile(kf))-E2m0 <= maxDiffE2m
132 break
133 end
134 end
135 end
136
137 %% Test each number of missing samples
138 PerfRes = cell(length(expParam.totalMissSamplesList),length(expParam.solvers));
139 factorsToTest = cell(length(expParam.totalMissSamplesList),length(expParam.solvers));
140 outputFile = [expParam.destDir 'missSampTopoExp.mat'];
141 for kSolver = 1:length(expParam.solvers)
142 fprintf('\n ------ Solver: %s ------\n\n',...
143 expParam.solvers(kSolver).name);
144 for kMiss = 1:length(expParam.totalMissSamplesList)
145 NMissSamples = expParam.totalMissSamplesList(kMiss);
146 factorsToTest{kMiss} = allFactors(NMissSamples);
147 PerfRes{kMiss,kSolver} = zeros([length(factorsToTest{kMiss}),expParam.NFramesPerHoleSize]);
148 for kFactor = 1:length(factorsToTest{kMiss})
149 holeSize = factorsToTest{kMiss}(kFactor);
150 NHoles = NMissSamples/holeSize;
151 fprintf('%d %d-length holes (%d missing samples = %.1f%%)\n',...
152 NHoles,holeSize,NMissSamples,NMissSamples/expParam.N*100)
153 problemParameters.holeSize = holeSize;
154 problemParameters.NHoles = NHoles;
155 for kFrame = 1:expParam.NFramesPerHoleSize
156 %% load audio frame
157 xFrame = wavread(...
158 wavFiles{frameParam.kFrameFile(kFrame)},...
159 frameParam.kFrameBegin(kFrame)+[0,expParam.N-1]);
160
161 %% generate problem
162 [problemData, solutionData] = ...
163 generateMissingGroupsProblem(xFrame,problemParameters);
164
165 %% solve problem
166 xEst = ...
167 expParam.solvers(kSolver).inpaintFrame(...
168 problemData,...
169 expParam.solvers(kSolver).param);
170
171 %% compute and store performance
172 [SNRAll, SNRmiss] = ...
173 SNRInpaintingPerformance(...
174 solutionData.xClean,...
175 problemData.x,...
176 xEst,...
177 problemData.IMiss);
178 PerfRes{kMiss,kSolver}(kFactor,kFrame) = SNRmiss(2);
179
180 end
181 end
182 save(outputFile,'PerfRes','expParam');
183 end
184 end
185
186 figure
187 Nrows = floor(sqrt(length(expParam.solvers)));
188 Ncols = ceil(sqrt(length(expParam.solvers))/Nrows);
189 cmap = lines;
190 for kSolver = 1:length(expParam.solvers)
191 subplot(Nrows,Ncols,kSolver)
192 hold on,grid on
193 for kMiss = 1:length(expParam.totalMissSamplesList)
194 plot(factorsToTest{kMiss},mean(PerfRes{kMiss,kSolver},2),...
195 'color',cmap(kMiss,:));
196 end
197 title(expParam.solvers(kSolver).name)
198 end
199 return
200
201 function m = allFactors(n)
202 % Find the list of all factors (not only prime factors)
203
204 primeFactors = factor(n);
205
206 degrees = zeros(size(primeFactors));
207
208 for k=1:length(degrees)
209 degrees(k) = sum(primeFactors==primeFactors(k));
210 end
211
212 [primeFactors, I] = unique(primeFactors);
213 degrees = degrees(I);
214
215 D = (0:degrees(1)).';
216 for k=2:length(degrees)
217 Dk = ones(size(D,1),1)*(0:degrees(k));
218 D = [repmat(D,degrees(k)+1,1),Dk(:)];
219 end
220
221 m = unique(sort(prod((ones(size(D,1),1)*primeFactors).^D,2)));
222
223 return