Mercurial > hg > smallbox
comparison examples/AudioInpainting/Audio_Declipping_Example.m @ 140:31d2864dfdd4 ivand_dev
Audio Impainting additional constraints with cvx added
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 17:27:05 +0100 |
parents | 4bd6856a7128 |
children | 0de08f68256b |
comparison
equal
deleted
inserted
replaced
139:4bd6856a7128 | 140:31d2864dfdd4 |
---|---|
1 %% Audio Declipping Example | 1 %% Audio Declipping Example |
2 % | 2 % |
3 % CHANGE!!! This example is based on the experiment suggested by Professor Pierre | 3 % Audio declipping is a problem proposed in Audio Inpaining Toolbox and |
4 % Vandergheynst on the SMALL meeting in Villars. | 4 % in [2]. This is an example of solving the problem with fast omp using |
5 % The idea behind is to use patches from source image as a dictionary in | 5 % Gabor dictionary and ompGabor implemented in SMALLbox [1]. |
6 % which we represent target image using matching pursuit algorithm. | 6 % |
7 % Calling Pierre_Problem function to get src image to be used as dictionary | 7 % [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an |
8 % and target image to be represented using MP with 3 patches from source image | 8 % evaluation framework for sparse representations and dictionary |
9 % learning algorithms," V. Vigneron et al. (Eds.): LVA/ICA 2010, | |
10 % Springer-Verlag, Berlin, Germany, LNCS 6365, pp. 418-425 | |
11 % [2] A. Adler, V. Emiya, M. G. Jafari, M. Elad, R. Gribonval, and M. D. | |
12 % Plumbley, “Audio Inpainting,” submitted to IEEE Trans. Audio, Speech, | |
13 % and Lang. Proc., 2011, http://hal.inria.fr/inria-00577079/en/. | |
9 | 14 |
10 % | 15 % |
11 % Centre for Digital Music, Queen Mary, University of London. | 16 % Centre for Digital Music, Queen Mary, University of London. |
12 % This file copyright 2011 Ivan Damnjanovic. | 17 % This file copyright 2011 Ivan Damnjanovic. |
13 % | 18 % |
18 % COPYING included with this distribution for more information. | 23 % COPYING included with this distribution for more information. |
19 % | 24 % |
20 %% | 25 %% |
21 | 26 |
22 clear all; | 27 clear all; |
28 % Defining the solvers to test in Audio declipping scenario | |
29 | |
30 % First solver omp2 - DCT+DST dictionary with no additional constraints | |
31 | |
32 SMALL.solver(1) = SMALL_init_solver('ompbox', 'omp2', '', 0); | |
33 SMALL.solver(1).add_constraints = 0; | |
34 | |
35 % Second solver omp2 - DCT+DST dictionary with additional constraints | |
36 | |
37 SMALL.solver(2) = SMALL_init_solver('ompbox', 'omp2', '', 0); | |
38 SMALL.solver(2).add_constraints = 1; | |
39 | |
40 % Third solver omp2 - Gabor dictionary with no additional constraints | |
41 | |
42 SMALL.solver(3) = SMALL_init_solver('ompbox', 'omp2Gabor', '', 0); | |
43 SMALL.solver(3).add_constraints = 0; | |
44 | |
45 % Fourth solver omp2- Gabor dictionary with no additional constraints | |
46 | |
47 SMALL.solver(4) = SMALL_init_solver('ompbox', 'omp2Gabor', '', 0); | |
48 SMALL.solver(4).add_constraints = 1; | |
23 | 49 |
24 % Defining the Problem structure | 50 % Defining the Problem structure |
25 | 51 |
26 SMALL.Problem = generateAudioDeclippingProblem('male01_8kHz.wav', 0.6, 256, 0.5, @wRect, @wSine, @wRect, @Gabor_Dictionary, 2); | 52 SMALL.Problem = generateAudioDeclippingProblem('male01_8kHz.wav', 0.6, 256, 0.5, @wRect, @wSine, @wRect, @Gabor_Dictionary, 2); |
27 | 53 |
28 % % Show original image and image that is used as a dictionary | 54 for idxSolver = 1:4 |
29 % figure('Name', 'Original and Dictionary Image'); | |
30 % | |
31 % subplot(1,2,1); imagesc(SMALL.Problem.imageTrg/SMALL.Problem.maxval); | |
32 % title('Original Image');colormap(gray);axis off; axis image; | |
33 % subplot(1,2,2); imagesc(SMALL.Problem.imageSrc/SMALL.Problem.maxval); | |
34 % title('Dictionary image:');colormap(gray);axis off; axis image; | |
35 time=0; | |
36 error2=0.001^2; | |
37 coeffFrames = zeros(SMALL.Problem.p, SMALL.Problem.n); | |
38 | |
39 for i=1:SMALL.Problem.n | |
40 | 55 |
41 idx = find(SMALL.Problem.M(:,i)); | 56 fprintf('\nStarting Audio Declipping of %s... \n', SMALL.Problem.name); |
42 if size(idx,1)==SMALL.Problem.m | 57 fprintf('\nClipping level %s... \n', SMALL.Problem.clippingLevel); |
43 continue | |
44 end | |
45 Dict = SMALL.Problem.B(idx,:); | |
46 wDict = 1./sqrt(diag(Dict'*Dict)); | |
47 | 58 |
48 SMALL.Problem.A = Dict*diag(wDict); | 59 start=cputime; |
60 tStart=tic; | |
49 | 61 |
50 SMALL.Problem.b1 = SMALL.Problem.b(idx,i); | 62 error2=0.001^2; |
63 coeffFrames = zeros(SMALL.Problem.p, SMALL.Problem.n); | |
51 | 64 |
52 | 65 |
53 | 66 |
54 % Defining the parameters sparse representation | 67 for i = 1:SMALL.Problem.n |
55 SMALL.solver=SMALL_init_solver; | 68 |
56 SMALL.solver.toolbox='ompbox'; | 69 idx = find(SMALL.Problem.M(:,i)); |
57 SMALL.solver.name='omp2Gabor'; | 70 if size(idx,1)==SMALL.Problem.m |
71 continue | |
72 end | |
73 Dict = SMALL.Problem.B(idx,:); | |
74 wDict = 1./sqrt(diag(Dict'*Dict)); | |
75 | |
76 SMALL.Problem.A = Dict*diag(wDict); | |
77 | |
78 SMALL.Problem.b1 = SMALL.Problem.b(idx,i); | |
79 | |
80 | |
81 | |
82 % set solver parameters | |
83 | |
84 SMALL.solver(idxSolver).param=struct(... | |
85 'epsilon', error2*size(idx,1),... | |
86 'maxatoms', 128, ... | |
87 'profile', 'off'); | |
88 | |
89 % Find solution | |
90 | |
91 SMALL.solver(idxSolver)=SMALL_solve(SMALL.Problem, SMALL.solver(idxSolver)); | |
92 | |
93 % Refine solution with additional constraints for declipping scenario | |
94 | |
95 if (SMALL.solver(idxSolver).add_constraints) | |
96 SMALL.solver(idxSolver)=CVX_add_const_Audio_declipping(... | |
97 SMALL.Problem, SMALL.solver(idxSolver), i); | |
98 end | |
99 | |
100 %% | |
101 coeffFrames(:,i) = wDict .* SMALL.solver(idxSolver).solution; | |
102 | |
103 | |
104 end | |
58 | 105 |
59 SMALL.solver.param=struct(... | 106 %% Set reconstruction function |
60 'epsilon', error2*size(idx,1),... | |
61 'maxatoms', 128); | |
62 | 107 |
63 % Find solution | 108 SMALL.Problem.reconstruct=@(x) AudioDeclipping_reconstruct(x, SMALL.Problem); |
109 reconstructed=SMALL.Problem.reconstruct(coeffFrames); | |
110 SMALL.Problem = rmfield(SMALL.Problem, 'reconstruct'); | |
111 tElapsed=toc(tStart); | |
64 | 112 |
65 SMALL.solver=SMALL_solve(SMALL.Problem, SMALL.solver); | 113 SMALL.solver(idxSolver).time = cputime - start; |
114 fprintf('Solver %s finished task in %2f seconds (cpu time). \n', ... | |
115 SMALL.solver(idxSolver).name, SMALL.solver(idxSolver).time); | |
116 fprintf('Solver %s finished task in %2f seconds (tic-toc time). \n', ... | |
117 SMALL.solver(idxSolver).name, tElapsed); | |
66 | 118 |
67 | 119 |
68 coeffFrames(:,i) = wDict .* SMALL.solver.solution; | |
69 time = time + SMALL.solver.time; | |
70 | 120 |
121 %% Plot results | |
71 | 122 |
72 | 123 xClipped = SMALL.Problem.clipped; |
124 xClean = SMALL.Problem.original; | |
125 xEst1 = reconstructed.audioAllSamples; | |
126 xEst2 = reconstructed.audioOnlyClipped; | |
127 fs = SMALL.Problem.fs; | |
128 | |
129 figure | |
130 hold on | |
131 plot(xClipped,'r') | |
132 plot(xClean) | |
133 plot(xEst2,'--g') | |
134 plot([1;length(xClipped)],[1;1]*[-1,1]*max(abs(xClipped)),':r') | |
135 legend('Clipped','True solution','Estimate') | |
73 end | 136 end |
74 | 137 |
75 %% Set reconstruction function | 138 % % Normalized and save sounds |
76 | 139 % normX = 1.1*max(abs([xEst1(:);xEst2(:);xClean(:)])); |
77 SMALL.Problem.reconstruct=@(x) AudioDeclipping_reconstruct(x, SMALL.Problem); | 140 % L = min([length(xEst2),length(xEst1),length(xClean),length(xEst1),length(xClipped)]); |
78 reconstructed=SMALL.Problem.reconstruct(coeffFrames); | 141 % xEst1 = xEst1(1:L)/normX; |
79 | 142 % xEst2 = xEst2(1:L)/normX; |
80 | 143 % xClipped = xClipped(1:L)/normX; |
81 | 144 % xClean = xClean(1:L)/normX; |
82 %% Plot results | |
83 | |
84 xClipped = SMALL.Problem.clipped; | |
85 xClean = SMALL.Problem.original; | |
86 xEst1 = reconstructed.audioAllSamples; | |
87 xEst2 = reconstructed.audioOnlyClipped; | |
88 fs = SMALL.Problem.fs; | |
89 | |
90 figure | |
91 hold on | |
92 plot(xClipped,'r') | |
93 plot(xClean) | |
94 plot(xEst2,'--g') | |
95 plot([1;length(xClipped)],[1;1]*[-1,1]*max(abs(xClipped)),':r') | |
96 legend('Clipped','True solution','Estimate') | |
97 | |
98 % Normalized and save sounds | |
99 normX = 1.1*max(abs([xEst1(:);xEst2(:);xClean(:)])); | |
100 L = min([length(xEst2),length(xEst1),length(xClean),length(xEst1),length(xClipped)]); | |
101 xEst1 = xEst1(1:L)/normX; | |
102 xEst2 = xEst2(1:L)/normX; | |
103 xClipped = xClipped(1:L)/normX; | |
104 xClean = xClean(1:L)/normX; | |
105 % wavwrite(xEst1,fs,[expParam.destDir 'xEst1.wav']); | 145 % wavwrite(xEst1,fs,[expParam.destDir 'xEst1.wav']); |
106 % wavwrite(xEst2,fs,[expParam.destDir 'xEst2.wav']); | 146 % wavwrite(xEst2,fs,[expParam.destDir 'xEst2.wav']); |
107 % wavwrite(xClipped,fs,[expParam.destDir 'xClipped.wav']); | 147 % wavwrite(xClipped,fs,[expParam.destDir 'xClipped.wav']); |
108 % wavwrite(xClean,fs,[expParam.destDir 'xClean.wav']); | 148 % wavwrite(xClean,fs,[expParam.destDir 'xClean.wav']); |