comparison toolboxes/AudioInpaintingToolbox/Experiments/DeclippingExperiment/declipOneSoundExperiment.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 31d2864dfdd4
comparison
equal deleted inserted replaced
137:9207d56c5547 138:56d719a5fd31
1 function declipOneSoundExperiment(expParam)
2 % A simple experiment to declip a signal.
3 %
4 % Usage: declipOneSoundExperiment(expParam)
5 %
6 %
7 % Inputs:
8 % - expParam is an optional structure where the user can define
9 % the experiment parameters.
10 % - expParam.clippingLevel: clipping level between 0 and 1.
11 % - expParam.filename: file to be tested.
12 % - expParam.destDir: path to store the results.
13 % - expParam.solver: solver with its parameters
14 % - expParam.destDir: path to store the results.
15 %
16 %
17 % -------------------
18 %
19 % Audio Inpainting toolbox
20 % Date: June 28, 2011
21 % By Valentin Emiya, Amir Adler, Maria Jafari
22 % This code is distributed under the terms of the GNU Public License version 3 (http://www.gnu.org/licenses/gpl.txt).
23
24 if ~isdeployed
25 close all
26 addpath('../../Problems/');
27 addpath('../../Solvers/');
28 addpath('../../Utils/');
29 addpath('../../Utils/dictionaries/');
30 addpath('../../Utils/evaluation/');
31 % addpath('../../Utils/TCPIP_SocketCom/');
32 % javaaddpath('../../Utils/TCPIP_SocketCom');
33 dbstop if error
34 end
35
36 %% Set parameters
37 if nargin<1
38 expParam = [];
39 end
40 if ~isfield(expParam,'filename')
41 expParam.filename = 'male01_8kHz.wav';
42 end
43 if ~isfield(expParam,'clippingLevel')
44 expParam.clippingLevel = 0.6;
45 end
46
47 % Solver
48 if ~isfield(expParam,'solver')
49 warning('AITB:N','Frame length=256 is used to have faster computations. Recommended frame length is 512 at 8kHz.');
50 warning('AITB:overlap','Overlap factor=2 is used to have faster computations. Recommended value: 4.');
51
52 expParam.solver.name = 'OMP-G';
53 expParam.solver.function = @inpaintSignal_IndependentProcessingOfFrames;
54 expParam.solver.param.N = 512; % frame length
55 expParam.solver.param.N = 256; % frame length
56 expParam.solver.param.inpaintFrame = @inpaintFrame_OMP_Gabor; % solver function
57 expParam.solver.param.OMPerr = 0.001;
58 expParam.solver.param.sparsityDegree = expParam.solver.param.N/4;
59 expParam.solver.param.D_fun = @Gabor_Dictionary; % Dictionary (function handle)
60 expParam.solver.param.OLA_frameOverlapFactor = 4;
61 expParam.solver.param.OLA_frameOverlapFactor = 2;
62 expParam.solver.param.redundancyFactor = 2; % Dictionary redundancy
63 expParam.solver.param.wd = @wRect; % Weighting window for dictionary atoms
64 expParam.solver.param.wa = @wRect; % Analysis window
65 expParam.solver.param.OLA_ws = @wSine; % Synthesis window
66 expParam.solver.param.SKIP_CLEAN_FRAMES = true; % do not process frames where there is no missing samples
67 expParam.solver.param.MULTITHREAD_FRAME_PROCESSING = false; % not implemented yet
68 end
69 if ~isfield(expParam,'destDir'),
70 expParam.destDir = '../../tmp/declipOneSound/';
71 end
72 if ~exist(expParam.destDir,'dir')
73 mkdir(expParam.destDir)
74 end
75
76 %% Read test signal
77 [x fs] = wavread(expParam.filename);
78
79 %% Generate the problem
80 [problemData, solutionData] = generateDeclippingProblem(x,expParam.clippingLevel);
81
82 %% Declip with solver
83 fprintf('\nDeclipping\n')
84 % [xEst1 xEst2] = inpaintSignal_IndependentProcessingOfFrames(problemData,param);
85 solverParam = expParam.solver.param;
86 [xEst1 xEst2] = expParam.solver.function(problemData,solverParam);
87
88 %% Compute and display SNR performance
89 L = length(xEst1);
90 N = expParam.solver.param.N;
91 [SNRAll, SNRmiss] = SNRInpaintingPerformance(...
92 solutionData.xClean(N:L-N),problemData.x(N:L-N),...
93 xEst2(N:L-N),problemData.IMiss(N:L-N));
94 fprintf('SNR on missing samples:\n');
95 fprintf('Clipped: %g dB\n',SNRmiss(1));
96 fprintf('Estimate: %g dB\n',SNRmiss(2));
97
98
99 % Plot results
100 xClipped = problemData.x;
101 xClean = solutionData.xClean;
102 figure
103 hold on
104 plot(xClipped,'r')
105 plot(xClean)
106 plot(xEst2,'--g')
107 plot([1;length(xClipped)],[1;1]*[-1,1]*max(abs(xClipped)),':r')
108 legend('Clipped','True solution','Estimate')
109
110 % Normalized and save sounds
111 normX = 1.1*max(abs([xEst1(:);xEst2(:);xClean(:)]));
112 L = min([length(xEst2),length(xEst1),length(xClean),length(xEst1),length(xClipped)]);
113 xEst1 = xEst1(1:L)/normX;
114 xEst2 = xEst2(1:L)/normX;
115 xClipped = xClipped(1:L)/normX;
116 xClean = xClean(1:L)/normX;
117 wavwrite(xEst1,fs,[expParam.destDir 'xEst1.wav']);
118 wavwrite(xEst2,fs,[expParam.destDir 'xEst2.wav']);
119 wavwrite(xClipped,fs,[expParam.destDir 'xClipped.wav']);
120 wavwrite(xClean,fs,[expParam.destDir 'xClean.wav']);
121
122
123 return