comparison examples/SMALL_test_coherence2.m @ 169:290cca7d3469 danieleb

Added dictionary decorrelation functions and test script for ICASSP paper.
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Thu, 29 Sep 2011 09:46:52 +0100
parents
children 68fb71aa5339
comparison
equal deleted inserted replaced
168:ff866a412be5 169:290cca7d3469
1 clc, clear, close all
2
3 %% Parameteres
4 % Dictionary learning parameters
5 toolbox = 'TwoStepDL'; %dictionary learning toolbox
6 dicUpdate = {'ksvd'}; %dictionary learning updates
7 dicDecorr = {'none','mailhe','tropp','barchiesi'}; %dictionary decorrelation methods
8 minCoherence = linspace(0.1,1,1); %coherence levels
9 minCoherence = 0.4;
10 %dicDecorr = {'barchiesi'};
11
12 iterNum = 20; %number of iterations
13 epsilon = 1e-6; %tolerance level
14 dictSize = 512; %number of atoms in the dictionary
15 percActiveAtoms = 5; %percentage of active atoms
16
17 % Test signal parameters
18 signal = audio('music03_16kHz.wav'); %audio signal
19 blockSize = 256; %size of audio frames
20 overlap = 0.5; %overlap between consecutive frames
21
22
23 % Dependent parameters
24 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms
25
26 % Initial dictionaries
27 dctDict = dictionary('dct',blockSize,dictSize);
28 dctDict = dctDict.phi;
29 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin);
30 gaborDict = Gabor_Dictionary(gaborParam);
31 initDicts = {[],dctDict,gaborDict};
32 initDicts = {[]};
33
34 %% Generate audio approximation problem
35 signal = buffer(signal,blockSize,blockSize*overlap,@rectwin);
36 SMALL.Problem.b = signal.S;
37 SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions)
38
39 % omp2 sparse representation solver
40 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters
41 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure
42
43
44 %% Test
45 nDicUpdates = length(dicUpdate); %number of dictionary updates
46 nDecorrAlgs = length(dicDecorr); %number of decorrelation algorithms
47 nCorrLevels = length(minCoherence); %number of coherence levels
48 nInitDicts = length(initDicts); %number of initial dictionaries
49
50 SMALL.DL(nInitDicts,nCorrLevels,nDecorrAlgs,nDicUpdates) = SMALL_init_DL(toolbox); %create dictionary learning structures
51 for iInitDicts=1:nInitDicts
52 for iCorrLevels=1:nCorrLevels
53 for iDecorrAlgs=1:nDecorrAlgs
54 for iDicUpdates=1:nDicUpdates
55 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).toolbox = toolbox;
56 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).name = dicUpdate{iDicUpdates};
57 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).profile = true;
58 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).param = ...
59 struct( 'data',SMALL.Problem.b,...
60 'Tdata',nActiveAtoms,...
61 'dictsize',dictSize,...
62 'iternum',iterNum,...
63 'memusage','high',...
64 'solver',solver,...
65 'decFcn',dicDecorr{iDecorrAlgs},...
66 'coherence',minCoherence(iCorrLevels),...
67 'initdict',initDicts(iInitDicts));
68
69 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ...
70 SMALL_learn(SMALL.Problem,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates));
71 end
72 end
73 end
74 end
75
76 %% Evaluate coherence and snr of representation for the various methods
77 sr = zeros(size(SMALL.DL)); %signal to noise ratio
78 mu = zeros(size(SMALL.DL)); %coherence
79 dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects
80 for iInitDict=1:nInitDicts
81 for iCorrLevels=1:nCorrLevels
82 for iDecorrAlgs=1:nDecorrAlgs
83 for iDicUpdates=1:nDicUpdates
84 %Sparse representation
85 SMALL.Problem.A = SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D;
86 tempSolver = SMALL_solve(SMALL.Problem,solver);
87 %calculate snr
88 sr(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ...
89 snr(SMALL.Problem.b,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D*tempSolver.solution);
90 %calculate mu
91 dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ...
92 dictionary(SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D);
93 mu(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ...
94 dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).coherence;
95 end
96 end
97 end
98 end
99
100 %% Plot results
101 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence
102 initDictsNames = {'Data','DCT','Gabor'};
103 dicDecorrNames = {'K-SVD','INK-SVD','Grassmannian','New'};
104 lineStyles = {'ks-','kd-','ko-','k*-'};
105 for iInitDict=1:nInitDicts
106 figure, hold on, grid on
107 title([initDictsNames{iInitDict} ' Initialisation']);
108 plot([1 1],[0 25],'k-');
109 for iDecorrAlgs=1:nDecorrAlgs
110 plot(mu(iInitDicts,:,iDecorrAlgs,1),sr(iInitDicts,:,iDecorrAlgs,1),...
111 lineStyles{iDecorrAlgs});
112 end
113 plot([minMu minMu],[0 25],'k--')
114
115 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
116 legend([{'\mu_{max}'},dicDecorrNames,{'\mu_{min}'}]);
117 xlabel('\mu');
118 ylabel('SNR (dB)');
119 end