annotate toolboxes/AudioInpaintingToolbox/Experiments/DeclippingExperiment/declipOneSoundExperiment.m @ 233:88a5c02d20d3

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