Mercurial > hg > smallbox
comparison toolboxes/AudioInpaintingToolbox/Experiments/DeclippingExperiment/declippingExperiment.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 declippingExperiment(expParam) | |
2 % Declip several sounds with different clipping levels, using several | |
3 % solvers. | |
4 % | |
5 % Usage: declippingExperiment(expParam) | |
6 % | |
7 % | |
8 % Inputs: | |
9 % - expParam is an optional structure where the user can define | |
10 % the experiment parameters. | |
11 % - expParam.clippingScale: clipping values to test, as a vector | |
12 % of real numbers in ]0,1[. | |
13 % - expParam.soundDir: path to sound directory. All the .wav files | |
14 % in this directory will be tested. | |
15 % - expParam.destDir: path to store the results. | |
16 % - expParam.solvers: list of solvers with their parameters | |
17 % | |
18 % | |
19 % ------------------- | |
20 % | |
21 % Audio Inpainting toolbox | |
22 % Date: June 28, 2011 | |
23 % By Valentin Emiya, Amir Adler, Maria Jafari | |
24 % This code is distributed under the terms of the GNU Public License version 3 (http://www.gnu.org/licenses/gpl.txt). | |
25 | |
26 if ~isdeployed | |
27 addpath('../../Problems/'); | |
28 addpath('../../Solvers/'); | |
29 addpath('../../Utils/'); | |
30 addpath('../../Utils/dictionaries/'); | |
31 addpath('../../Utils/evaluation/'); | |
32 % addpath('../../Utils/TCPIP_SocketCom/'); | |
33 % javaaddpath('../../Utils/TCPIP_SocketCom'); | |
34 dbstop if error | |
35 close all | |
36 end | |
37 | |
38 if nargin<1 | |
39 expParam = []; | |
40 end | |
41 if ~isfield(expParam,'clippingScale'), | |
42 expParam.clippingScale = 0.4:0.2:0.8; | |
43 end | |
44 if ~isfield(expParam,'soundDir'), | |
45 expParam.soundDir = '../../Data/testSpeech8kHz_from16kHz/'; | |
46 expParam.soundDir = '../../Data/shortTest/'; | |
47 warning('AITB:soundDir','soundDir has only one sound to have faster computations. Recommended soundDir: ../../Data/testSpeech8kHz_from16kHz/'); | |
48 end | |
49 if ~isfield(expParam,'destDir'), | |
50 expParam.destDir = '../../tmp/declip/'; | |
51 end | |
52 | |
53 %% Set parameters | |
54 | |
55 if ~isfield(expParam,'solvers'), | |
56 % Choose the solver methods you would like to test: OMP, L1, Janssen | |
57 warning('AITB:N','Frame length=256 is used to have faster computations. Recommended frame length is 512 at 8kHz.'); | |
58 warning('AITB:overlap','Overlap factor=2 is used to have faster computations. Recommended value: 4.'); | |
59 nSolver = 0; | |
60 | |
61 nSolver = nSolver+1; | |
62 expParam.solvers(nSolver).name = 'OMP-C'; | |
63 expParam.solvers(nSolver).function = @inpaintSignal_IndependentProcessingOfFrames; | |
64 expParam.solvers(nSolver).param.N = 512; % frame length | |
65 expParam.solvers(nSolver).param.N = 256; % frame length | |
66 expParam.solvers(nSolver).param.inpaintFrame = @inpaintFrame_OMP; % solver function | |
67 expParam.solvers(nSolver).param.OMPerr = 0.001; | |
68 expParam.solvers(nSolver).param.sparsityDegree = expParam.solvers(nSolver).param.N/4; | |
69 expParam.solvers(nSolver).param.D_fun = @DCT_Dictionary; % Dictionary (function handle) | |
70 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 4; | |
71 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 2; | |
72 expParam.solvers(nSolver).param.redundancyFactor = 2; % Dictionary redundancy | |
73 expParam.solvers(nSolver).param.wd = @wRect; % Weighting window for dictionary atoms | |
74 expParam.solvers(nSolver).param.wa = @wRect; % Analysis window | |
75 expParam.solvers(nSolver).param.OLA_ws = @wSine; % Synthesis window | |
76 expParam.solvers(nSolver).param.SKIP_CLEAN_FRAMES = true; % do not process frames where there is no missing samples | |
77 expParam.solvers(nSolver).param.MULTITHREAD_FRAME_PROCESSING = false; % not implemented yet | |
78 | |
79 nSolver = nSolver+1; | |
80 expParam.solvers(nSolver).name = 'consOMP-C'; | |
81 expParam.solvers(nSolver).function = @inpaintSignal_IndependentProcessingOfFrames; | |
82 expParam.solvers(nSolver).param.N = 512; % frame length | |
83 expParam.solvers(nSolver).param.N = 256; % frame length | |
84 expParam.solvers(nSolver).param.inpaintFrame = @inpaintFrame_consOMP; % solver function | |
85 expParam.solvers(nSolver).param.OMPerr = 0.001; | |
86 expParam.solvers(nSolver).param.sparsityDegree = expParam.solvers(nSolver).param.N/4; | |
87 expParam.solvers(nSolver).param.D_fun = @DCT_Dictionary; % Dictionary (function handle) | |
88 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 4; | |
89 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 2; | |
90 expParam.solvers(nSolver).param.redundancyFactor = 2; % Dictionary redundancy | |
91 expParam.solvers(nSolver).param.wd = @wRect; % Weighting window for dictionary atoms | |
92 expParam.solvers(nSolver).param.wa = @wRect; % Analysis window | |
93 expParam.solvers(nSolver).param.OLA_ws = @wSine; % Synthesis window | |
94 expParam.solvers(nSolver).param.SKIP_CLEAN_FRAMES = true; % do not process frames where there is no missing samples | |
95 expParam.solvers(nSolver).param.MULTITHREAD_FRAME_PROCESSING = false; % not implemented yet | |
96 | |
97 nSolver = nSolver+1; | |
98 expParam.solvers(nSolver).name = 'OMP-G'; | |
99 expParam.solvers(nSolver).function = @inpaintSignal_IndependentProcessingOfFrames; | |
100 expParam.solvers(nSolver).param.N = 512; % frame length | |
101 expParam.solvers(nSolver).param.N = 256; % frame length | |
102 expParam.solvers(nSolver).param.inpaintFrame = @inpaintFrame_OMP_Gabor; % solver function | |
103 expParam.solvers(nSolver).param.OMPerr = 0.001; | |
104 expParam.solvers(nSolver).param.sparsityDegree = expParam.solvers(nSolver).param.N/4; | |
105 expParam.solvers(nSolver).param.D_fun = @Gabor_Dictionary; % Dictionary (function handle) | |
106 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 4; | |
107 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 2; | |
108 expParam.solvers(nSolver).param.redundancyFactor = 2; % Dictionary redundancy | |
109 expParam.solvers(nSolver).param.wd = @wRect; % Weighting window for dictionary atoms | |
110 expParam.solvers(nSolver).param.wa = @wRect; % Analysis window | |
111 expParam.solvers(nSolver).param.OLA_ws = @wSine; % Synthesis window | |
112 expParam.solvers(nSolver).param.SKIP_CLEAN_FRAMES = true; % do not process frames where there is no missing samples | |
113 expParam.solvers(nSolver).param.MULTITHREAD_FRAME_PROCESSING = false; % not implemented yet | |
114 | |
115 nSolver = nSolver+1; | |
116 expParam.solvers(nSolver).name = 'consOMP-G'; | |
117 expParam.solvers(nSolver).function = @inpaintSignal_IndependentProcessingOfFrames; | |
118 expParam.solvers(nSolver).param.N = 512; % frame length | |
119 expParam.solvers(nSolver).param.N = 256; % frame length | |
120 expParam.solvers(nSolver).param.inpaintFrame = @inpaintFrame_consOMP_Gabor; % solver function | |
121 expParam.solvers(nSolver).param.OMPerr = 0.001; | |
122 expParam.solvers(nSolver).param.sparsityDegree = expParam.solvers(nSolver).param.N/4; | |
123 expParam.solvers(nSolver).param.D_fun = @Gabor_Dictionary; % Dictionary (function handle) | |
124 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 4; | |
125 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 2 | |
126 expParam.solvers(nSolver).param.redundancyFactor = 2; % Dictionary redundancy | |
127 expParam.solvers(nSolver).param.wd = @wRect; % Weighting window for dictionary atoms | |
128 expParam.solvers(nSolver).param.wa = @wRect; % Analysis window | |
129 expParam.solvers(nSolver).param.OLA_ws = @wSine; % Synthesis window | |
130 expParam.solvers(nSolver).param.SKIP_CLEAN_FRAMES = true; % do not process frames where there is no missing samples | |
131 expParam.solvers(nSolver).param.MULTITHREAD_FRAME_PROCESSING = false; % not implemented yet | |
132 | |
133 nSolver = nSolver+1; | |
134 expParam.solvers(nSolver).name = 'Janssen'; | |
135 expParam.solvers(nSolver).function = @inpaintSignal_IndependentProcessingOfFrames; | |
136 expParam.solvers(nSolver).param.inpaintFrame = @inpaintFrame_janssenInterpolation; % solver function | |
137 expParam.solvers(nSolver).param.N = 512; % frame length | |
138 expParam.solvers(nSolver).param.N = 256; | |
139 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 4; | |
140 expParam.solvers(nSolver).param.OLA_frameOverlapFactor = 2 | |
141 expParam.solvers(nSolver).param.wa = @wRect; % Analysis window | |
142 expParam.solvers(nSolver).param.OLA_ws = @wSine; % Synthesis window | |
143 expParam.solvers(nSolver).param.SKIP_CLEAN_FRAMES = true; % do not process frames where there is no missing samples | |
144 expParam.solvers(nSolver).param.MULTITHREAD_FRAME_PROCESSING = false; % not implemented yet | |
145 end | |
146 | |
147 SNRClip = zeros(0,0,0); | |
148 fprintf('Folder %s\n',expParam.soundDir); | |
149 if ~exist(expParam.destDir,'dir') | |
150 mkdir(expParam.destDir) | |
151 end | |
152 soundFiles = dir([expParam.soundDir '*.wav']); | |
153 | |
154 for kf = 1:length(soundFiles) | |
155 soundfile = [expParam.soundDir soundFiles(kf).name]; | |
156 fprintf(' File %s\n',soundfile); | |
157 %% Read test signal | |
158 [x fs] = wavread(soundfile); | |
159 | |
160 for kClip = 1:length(expParam.clippingScale) | |
161 clippingLevel = expParam.clippingScale(kClip); | |
162 fprintf(' Clip level %g\n',clippingLevel); | |
163 | |
164 %% Generate the problem | |
165 [problemData, solutionData] = generateDeclippingProblem(x,clippingLevel); | |
166 | |
167 for nSolver = 1:length(expParam.solvers) | |
168 %% Declip with solver | |
169 solverParam = expParam.solvers(nSolver).param; | |
170 [xEst1 xEst2] = expParam.solvers(nSolver).function(problemData,solverParam); | |
171 | |
172 %% compute performance | |
173 L = length(xEst1); | |
174 N = solverParam.N; | |
175 [SNRAll, SNRmiss] = ... | |
176 SNRInpaintingPerformance(... | |
177 solutionData.xClean(N:L-N),... | |
178 problemData.x(N:L-N),... | |
179 xEst2(N:L-N),... | |
180 problemData.IMiss(N:L-N)); | |
181 SNRClip(kf,kClip,nSolver) = SNRmiss(2); | |
182 | |
183 % normalize and save both the reference and the estimates! | |
184 normX = 1.1*max(abs([xEst1(:);xEst2(:);solutionData.xClean(:)])); | |
185 | |
186 L = min([length(xEst2),length(xEst1),length(solutionData.xClean),length(problemData.x)]); | |
187 xEst1 = xEst1(1:L)/normX; | |
188 xEst2 = xEst2(1:L)/normX; | |
189 xClipped = problemData.x(1:L)/normX; | |
190 xClean = solutionData.xClean(1:L)/normX; | |
191 wavwrite(xEst1,fs,sprintf('%s%s%s%g.wav',expParam.destDir,soundFiles(kf).name(1:end-4),'Est1',clippingLevel)); | |
192 wavwrite(xEst2,fs,sprintf('%s%s%s%g.wav',expParam.destDir,soundFiles(kf).name(1:end-4),'Est2',clippingLevel)); | |
193 wavwrite(xClipped,fs,sprintf('%s%s%s%g.wav',expParam.destDir,soundFiles(kf).name(1:end-4),'Clipped',clippingLevel)); | |
194 wavwrite(xClean,fs,sprintf('%s%s%s%g.wav',expParam.destDir,soundFiles(kf).name(1:end-4),'Ref',clippingLevel)); | |
195 | |
196 fprintf('\n'); | |
197 clear a xEst1 xEst2 xClipped xClean IClipped | |
198 save([expParam.destDir 'clippingExp.mat']); | |
199 end | |
200 end | |
201 end | |
202 | |
203 %% Plot results | |
204 averageSNR = squeeze(mean(SNRClip,1)); | |
205 disp(averageSNR) | |
206 figure, | |
207 plot(averageSNR) | |
208 legend(arrayfun(@(x)x.name,expParam.solvers,'UniformOutput',false)); | |
209 xlabel('Clipping level') | |
210 ylabel('SNR') | |
211 return |