daniele@183
|
1 %
|
daniele@183
|
2 %
|
daniele@183
|
3 %
|
daniele@183
|
4
|
daniele@169
|
5 clc, clear, close all
|
daniele@169
|
6
|
daniele@169
|
7 %% Parameteres
|
daniele@170
|
8 nTrials = 10; %number of trials of the experiment
|
daniele@170
|
9
|
daniele@169
|
10 % Dictionary learning parameters
|
daniele@169
|
11 toolbox = 'TwoStepDL'; %dictionary learning toolbox
|
daniele@170
|
12 dicUpdate = 'ksvd'; %dictionary learning updates
|
daniele@170
|
13 dicDecorr = {'iterproj','ink-svd','shrinkgram'}; %dictionary decorrelation methods
|
daniele@170
|
14 minCoherence = linspace(0.1,1,10); %coherence levels
|
daniele@169
|
15
|
daniele@169
|
16 iterNum = 20; %number of iterations
|
daniele@169
|
17 epsilon = 1e-6; %tolerance level
|
daniele@169
|
18 dictSize = 512; %number of atoms in the dictionary
|
daniele@169
|
19 percActiveAtoms = 5; %percentage of active atoms
|
daniele@169
|
20
|
daniele@169
|
21 % Test signal parameters
|
daniele@169
|
22 signal = audio('music03_16kHz.wav'); %audio signal
|
daniele@169
|
23 blockSize = 256; %size of audio frames
|
daniele@169
|
24 overlap = 0.5; %overlap between consecutive frames
|
daniele@169
|
25
|
daniele@169
|
26 % Dependent parameters
|
daniele@169
|
27 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms
|
daniele@169
|
28
|
daniele@169
|
29 % Initial dictionaries
|
daniele@169
|
30 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin);
|
daniele@169
|
31 gaborDict = Gabor_Dictionary(gaborParam);
|
daniele@170
|
32 initDicts = {[],gaborDict};
|
daniele@169
|
33
|
daniele@169
|
34 %% Generate audio approximation problem
|
daniele@170
|
35 signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); %buffer frames of audio into columns of the matrix S
|
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 nDecorrAlgs = length(dicDecorr); %number of decorrelation algorithms
|
daniele@169
|
46 nCorrLevels = length(minCoherence); %number of coherence levels
|
daniele@169
|
47 nInitDicts = length(initDicts); %number of initial dictionaries
|
daniele@169
|
48
|
daniele@170
|
49 SMALL.DL(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs) = SMALL_init_DL(toolbox); %create dictionary learning structures
|
daniele@170
|
50 for iTrial=1:nTrials
|
daniele@170
|
51 for iInitDicts=1:nInitDicts
|
daniele@170
|
52 for iCorrLevels=1:nCorrLevels
|
daniele@170
|
53 for iDecorrAlgs=1:nDecorrAlgs
|
daniele@170
|
54 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).toolbox = toolbox;
|
daniele@170
|
55 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).name = dicUpdate;
|
daniele@170
|
56 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).profile = true;
|
daniele@170
|
57 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).param = ...
|
daniele@169
|
58 struct( 'data',SMALL.Problem.b,...
|
daniele@169
|
59 'Tdata',nActiveAtoms,...
|
daniele@169
|
60 'dictsize',dictSize,...
|
daniele@169
|
61 'iternum',iterNum,...
|
daniele@169
|
62 'memusage','high',...
|
daniele@169
|
63 'solver',solver,...
|
daniele@169
|
64 'decFcn',dicDecorr{iDecorrAlgs},...
|
daniele@169
|
65 'coherence',minCoherence(iCorrLevels),...
|
daniele@169
|
66 'initdict',initDicts(iInitDicts));
|
daniele@169
|
67
|
daniele@170
|
68 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ...
|
daniele@170
|
69 SMALL_learn(SMALL.Problem,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs));
|
daniele@170
|
70 save('SMALL_DL','SMALL');
|
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@183
|
78 mu1 = zeros(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs,blockSize); %cumulative coherence
|
daniele@183
|
79 mu2 = zeros(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs,blockSize); %cumulative coherence
|
daniele@169
|
80 dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects
|
daniele@170
|
81 for iTrial=1:nTrials
|
daniele@170
|
82 for iInitDicts=1:nInitDicts
|
daniele@170
|
83 for iCorrLevels=1:nCorrLevels
|
daniele@170
|
84 for iDecorrAlgs=1:nDecorrAlgs
|
daniele@169
|
85 %Sparse representation
|
daniele@170
|
86 SMALL.Problem.A = SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D;
|
daniele@169
|
87 tempSolver = SMALL_solve(SMALL.Problem,solver);
|
daniele@169
|
88 %calculate snr
|
daniele@170
|
89 sr(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ...
|
daniele@170
|
90 snr(SMALL.Problem.b,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D*tempSolver.solution);
|
daniele@169
|
91 %calculate mu
|
daniele@170
|
92 dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ...
|
daniele@170
|
93 dictionary(SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D);
|
daniele@183
|
94 mu1(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,:) = ...
|
daniele@170
|
95 dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).cumcoherence;
|
daniele@183
|
96 mu2(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,:) = ...
|
daniele@183
|
97 dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).cumcoherence(2);
|
daniele@169
|
98 end
|
daniele@169
|
99 end
|
daniele@169
|
100 end
|
daniele@169
|
101 end
|
daniele@169
|
102
|
daniele@169
|
103 %% Plot results
|
daniele@169
|
104 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence
|
daniele@170
|
105 initDictsNames = {'Data','Gabor'};
|
daniele@183
|
106 dicDecorrNames = {'IPR','INK-SVD'};
|
daniele@174
|
107 lineStyles = {'k.-','r*-','b+-'};
|
daniele@169
|
108 for iInitDict=1:nInitDicts
|
daniele@169
|
109 figure, hold on, grid on
|
daniele@169
|
110 title([initDictsNames{iInitDict} ' Initialisation']);
|
daniele@169
|
111 plot([1 1],[0 25],'k-');
|
daniele@183
|
112 for iDecorrAlgs=1:nDecorrAlgs-1
|
daniele@174
|
113 coherenceLevels = squeeze(mean(mu(:,iInitDict,:,iDecorrAlgs,1),1));
|
daniele@174
|
114 meanSNRs = squeeze(mean(sr(:,iInitDict,:,iDecorrAlgs),1));
|
daniele@174
|
115 stdSNRs = squeeze(std(sr(:,iInitDict,:,iDecorrAlgs),0,1));
|
daniele@174
|
116 errorbar(coherenceLevels,meanSNRs,stdSNRs,lineStyles{iDecorrAlgs});
|
daniele@169
|
117 end
|
daniele@169
|
118 plot([minMu minMu],[0 25],'k--')
|
daniele@169
|
119
|
daniele@169
|
120 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
|
daniele@169
|
121 legend([{'\mu_{max}'},dicDecorrNames,{'\mu_{min}'}]);
|
daniele@169
|
122 xlabel('\mu');
|
daniele@169
|
123 ylabel('SNR (dB)');
|
daniele@169
|
124 end
|
daniele@183
|
125
|
daniele@183
|
126 %%
|
daniele@183
|
127 mu2 = squeeze(mean(mu2,1));
|
daniele@183
|
128 mu = squeeze(mean(mu,1));
|