danieleb@156: clear danieleb@156: danieleb@156: %% Parameteres danieleb@156: danieleb@156: % Dictionary learning parameters danieleb@156: toolbox = 'TwoStepDL'; %dictionary learning toolbox danieleb@156: dicUpdate = {'ksvd','mailhe'}; %dictionary updates danieleb@156: iterNum = 20; %number of iterations danieleb@156: danieleb@156: % Test signal parameters danieleb@156: signal = audio('music03_16kHz.wav'); %audio signal danieleb@156: blockSize = 256; %size of audio frames danieleb@156: dictSize = 512; %number of atoms in the dictionary danieleb@156: overlap = 0.5; %overlap between consecutive frames danieleb@156: sigma = 1e6; %snr of noise (set to be negligible so that the problem becomes approximation rather than denoising) danieleb@156: percActiveAtoms = 5; %percentage of active atoms danieleb@156: danieleb@156: % Dependent parameters danieleb@156: nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms danieleb@156: epsilon = 1/sigma; %error constraint for sparse representation step (corresponds to noise applied to signals) daniele@169: minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %target coherence (based on coherence lower bound) daniele@169: minCoherence = [0.1:0.1:1]; danieleb@156: danieleb@156: % Initial dictionaries danieleb@156: dctDict = dictionary('dct',blockSize,dictSize); danieleb@156: dctDict = dctDict.phi; danieleb@156: gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); danieleb@156: gaborDict = Gabor_Dictionary(gaborParam); danieleb@156: danieleb@156: %% Generate audio denoising problem with low noise (audio representation) danieleb@156: SMALL.Problem = generateAudioDenoiseProblem(signal.s,[],blockSize,... daniele@169: dictSize,overlap,sigma); % generate representation problem danieleb@156: SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions) danieleb@156: danieleb@156: % omp2 sparse representation solver danieleb@156: ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters danieleb@156: solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure danieleb@156: danieleb@156: daniele@169: %% Test danieleb@156: name = dicUpdate{1}; %use ksvd update daniele@169: SMALL.DL(1:36) = SMALL_init_DL(toolbox,name); %create dictionary learning structures danieleb@156: danieleb@156: % learn with random initialisation and no decorrelation danieleb@156: SMALL.DL(1).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','none'); %parameters for the dictionary learning danieleb@156: SMALL.DL(1) = SMALL_learn(SMALL.Problem,SMALL.DL(1)); %learn dictionary daniele@169: %save('SMALL','SMALL'); danieleb@156: danieleb@156: % learn with random initialisation and mailhe decorrelation daniele@169: for iMu=1:10 daniele@169: SMALL.DL(1+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','mailhe','coherence',minCoherence(iMu)); %parameters for the dictionary learning daniele@169: SMALL.DL(1+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(1+iMu)); %learn dictionary daniele@169: %save('SMALL','SMALL'); daniele@169: end danieleb@156: danieleb@156: % learn with random initialisation and tropp decorrelation danieleb@156: SMALL.DL(12).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','tropp','coherence',minCoherence); %parameters for the dictionary learning danieleb@156: SMALL.DL(12) = SMALL_learn(SMALL.Problem,SMALL.DL(12)); %learn dictionary danieleb@156: danieleb@156: % Learn with dct initialisation and no decorrelation danieleb@156: SMALL.DL(13).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','none','initdict',dctDict); %parameters for the dictionary learning danieleb@156: SMALL.DL(13) = SMALL_learn(SMALL.Problem,SMALL.DL(13)); %learn dictionary danieleb@156: danieleb@156: % learn with dct initialisation and mailhe decorrelation daniele@169: for iMu=1:10 daniele@169: SMALL.DL(13+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','mailhe','coherence',minCoherence(iMu),'initdict',dctDict); %parameters for the dictionary learning daniele@169: SMALL.DL(13+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(13+iMu)); %learn dictionary daniele@169: %save('SMALL','SMALL'); daniele@169: end danieleb@156: danieleb@156: % learn with dct initialisation and tropp decorrelation daniele@169: SMALL.DL(24).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','tropp','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning daniele@169: SMALL.DL(24) = SMALL_learn(SMALL.Problem,SMALL.DL(24)); %learn dictionary daniele@169: danieleb@156: danieleb@156: % Learn with gabor initialisation and no decorrelation daniele@169: SMALL.DL(25).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','none','initdict',gaborDict); %parameters for the dictionary learning daniele@169: SMALL.DL(25) = SMALL_learn(SMALL.Problem,SMALL.DL(25)); %learn dictionary danieleb@156: danieleb@156: % learn with gabor initialisation and mailhe decorrelation daniele@169: for iMu=1:10 daniele@169: SMALL.DL(25+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','mailhe','coherence',minCoherence(iMu),'initdict',gaborDict); %parameters for the dictionary learning daniele@169: SMALL.DL(25+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(25+iMu)); %learn dictionary daniele@169: %save('SMALL','SMALL'); daniele@169: end danieleb@156: danieleb@156: % learn with gabor initialisation and tropp decorrelation daniele@169: SMALL.DL(36).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... daniele@169: 'decFcn','tropp','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning daniele@169: SMALL.DL(36) = SMALL_learn(SMALL.Problem,SMALL.DL(36)); %learn dictionary danieleb@156: danieleb@156: %% Evaluate coherence and snr of representation for the various methods daniele@169: sigNoiseRatio = zeros(36,1); daniele@169: mu = zeros(36,1); daniele@169: for i=1:36 daniele@169: SMALL.Problem.A = SMALL.DL(i).D; daniele@169: tempSolver = SMALL_solve(SMALL.Problem,solver); daniele@169: sigNoiseRatio(i) = snr(SMALL.Problem.b,SMALL.DL(i).D*tempSolver.solution); daniele@169: dic(i) = dictionary(SMALL.DL(i).D); daniele@169: mu(i) = dic(i).coherence; danieleb@156: end danieleb@156: danieleb@156: %% Plot results danieleb@156: minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); danieleb@156: daniele@169: figure, daniele@169: %subplot(3,1,1) daniele@169: hold on, grid on daniele@169: title('Data Initialisation') daniele@169: plot([1 1],[0 25],'k-'); daniele@169: plot(mu(1),sigNoiseRatio(1),'ks'); daniele@169: plot(mu(12),sigNoiseRatio(12),'kd'); daniele@169: plot(mu(2:11),sigNoiseRatio(2:11),'k*-'); daniele@169: plot([minMu minMu],[0 25],'k--') daniele@169: set(gca,'YLim',[0 25],'XLim',[0 1.4]); daniele@169: legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'}); daniele@169: xlabel('\mu'); daniele@169: ylabel('SNR (dB)'); danieleb@156: daniele@169: figure daniele@169: %subplot(3,1,2) daniele@169: hold on, grid on daniele@169: title('DCT Initialisation') daniele@169: plot([1 1],[0 25],'k-'); daniele@169: plot(mu(13),sigNoiseRatio(13),'ks'); daniele@169: plot(mu(24),sigNoiseRatio(24),'kd'); daniele@169: plot(mu(14:23),sigNoiseRatio(14:23),'k*-'); daniele@169: plot([minMu minMu],[0 25],'k--') daniele@169: set(gca,'YLim',[0 25],'XLim',[0 1.4]); daniele@169: legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'}); daniele@169: xlabel('\mu'); daniele@169: ylabel('SNR (dB)'); daniele@169: daniele@169: figure daniele@169: %subplot(3,1,3) daniele@169: hold on, grid on daniele@169: title('Gabor Initialisation') daniele@169: plot([1 1],[0 25],'k-'); daniele@169: plot(mu(25),sigNoiseRatio(25),'ks'); daniele@169: plot(mu(36),sigNoiseRatio(36),'kd'); daniele@169: plot(mu(26:35),sigNoiseRatio(26:35),'k*-'); daniele@169: plot([minMu minMu],[0 25],'k--') daniele@169: set(gca,'YLim',[0 25],'XLim',[0 1.4]); daniele@169: legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'}); daniele@169: xlabel('\mu'); daniele@169: ylabel('SNR (dB)'); daniele@169: daniele@169: % minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); daniele@169: % maxSNR = max(sigNoiseRatio); daniele@169: % daniele@169: % figure, subplot(2,2,1) daniele@169: % snrMat = buffer(sigNoiseRatio(1:9),3); daniele@169: % bar(snrMat'); daniele@169: % title('Signal to noise ratio') daniele@169: % xlabel('Initial dictionary') daniele@169: % ylabel('SNR (dB)') daniele@169: % set(gca,'XTickLabel',{'data','dct','gabor'}); daniele@169: % legend('none','Mailhe','Tropp') daniele@169: % grid on daniele@169: % daniele@167: % subplot(2,2,2), grid on daniele@167: % snrMat = buffer(sigNoiseRatio(10:18),3); daniele@167: % bar(snrMat'); daniele@167: % title('SNR - Mailhe Update') daniele@167: % xlabel('Initial dictionary') daniele@167: % ylabel('SNR (dB)') daniele@167: % set(gca,'XTickLabel',{'data','dct','gabor'},'YLim',[0 maxSNR+1]); daniele@167: % legend('none','Mailhe','Tropp') daniele@167: % grid on daniele@169: % daniele@169: % subplot(2,2,3), hold on, grid on daniele@169: % title('Coherence') daniele@169: % muMat = buffer(mu(1:9),3); daniele@169: % line([0.5 3.5],[1 1],'Color','r'); daniele@169: % bar(muMat'); daniele@169: % line([0.5 3.5],[minMu minMu],'Color','k'); daniele@169: % set(gca,'XTick',1:3,'XTickLabel',{'data','dct','gabor'},'YLim',[0 1.05]) daniele@169: % legend('\mu_{max}','none','Mailhe','Tropp','\mu_{min}') daniele@169: % ylabel('\mu') daniele@169: % xlabel('Initial dictionary') daniele@169: % daniele@167: % subplot(2,2,4), hold on, grid on daniele@167: % title('Coherence - Mailhe Update') daniele@167: % muMat = buffer(mu(10:18),3); daniele@167: % line([0.5 3.5],[1 1],'Color','r'); daniele@167: % bar(muMat'); daniele@167: % line([0.5 3.5],[minMu minMu],'Color','k'); daniele@167: % set(gca,'XTick',1:3,'XTickLabel',{'data','dct','gabor'},'YLim',[0 1.05]) daniele@167: % legend('\mu_{max}','none','Mailhe','Tropp','\mu_{min}') daniele@167: % ylabel('\mu') daniele@167: % xlabel('Initial dictionary')