ivan@136: %% Audio Declipping Example ivan@136: % ivan@140: % Audio declipping is a problem proposed in Audio Inpaining Toolbox and ivan@140: % in [2]. This is an example of solving the problem with fast omp using ivan@140: % Gabor dictionary and ompGabor implemented in SMALLbox [1]. ivan@140: % ivan@140: % [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an ivan@140: % evaluation framework for sparse representations and dictionary ivan@140: % learning algorithms," V. Vigneron et al. (Eds.): LVA/ICA 2010, ivan@140: % Springer-Verlag, Berlin, Germany, LNCS 6365, pp. 418-425 ivan@140: % [2] A. Adler, V. Emiya, M. G. Jafari, M. Elad, R. Gribonval, and M. D. ivan@140: % Plumbley, “Audio Inpainting,” submitted to IEEE Trans. Audio, Speech, ivan@140: % and Lang. Proc., 2011, http://hal.inria.fr/inria-00577079/en/. ivan@136: ivan@136: % ivan@136: % Centre for Digital Music, Queen Mary, University of London. ivan@136: % This file copyright 2011 Ivan Damnjanovic. ivan@136: % ivan@136: % This program is free software; you can redistribute it and/or ivan@136: % modify it under the terms of the GNU General Public License as ivan@136: % published by the Free Software Foundation; either version 2 of the ivan@136: % License, or (at your option) any later version. See the file ivan@136: % COPYING included with this distribution for more information. ivan@136: % ivan@136: %% ivan@136: ivan@136: clear all; ivan@140: % Defining the solvers to test in Audio declipping scenario ivan@140: ivan@140: % First solver omp2 - DCT+DST dictionary with no additional constraints ivan@140: ivan@140: SMALL.solver(1) = SMALL_init_solver('ompbox', 'omp2', '', 0); ivan@140: SMALL.solver(1).add_constraints = 0; ivan@140: ivan@140: % Second solver omp2 - DCT+DST dictionary with additional constraints ivan@140: ivan@140: SMALL.solver(2) = SMALL_init_solver('ompbox', 'omp2', '', 0); ivan@140: SMALL.solver(2).add_constraints = 1; ivan@140: ivan@140: % Third solver omp2 - Gabor dictionary with no additional constraints ivan@140: ivan@140: SMALL.solver(3) = SMALL_init_solver('ompbox', 'omp2Gabor', '', 0); ivan@140: SMALL.solver(3).add_constraints = 0; ivan@140: ivan@140: % Fourth solver omp2- Gabor dictionary with no additional constraints ivan@140: ivan@140: SMALL.solver(4) = SMALL_init_solver('ompbox', 'omp2Gabor', '', 0); ivan@140: SMALL.solver(4).add_constraints = 1; ivan@136: ivan@136: % Defining the Problem structure ivan@136: ivan@154: SMALL.Problem = generateAudioDeclippingProblem('', 0.6, 256, 0.5, @wRect, @wSine, @wRect, @Gabor_Dictionary, 2); ivan@136: ivan@140: for idxSolver = 1:4 ivan@136: ivan@140: fprintf('\nStarting Audio Declipping of %s... \n', SMALL.Problem.name); ivan@140: fprintf('\nClipping level %s... \n', SMALL.Problem.clippingLevel); ivan@140: ivan@140: start=cputime; ivan@140: tStart=tic; ivan@140: ivan@140: error2=0.001^2; ivan@140: coeffFrames = zeros(SMALL.Problem.p, SMALL.Problem.n); ivan@140: ivan@140: ivan@140: ivan@140: for i = 1:SMALL.Problem.n ivan@140: ivan@140: idx = find(SMALL.Problem.M(:,i)); ivan@140: if size(idx,1)==SMALL.Problem.m ivan@140: continue ivan@140: end ivan@140: Dict = SMALL.Problem.B(idx,:); ivan@140: wDict = 1./sqrt(diag(Dict'*Dict)); ivan@140: ivan@140: SMALL.Problem.A = Dict*diag(wDict); ivan@140: ivan@140: SMALL.Problem.b1 = SMALL.Problem.b(idx,i); ivan@140: ivan@140: ivan@140: ivan@140: % set solver parameters ivan@140: ivan@140: SMALL.solver(idxSolver).param=struct(... ivan@140: 'epsilon', error2*size(idx,1),... ivan@140: 'maxatoms', 128, ... ivan@140: 'profile', 'off'); ivan@140: ivan@140: % Find solution ivan@140: ivan@140: SMALL.solver(idxSolver)=SMALL_solve(SMALL.Problem, SMALL.solver(idxSolver)); ivan@140: ivan@140: % Refine solution with additional constraints for declipping scenario ivan@140: ivan@140: if (SMALL.solver(idxSolver).add_constraints) ivan@140: SMALL.solver(idxSolver)=CVX_add_const_Audio_declipping(... ivan@140: SMALL.Problem, SMALL.solver(idxSolver), i); ivan@140: end ivan@140: ivan@140: %% ivan@140: coeffFrames(:,i) = wDict .* SMALL.solver(idxSolver).solution; ivan@140: ivan@140: ivan@137: end ivan@137: ivan@140: %% Set reconstruction function ivan@136: ivan@140: SMALL.Problem.reconstruct=@(x) AudioDeclipping_reconstruct(x, SMALL.Problem); ivan@140: reconstructed=SMALL.Problem.reconstruct(coeffFrames); ivan@140: SMALL.Problem = rmfield(SMALL.Problem, 'reconstruct'); ivan@140: tElapsed=toc(tStart); ivan@136: ivan@140: SMALL.solver(idxSolver).time = cputime - start; ivan@140: fprintf('Solver %s finished task in %2f seconds (cpu time). \n', ... ivan@140: SMALL.solver(idxSolver).name, SMALL.solver(idxSolver).time); ivan@140: fprintf('Solver %s finished task in %2f seconds (tic-toc time). \n', ... ivan@140: SMALL.solver(idxSolver).name, tElapsed); ivan@137: ivan@136: ivan@136: ivan@140: %% Plot results ivan@136: ivan@140: xClipped = SMALL.Problem.clipped; ivan@140: xClean = SMALL.Problem.original; ivan@140: xEst1 = reconstructed.audioAllSamples; ivan@140: xEst2 = reconstructed.audioOnlyClipped; ivan@140: fs = SMALL.Problem.fs; ivan@136: ivan@140: figure ivan@140: hold on ivan@140: plot(xClipped,'r') ivan@140: plot(xClean) ivan@140: plot(xEst2,'--g') ivan@140: plot([1;length(xClipped)],[1;1]*[-1,1]*max(abs(xClipped)),':r') ivan@140: legend('Clipped','True solution','Estimate') ivan@136: end ivan@136: ivan@140: % % Normalized and save sounds ivan@140: % normX = 1.1*max(abs([xEst1(:);xEst2(:);xClean(:)])); ivan@140: % L = min([length(xEst2),length(xEst1),length(xClean),length(xEst1),length(xClipped)]); ivan@140: % xEst1 = xEst1(1:L)/normX; ivan@140: % xEst2 = xEst2(1:L)/normX; ivan@140: % xClipped = xClipped(1:L)/normX; ivan@140: % xClean = xClean(1:L)/normX; ivan@139: % wavwrite(xEst1,fs,[expParam.destDir 'xEst1.wav']); ivan@139: % wavwrite(xEst2,fs,[expParam.destDir 'xEst2.wav']); ivan@139: % wavwrite(xClipped,fs,[expParam.destDir 'xClipped.wav']); ivan@139: % wavwrite(xClean,fs,[expParam.destDir 'xClean.wav']);