diff 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
line wrap: on
line diff
--- a/examples/AudioInpainting/Audio_Declipping_Example.m	Thu Jul 14 16:26:07 2011 +0100
+++ b/examples/AudioInpainting/Audio_Declipping_Example.m	Thu Jul 21 14:07:41 2011 +0100
@@ -33,32 +33,39 @@
 % subplot(1,2,2); imagesc(SMALL.Problem.imageSrc/SMALL.Problem.maxval);
 % title('Dictionary image:');colormap(gray);axis off; axis image;
 time=0;
+error2=0.001^2;
 coeffFrames = zeros(SMALL.Problem.p, SMALL.Problem.n);
 
 for i=1:SMALL.Problem.n
     
     idx = find(SMALL.Problem.M(:,i));
-    SMALL.Problem.A  = SMALL.Problem.B(idx,:);
+    if size(idx,1)==SMALL.Problem.m
+        continue
+    end
+    Dict = SMALL.Problem.B(idx,:);
+    wDict = 1./sqrt(diag(Dict'*Dict));
+    
+    SMALL.Problem.A  = Dict*diag(wDict);
     
     SMALL.Problem.b1 = SMALL.Problem.b(idx,i);
     
-   
+    
     
     %   Defining the parameters sparse representation
     SMALL.solver=SMALL_init_solver;
     SMALL.solver.toolbox='ompbox';
-    SMALL.solver.name='omp2';
+    SMALL.solver.name='omp2Gabor';
     
     SMALL.solver.param=struct(...
-        'epsilon', 0.001,...
-        'maxatoms', 64); 
+        'epsilon', error2*size(idx,1),...
+        'maxatoms', 128); 
     
     % Find solution
     
     SMALL.solver=SMALL_solve(SMALL.Problem, SMALL.solver);
     
     
-    coeffFrames(:,i) = SMALL.solver.solution;
+    coeffFrames(:,i) = wDict .* SMALL.solver.solution;
     time = time + SMALL.solver.time;
     
     
@@ -70,10 +77,32 @@
 SMALL.Problem.reconstruct=@(x) AudioDeclipping_reconstruct(x, SMALL.Problem);
 reconstructed=SMALL.Problem.reconstruct(coeffFrames);
 
-%%  plot time and psnr given dictionary size %%
-figure('Name', 'time and psnr');
 
-subplot(1,2,1); plot(dictsize(1,:), time(1,:), 'ro-');
-title('Time vs number of source image patches used');
-subplot(1,2,2); plot(dictsize(1,:), psnr(1,:), 'b*-');
-title('PSNR vs number of source image patches used');
\ No newline at end of file
+
+%% Plot results
+
+xClipped = SMALL.Problem.clipped;
+xClean   = SMALL.Problem.original;
+xEst1    = reconstructed.audioAllSamples;
+xEst2    = reconstructed.audioOnlyClipped;
+fs       = SMALL.Problem.fs;
+
+figure
+hold on
+plot(xClipped,'r')
+plot(xClean)
+plot(xEst2,'--g')
+plot([1;length(xClipped)],[1;1]*[-1,1]*max(abs(xClipped)),':r')
+legend('Clipped','True solution','Estimate')
+
+% Normalized and save sounds
+normX = 1.1*max(abs([xEst1(:);xEst2(:);xClean(:)]));
+L = min([length(xEst2),length(xEst1),length(xClean),length(xEst1),length(xClipped)]);
+xEst1 = xEst1(1:L)/normX;
+xEst2 = xEst2(1:L)/normX;
+xClipped = xClipped(1:L)/normX;
+xClean = xClean(1:L)/normX;
+wavwrite(xEst1,fs,[expParam.destDir 'xEst1.wav']);
+wavwrite(xEst2,fs,[expParam.destDir 'xEst2.wav']);
+wavwrite(xClipped,fs,[expParam.destDir 'xClipped.wav']);
+wavwrite(xClean,fs,[expParam.destDir 'xClean.wav']);