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