danieleb@156
|
1 clear
|
danieleb@156
|
2
|
danieleb@156
|
3 %% Parameteres
|
danieleb@156
|
4
|
danieleb@156
|
5 % Dictionary learning parameters
|
danieleb@156
|
6 toolbox = 'TwoStepDL'; %dictionary learning toolbox
|
danieleb@156
|
7 dicUpdate = {'ksvd','mailhe'}; %dictionary updates
|
danieleb@156
|
8 iterNum = 20; %number of iterations
|
danieleb@156
|
9
|
danieleb@156
|
10 % Test signal parameters
|
danieleb@156
|
11 signal = audio('music03_16kHz.wav'); %audio signal
|
danieleb@156
|
12 blockSize = 256; %size of audio frames
|
danieleb@156
|
13 dictSize = 512; %number of atoms in the dictionary
|
danieleb@156
|
14 overlap = 0.5; %overlap between consecutive frames
|
danieleb@156
|
15 sigma = 1e6; %snr of noise (set to be negligible so that the problem becomes approximation rather than denoising)
|
danieleb@156
|
16 percActiveAtoms = 5; %percentage of active atoms
|
danieleb@156
|
17
|
danieleb@156
|
18 % Dependent parameters
|
danieleb@156
|
19 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms
|
danieleb@156
|
20 epsilon = 1/sigma; %error constraint for sparse representation step (corresponds to noise applied to signals)
|
daniele@169
|
21 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %target coherence (based on coherence lower bound)
|
daniele@169
|
22 minCoherence = [0.1:0.1:1];
|
danieleb@156
|
23
|
danieleb@156
|
24 % Initial dictionaries
|
danieleb@156
|
25 dctDict = dictionary('dct',blockSize,dictSize);
|
danieleb@156
|
26 dctDict = dctDict.phi;
|
danieleb@156
|
27 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin);
|
danieleb@156
|
28 gaborDict = Gabor_Dictionary(gaborParam);
|
danieleb@156
|
29
|
danieleb@156
|
30 %% Generate audio denoising problem with low noise (audio representation)
|
danieleb@156
|
31 SMALL.Problem = generateAudioDenoiseProblem(signal.s,[],blockSize,...
|
daniele@169
|
32 dictSize,overlap,sigma); % generate representation problem
|
danieleb@156
|
33 SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions)
|
danieleb@156
|
34
|
danieleb@156
|
35 % omp2 sparse representation solver
|
danieleb@156
|
36 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters
|
danieleb@156
|
37 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure
|
danieleb@156
|
38
|
danieleb@156
|
39
|
daniele@169
|
40 %% Test
|
danieleb@156
|
41 name = dicUpdate{1}; %use ksvd update
|
daniele@169
|
42 SMALL.DL(1:36) = SMALL_init_DL(toolbox,name); %create dictionary learning structures
|
danieleb@156
|
43
|
danieleb@156
|
44 % learn with random initialisation and no decorrelation
|
danieleb@156
|
45 SMALL.DL(1).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
46 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
47 'decFcn','none'); %parameters for the dictionary learning
|
danieleb@156
|
48 SMALL.DL(1) = SMALL_learn(SMALL.Problem,SMALL.DL(1)); %learn dictionary
|
daniele@169
|
49 %save('SMALL','SMALL');
|
danieleb@156
|
50
|
danieleb@156
|
51 % learn with random initialisation and mailhe decorrelation
|
daniele@169
|
52 for iMu=1:10
|
daniele@169
|
53 SMALL.DL(1+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
54 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
55 'decFcn','mailhe','coherence',minCoherence(iMu)); %parameters for the dictionary learning
|
daniele@169
|
56 SMALL.DL(1+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(1+iMu)); %learn dictionary
|
daniele@169
|
57 %save('SMALL','SMALL');
|
daniele@169
|
58 end
|
danieleb@156
|
59
|
danieleb@156
|
60 % learn with random initialisation and tropp decorrelation
|
danieleb@156
|
61 SMALL.DL(12).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
62 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
63 'decFcn','tropp','coherence',minCoherence); %parameters for the dictionary learning
|
danieleb@156
|
64 SMALL.DL(12) = SMALL_learn(SMALL.Problem,SMALL.DL(12)); %learn dictionary
|
danieleb@156
|
65
|
danieleb@156
|
66 % Learn with dct initialisation and no decorrelation
|
danieleb@156
|
67 SMALL.DL(13).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
68 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
69 'decFcn','none','initdict',dctDict); %parameters for the dictionary learning
|
danieleb@156
|
70 SMALL.DL(13) = SMALL_learn(SMALL.Problem,SMALL.DL(13)); %learn dictionary
|
danieleb@156
|
71
|
danieleb@156
|
72 % learn with dct initialisation and mailhe decorrelation
|
daniele@169
|
73 for iMu=1:10
|
daniele@169
|
74 SMALL.DL(13+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
75 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
76 'decFcn','mailhe','coherence',minCoherence(iMu),'initdict',dctDict); %parameters for the dictionary learning
|
daniele@169
|
77 SMALL.DL(13+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(13+iMu)); %learn dictionary
|
daniele@169
|
78 %save('SMALL','SMALL');
|
daniele@169
|
79 end
|
danieleb@156
|
80
|
danieleb@156
|
81 % learn with dct initialisation and tropp decorrelation
|
daniele@169
|
82 SMALL.DL(24).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
83 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
84 'decFcn','tropp','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning
|
daniele@169
|
85 SMALL.DL(24) = SMALL_learn(SMALL.Problem,SMALL.DL(24)); %learn dictionary
|
daniele@169
|
86
|
danieleb@156
|
87
|
danieleb@156
|
88 % Learn with gabor initialisation and no decorrelation
|
daniele@169
|
89 SMALL.DL(25).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
90 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
91 'decFcn','none','initdict',gaborDict); %parameters for the dictionary learning
|
daniele@169
|
92 SMALL.DL(25) = SMALL_learn(SMALL.Problem,SMALL.DL(25)); %learn dictionary
|
danieleb@156
|
93
|
danieleb@156
|
94 % learn with gabor initialisation and mailhe decorrelation
|
daniele@169
|
95 for iMu=1:10
|
daniele@169
|
96 SMALL.DL(25+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
97 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
98 'decFcn','mailhe','coherence',minCoherence(iMu),'initdict',gaborDict); %parameters for the dictionary learning
|
daniele@169
|
99 SMALL.DL(25+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(25+iMu)); %learn dictionary
|
daniele@169
|
100 %save('SMALL','SMALL');
|
daniele@169
|
101 end
|
danieleb@156
|
102
|
danieleb@156
|
103 % learn with gabor initialisation and tropp decorrelation
|
daniele@169
|
104 SMALL.DL(36).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
|
daniele@169
|
105 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
|
daniele@169
|
106 'decFcn','tropp','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning
|
daniele@169
|
107 SMALL.DL(36) = SMALL_learn(SMALL.Problem,SMALL.DL(36)); %learn dictionary
|
danieleb@156
|
108
|
danieleb@156
|
109 %% Evaluate coherence and snr of representation for the various methods
|
daniele@169
|
110 sigNoiseRatio = zeros(36,1);
|
daniele@169
|
111 mu = zeros(36,1);
|
daniele@169
|
112 for i=1:36
|
daniele@169
|
113 SMALL.Problem.A = SMALL.DL(i).D;
|
daniele@169
|
114 tempSolver = SMALL_solve(SMALL.Problem,solver);
|
daniele@169
|
115 sigNoiseRatio(i) = snr(SMALL.Problem.b,SMALL.DL(i).D*tempSolver.solution);
|
daniele@169
|
116 dic(i) = dictionary(SMALL.DL(i).D);
|
daniele@169
|
117 mu(i) = dic(i).coherence;
|
danieleb@156
|
118 end
|
danieleb@156
|
119
|
danieleb@156
|
120 %% Plot results
|
danieleb@156
|
121 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1)));
|
danieleb@156
|
122
|
daniele@169
|
123 figure,
|
daniele@169
|
124 %subplot(3,1,1)
|
daniele@169
|
125 hold on, grid on
|
daniele@169
|
126 title('Data Initialisation')
|
daniele@169
|
127 plot([1 1],[0 25],'k-');
|
daniele@169
|
128 plot(mu(1),sigNoiseRatio(1),'ks');
|
daniele@169
|
129 plot(mu(12),sigNoiseRatio(12),'kd');
|
daniele@169
|
130 plot(mu(2:11),sigNoiseRatio(2:11),'k*-');
|
daniele@169
|
131 plot([minMu minMu],[0 25],'k--')
|
daniele@169
|
132 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
|
daniele@169
|
133 legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'});
|
daniele@169
|
134 xlabel('\mu');
|
daniele@169
|
135 ylabel('SNR (dB)');
|
danieleb@156
|
136
|
daniele@169
|
137 figure
|
daniele@169
|
138 %subplot(3,1,2)
|
daniele@169
|
139 hold on, grid on
|
daniele@169
|
140 title('DCT Initialisation')
|
daniele@169
|
141 plot([1 1],[0 25],'k-');
|
daniele@169
|
142 plot(mu(13),sigNoiseRatio(13),'ks');
|
daniele@169
|
143 plot(mu(24),sigNoiseRatio(24),'kd');
|
daniele@169
|
144 plot(mu(14:23),sigNoiseRatio(14:23),'k*-');
|
daniele@169
|
145 plot([minMu minMu],[0 25],'k--')
|
daniele@169
|
146 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
|
daniele@169
|
147 legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'});
|
daniele@169
|
148 xlabel('\mu');
|
daniele@169
|
149 ylabel('SNR (dB)');
|
daniele@169
|
150
|
daniele@169
|
151 figure
|
daniele@169
|
152 %subplot(3,1,3)
|
daniele@169
|
153 hold on, grid on
|
daniele@169
|
154 title('Gabor Initialisation')
|
daniele@169
|
155 plot([1 1],[0 25],'k-');
|
daniele@169
|
156 plot(mu(25),sigNoiseRatio(25),'ks');
|
daniele@169
|
157 plot(mu(36),sigNoiseRatio(36),'kd');
|
daniele@169
|
158 plot(mu(26:35),sigNoiseRatio(26:35),'k*-');
|
daniele@169
|
159 plot([minMu minMu],[0 25],'k--')
|
daniele@169
|
160 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
|
daniele@169
|
161 legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'});
|
daniele@169
|
162 xlabel('\mu');
|
daniele@169
|
163 ylabel('SNR (dB)');
|
daniele@169
|
164
|
daniele@169
|
165 % minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1)));
|
daniele@169
|
166 % maxSNR = max(sigNoiseRatio);
|
daniele@169
|
167 %
|
daniele@169
|
168 % figure, subplot(2,2,1)
|
daniele@169
|
169 % snrMat = buffer(sigNoiseRatio(1:9),3);
|
daniele@169
|
170 % bar(snrMat');
|
daniele@169
|
171 % title('Signal to noise ratio')
|
daniele@169
|
172 % xlabel('Initial dictionary')
|
daniele@169
|
173 % ylabel('SNR (dB)')
|
daniele@169
|
174 % set(gca,'XTickLabel',{'data','dct','gabor'});
|
daniele@169
|
175 % legend('none','Mailhe','Tropp')
|
daniele@169
|
176 % grid on
|
daniele@169
|
177 %
|
daniele@167
|
178 % subplot(2,2,2), grid on
|
daniele@167
|
179 % snrMat = buffer(sigNoiseRatio(10:18),3);
|
daniele@167
|
180 % bar(snrMat');
|
daniele@167
|
181 % title('SNR - Mailhe Update')
|
daniele@167
|
182 % xlabel('Initial dictionary')
|
daniele@167
|
183 % ylabel('SNR (dB)')
|
daniele@167
|
184 % set(gca,'XTickLabel',{'data','dct','gabor'},'YLim',[0 maxSNR+1]);
|
daniele@167
|
185 % legend('none','Mailhe','Tropp')
|
daniele@167
|
186 % grid on
|
daniele@169
|
187 %
|
daniele@169
|
188 % subplot(2,2,3), hold on, grid on
|
daniele@169
|
189 % title('Coherence')
|
daniele@169
|
190 % muMat = buffer(mu(1:9),3);
|
daniele@169
|
191 % line([0.5 3.5],[1 1],'Color','r');
|
daniele@169
|
192 % bar(muMat');
|
daniele@169
|
193 % line([0.5 3.5],[minMu minMu],'Color','k');
|
daniele@169
|
194 % set(gca,'XTick',1:3,'XTickLabel',{'data','dct','gabor'},'YLim',[0 1.05])
|
daniele@169
|
195 % legend('\mu_{max}','none','Mailhe','Tropp','\mu_{min}')
|
daniele@169
|
196 % ylabel('\mu')
|
daniele@169
|
197 % xlabel('Initial dictionary')
|
daniele@169
|
198 %
|
daniele@167
|
199 % subplot(2,2,4), hold on, grid on
|
daniele@167
|
200 % title('Coherence - Mailhe Update')
|
daniele@167
|
201 % muMat = buffer(mu(10:18),3);
|
daniele@167
|
202 % line([0.5 3.5],[1 1],'Color','r');
|
daniele@167
|
203 % bar(muMat');
|
daniele@167
|
204 % line([0.5 3.5],[minMu minMu],'Color','k');
|
daniele@167
|
205 % set(gca,'XTick',1:3,'XTickLabel',{'data','dct','gabor'},'YLim',[0 1.05])
|
daniele@167
|
206 % legend('\mu_{max}','none','Mailhe','Tropp','\mu_{min}')
|
daniele@167
|
207 % ylabel('\mu')
|
daniele@167
|
208 % xlabel('Initial dictionary')
|