comparison examples/AudioInpainting/Audio_Declipping_Example.m @ 137:9207d56c5547 ivand_dev

New ompbox in utils for testing purposes
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Thu, 21 Jul 2011 14:07:41 +0100
parents 1334d2302dd9
children 4bd6856a7128
comparison
equal deleted inserted replaced
136:1334d2302dd9 137:9207d56c5547
31 % subplot(1,2,1); imagesc(SMALL.Problem.imageTrg/SMALL.Problem.maxval); 31 % subplot(1,2,1); imagesc(SMALL.Problem.imageTrg/SMALL.Problem.maxval);
32 % title('Original Image');colormap(gray);axis off; axis image; 32 % title('Original Image');colormap(gray);axis off; axis image;
33 % subplot(1,2,2); imagesc(SMALL.Problem.imageSrc/SMALL.Problem.maxval); 33 % subplot(1,2,2); imagesc(SMALL.Problem.imageSrc/SMALL.Problem.maxval);
34 % title('Dictionary image:');colormap(gray);axis off; axis image; 34 % title('Dictionary image:');colormap(gray);axis off; axis image;
35 time=0; 35 time=0;
36 error2=0.001^2;
36 coeffFrames = zeros(SMALL.Problem.p, SMALL.Problem.n); 37 coeffFrames = zeros(SMALL.Problem.p, SMALL.Problem.n);
37 38
38 for i=1:SMALL.Problem.n 39 for i=1:SMALL.Problem.n
39 40
40 idx = find(SMALL.Problem.M(:,i)); 41 idx = find(SMALL.Problem.M(:,i));
41 SMALL.Problem.A = SMALL.Problem.B(idx,:); 42 if size(idx,1)==SMALL.Problem.m
43 continue
44 end
45 Dict = SMALL.Problem.B(idx,:);
46 wDict = 1./sqrt(diag(Dict'*Dict));
47
48 SMALL.Problem.A = Dict*diag(wDict);
42 49
43 SMALL.Problem.b1 = SMALL.Problem.b(idx,i); 50 SMALL.Problem.b1 = SMALL.Problem.b(idx,i);
44 51
45 52
46 53
47 % Defining the parameters sparse representation 54 % Defining the parameters sparse representation
48 SMALL.solver=SMALL_init_solver; 55 SMALL.solver=SMALL_init_solver;
49 SMALL.solver.toolbox='ompbox'; 56 SMALL.solver.toolbox='ompbox';
50 SMALL.solver.name='omp2'; 57 SMALL.solver.name='omp2Gabor';
51 58
52 SMALL.solver.param=struct(... 59 SMALL.solver.param=struct(...
53 'epsilon', 0.001,... 60 'epsilon', error2*size(idx,1),...
54 'maxatoms', 64); 61 'maxatoms', 128);
55 62
56 % Find solution 63 % Find solution
57 64
58 SMALL.solver=SMALL_solve(SMALL.Problem, SMALL.solver); 65 SMALL.solver=SMALL_solve(SMALL.Problem, SMALL.solver);
59 66
60 67
61 coeffFrames(:,i) = SMALL.solver.solution; 68 coeffFrames(:,i) = wDict .* SMALL.solver.solution;
62 time = time + SMALL.solver.time; 69 time = time + SMALL.solver.time;
63 70
64 71
65 72
66 end 73 end
68 %% Set reconstruction function 75 %% Set reconstruction function
69 76
70 SMALL.Problem.reconstruct=@(x) AudioDeclipping_reconstruct(x, SMALL.Problem); 77 SMALL.Problem.reconstruct=@(x) AudioDeclipping_reconstruct(x, SMALL.Problem);
71 reconstructed=SMALL.Problem.reconstruct(coeffFrames); 78 reconstructed=SMALL.Problem.reconstruct(coeffFrames);
72 79
73 %% plot time and psnr given dictionary size %%
74 figure('Name', 'time and psnr');
75 80
76 subplot(1,2,1); plot(dictsize(1,:), time(1,:), 'ro-'); 81
77 title('Time vs number of source image patches used'); 82 %% Plot results
78 subplot(1,2,2); plot(dictsize(1,:), psnr(1,:), 'b*-'); 83
79 title('PSNR vs number of source image patches used'); 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']);
106 wavwrite(xEst2,fs,[expParam.destDir 'xEst2.wav']);
107 wavwrite(xClipped,fs,[expParam.destDir 'xClipped.wav']);
108 wavwrite(xClean,fs,[expParam.destDir 'xClean.wav']);