daniele@183: % daniele@183: % daniele@183: % daniele@183: daniele@169: clc, clear, close all daniele@169: daniele@169: %% Parameteres daniele@170: nTrials = 10; %number of trials of the experiment daniele@170: daniele@169: % Dictionary learning parameters daniele@169: toolbox = 'TwoStepDL'; %dictionary learning toolbox daniele@170: dicUpdate = 'ksvd'; %dictionary learning updates daniele@170: dicDecorr = {'iterproj','ink-svd','shrinkgram'}; %dictionary decorrelation methods daniele@170: minCoherence = linspace(0.1,1,10); %coherence levels daniele@169: daniele@169: iterNum = 20; %number of iterations daniele@169: epsilon = 1e-6; %tolerance level daniele@169: dictSize = 512; %number of atoms in the dictionary daniele@169: percActiveAtoms = 5; %percentage of active atoms daniele@169: daniele@169: % Test signal parameters daniele@169: signal = audio('music03_16kHz.wav'); %audio signal daniele@169: blockSize = 256; %size of audio frames daniele@169: overlap = 0.5; %overlap between consecutive frames daniele@169: daniele@169: % Dependent parameters daniele@169: nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms daniele@169: daniele@169: % Initial dictionaries daniele@169: gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); daniele@169: gaborDict = Gabor_Dictionary(gaborParam); daniele@170: initDicts = {[],gaborDict}; daniele@169: daniele@169: %% Generate audio approximation problem daniele@170: signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); %buffer frames of audio into columns of the matrix S daniele@169: SMALL.Problem.b = signal.S; daniele@169: SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions) daniele@169: daniele@169: % omp2 sparse representation solver daniele@169: ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters daniele@169: solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure daniele@169: daniele@169: daniele@169: %% Test daniele@169: nDecorrAlgs = length(dicDecorr); %number of decorrelation algorithms daniele@169: nCorrLevels = length(minCoherence); %number of coherence levels daniele@169: nInitDicts = length(initDicts); %number of initial dictionaries daniele@169: daniele@170: SMALL.DL(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs) = SMALL_init_DL(toolbox); %create dictionary learning structures daniele@170: for iTrial=1:nTrials daniele@170: for iInitDicts=1:nInitDicts daniele@170: for iCorrLevels=1:nCorrLevels daniele@170: for iDecorrAlgs=1:nDecorrAlgs daniele@170: SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).toolbox = toolbox; daniele@170: SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).name = dicUpdate; daniele@170: SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).profile = true; daniele@170: SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).param = ... daniele@169: struct( 'data',SMALL.Problem.b,... daniele@169: 'Tdata',nActiveAtoms,... daniele@169: 'dictsize',dictSize,... daniele@169: 'iternum',iterNum,... daniele@169: 'memusage','high',... daniele@169: 'solver',solver,... daniele@169: 'decFcn',dicDecorr{iDecorrAlgs},... daniele@169: 'coherence',minCoherence(iCorrLevels),... daniele@169: 'initdict',initDicts(iInitDicts)); daniele@169: daniele@170: SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ... daniele@170: SMALL_learn(SMALL.Problem,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs)); daniele@170: save('SMALL_DL','SMALL'); daniele@169: end daniele@169: end daniele@169: end daniele@169: end daniele@169: daniele@169: %% Evaluate coherence and snr of representation for the various methods daniele@169: sr = zeros(size(SMALL.DL)); %signal to noise ratio daniele@183: mu1 = zeros(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs,blockSize); %cumulative coherence daniele@183: mu2 = zeros(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs,blockSize); %cumulative coherence daniele@169: dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects daniele@170: for iTrial=1:nTrials daniele@170: for iInitDicts=1:nInitDicts daniele@170: for iCorrLevels=1:nCorrLevels daniele@170: for iDecorrAlgs=1:nDecorrAlgs daniele@169: %Sparse representation daniele@170: SMALL.Problem.A = SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D; daniele@169: tempSolver = SMALL_solve(SMALL.Problem,solver); daniele@169: %calculate snr daniele@170: sr(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ... daniele@170: snr(SMALL.Problem.b,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D*tempSolver.solution); daniele@169: %calculate mu daniele@170: dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ... daniele@170: dictionary(SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D); daniele@183: mu1(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,:) = ... daniele@170: dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).cumcoherence; daniele@183: mu2(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,:) = ... daniele@183: dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).cumcoherence(2); daniele@169: end daniele@169: end daniele@169: end daniele@169: end daniele@169: daniele@169: %% Plot results daniele@169: minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence daniele@170: initDictsNames = {'Data','Gabor'}; daniele@183: dicDecorrNames = {'IPR','INK-SVD'}; daniele@174: lineStyles = {'k.-','r*-','b+-'}; daniele@169: for iInitDict=1:nInitDicts daniele@169: figure, hold on, grid on daniele@169: title([initDictsNames{iInitDict} ' Initialisation']); daniele@169: plot([1 1],[0 25],'k-'); daniele@183: for iDecorrAlgs=1:nDecorrAlgs-1 daniele@174: coherenceLevels = squeeze(mean(mu(:,iInitDict,:,iDecorrAlgs,1),1)); daniele@174: meanSNRs = squeeze(mean(sr(:,iInitDict,:,iDecorrAlgs),1)); daniele@174: stdSNRs = squeeze(std(sr(:,iInitDict,:,iDecorrAlgs),0,1)); daniele@174: errorbar(coherenceLevels,meanSNRs,stdSNRs,lineStyles{iDecorrAlgs}); daniele@169: end daniele@169: plot([minMu minMu],[0 25],'k--') daniele@169: daniele@169: set(gca,'YLim',[0 25],'XLim',[0 1.4]); daniele@169: legend([{'\mu_{max}'},dicDecorrNames,{'\mu_{min}'}]); daniele@169: xlabel('\mu'); daniele@169: ylabel('SNR (dB)'); daniele@169: end daniele@183: daniele@183: %% daniele@183: mu2 = squeeze(mean(mu2,1)); daniele@183: mu = squeeze(mean(mu,1));