daniele@169: clc, clear, close all daniele@169: daniele@169: %% Parameteres daniele@169: % Dictionary learning parameters daniele@169: toolbox = 'TwoStepDL'; %dictionary learning toolbox daniele@169: dicUpdate = {'ksvd'}; %dictionary learning updates daniele@169: dicDecorr = {'none','mailhe','tropp','barchiesi'}; %dictionary decorrelation methods daniele@169: minCoherence = linspace(0.1,1,1); %coherence levels daniele@169: minCoherence = 0.4; daniele@169: %dicDecorr = {'barchiesi'}; 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: daniele@169: % Dependent parameters daniele@169: nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms daniele@169: daniele@169: % Initial dictionaries daniele@169: dctDict = dictionary('dct',blockSize,dictSize); daniele@169: dctDict = dctDict.phi; daniele@169: gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); daniele@169: gaborDict = Gabor_Dictionary(gaborParam); daniele@169: initDicts = {[],dctDict,gaborDict}; daniele@169: initDicts = {[]}; daniele@169: daniele@169: %% Generate audio approximation problem daniele@169: signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); 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: nDicUpdates = length(dicUpdate); %number of dictionary updates 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@169: SMALL.DL(nInitDicts,nCorrLevels,nDecorrAlgs,nDicUpdates) = SMALL_init_DL(toolbox); %create dictionary learning structures daniele@169: for iInitDicts=1:nInitDicts daniele@169: for iCorrLevels=1:nCorrLevels daniele@169: for iDecorrAlgs=1:nDecorrAlgs daniele@169: for iDicUpdates=1:nDicUpdates daniele@169: SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).toolbox = toolbox; daniele@169: SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).name = dicUpdate{iDicUpdates}; daniele@169: SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).profile = true; daniele@169: SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).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@169: SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... daniele@169: SMALL_learn(SMALL.Problem,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates)); 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@169: mu = zeros(size(SMALL.DL)); %coherence daniele@169: dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects daniele@169: for iInitDict=1:nInitDicts daniele@169: for iCorrLevels=1:nCorrLevels daniele@169: for iDecorrAlgs=1:nDecorrAlgs daniele@169: for iDicUpdates=1:nDicUpdates daniele@169: %Sparse representation daniele@169: SMALL.Problem.A = SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D; daniele@169: tempSolver = SMALL_solve(SMALL.Problem,solver); daniele@169: %calculate snr daniele@169: sr(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... daniele@169: snr(SMALL.Problem.b,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D*tempSolver.solution); daniele@169: %calculate mu daniele@169: dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... daniele@169: dictionary(SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D); daniele@169: mu(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... daniele@169: dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).coherence; 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@169: initDictsNames = {'Data','DCT','Gabor'}; daniele@169: dicDecorrNames = {'K-SVD','INK-SVD','Grassmannian','New'}; daniele@169: lineStyles = {'ks-','kd-','ko-','k*-'}; 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@169: for iDecorrAlgs=1:nDecorrAlgs daniele@169: plot(mu(iInitDicts,:,iDecorrAlgs,1),sr(iInitDicts,:,iDecorrAlgs,1),... daniele@169: 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