ivan@161: %% DICTIONARY LEARNING FOR AUDIO DENOISING ivan@161: % This file contains an example of how SMALLbox can be used to test different ivan@161: % dictionary learning techniques in Audio Denoising problem. ivan@161: % It calls generateAudioDenoiseProblem that will let you to choose audio file, ivan@161: % add noise and use noisy audio to generate training set for dictionary ivan@161: % learning. ivan@161: % ivan@161: % ivan@161: % Centre for Digital Music, Queen Mary, University of London. ivan@161: % This file copyright 2011 Ivan Damnjanovic. ivan@161: % ivan@161: % This program is free software; you can redistribute it and/or ivan@161: % modify it under the terms of the GNU General Public License as ivan@161: % published by the Free Software Foundation; either version 2 of the ivan@161: % License, or (at your option) any later version. See the file ivan@161: % COPYING included with this distribution for more information. ivan@161: % ivan@161: %% ivan@161: ivan@161: clear; ivan@161: ivan@161: % Defining Audio Denoising Problem as Dictionary Learning ivan@161: % Problem ivan@161: ivan@161: SMALL.Problem = generateAudioDenoiseProblem('male01_8kHz',0.1,512,1/128,'','','',4); ivan@161: ivan@161: %% ivan@161: % Initialising solver structure ivan@161: % Setting solver structure fields (toolbox, name, param, solution, ivan@161: % reconstructed and time) to zero values ivan@161: ivan@161: SMALL.solver(1)=SMALL_init_solver('MMbox', 'mm1', '', 1); ivan@161: ivan@161: % Defining the parameters needed for image denoising ivan@161: ivan@161: SMALL.solver(1).param=struct(... ivan@161: 'lambda', 0.2,... ivan@161: 'epsilon', 3*10^-4,... ivan@161: 'iternum',10); ivan@161: ivan@161: % Initialising Dictionary structure ivan@161: % Setting Dictionary structure fields (toolbox, name, param, D and time) ivan@161: % to zero values ivan@161: ivan@161: SMALL.DL(1)=SMALL_init_DL('MMbox', 'MM_cn', '', 1); ivan@161: ivan@161: ivan@161: % Defining the parameters for MOD ivan@161: % In this example we are learning 256 atoms in 20 iterations, so that ivan@161: % every patch in the training set can be represented with target error in ivan@161: % L2-norm (EData) ivan@161: % Type help ksvd in MATLAB prompt for more options. ivan@161: ivan@161: ivan@161: SMALL.DL(1).param=struct(... ivan@161: 'solver', SMALL.solver(1),... ivan@161: 'initdict', SMALL.Problem.initdict,... ivan@161: 'dictsize', SMALL.Problem.p,... ivan@161: 'iternum', 20,... ivan@161: 'iterDictUpdate', 10,... ivan@161: 'epsDictUpdate', 10^-7,... ivan@161: 'cvset',0,... ivan@161: 'show_dict', 0); ivan@161: ivan@161: % Learn the dictionary ivan@161: ivan@161: SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1)); ivan@161: ivan@161: % Set SMALL.Problem.A dictionary ivan@161: % (backward compatiblity with SPARCO: solver structure communicate ivan@161: % only with Problem structure, ie no direct communication between DL and ivan@161: % solver structures) ivan@161: ivan@161: SMALL.Problem.A = SMALL.DL(1).D; ivan@161: SMALL.Problem.reconstruct = @(x) AudioDenoise_reconstruct(x, SMALL.Problem); ivan@161: % Denoising the image - find the sparse solution in the learned ivan@161: % dictionary for all patches in the image and the end it uses ivan@161: % reconstruction function to reconstruct the patches and put them into a ivan@161: % denoised image ivan@161: ivan@161: SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1)); ivan@161: ivan@161: %% ivan@161: %% ivan@161: % % sparse coding using SPAMS online dictionary learning ivan@161: % ivan@161: ivan@161: SMALL.DL(2)=SMALL_init_DL(); ivan@161: SMALL.DL(2).toolbox = 'SPAMS'; ivan@161: SMALL.DL(2).name = 'mexTrainDL'; ivan@161: SMALL.DL(2).param=struct('D', SMALL.Problem.initdict, 'K', SMALL.Problem.p, 'lambda', 0.2, 'iter', 200, 'mode', 3, 'modeD', 0); ivan@161: ivan@161: ivan@161: SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); ivan@161: ivan@161: % Defining Reconstruction function ivan@161: ivan@161: SMALL.Problem.A = SMALL.DL(2).D; ivan@161: ivan@161: ivan@161: %% ivan@161: % Initialising solver structure ivan@161: % Setting toolbox, name, param, solution, reconstructed and time to zero values ivan@161: ivan@161: SMALL.solver(2)=SMALL_init_solver; ivan@161: ivan@161: % Defining the parameters needed for sparse representation ivan@161: ivan@161: SMALL.solver(2).toolbox='ompbox'; ivan@161: SMALL.solver(2).name='omp2'; ivan@161: SMALL.solver(2).param=struct(... ivan@161: 'epsilon',0.2,... ivan@161: 'maxatoms', 128); ivan@161: % Represent Training set in the learned dictionary ivan@161: ivan@161: SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); ivan@161: ivan@161: ivan@161: ivan@161: ivan@161: %% ivan@161: % Plot results and save midi files ivan@161: ivan@161: % show results % ivan@161: ivan@161: ivan@161: SMALL_AudioDeNoiseResult(SMALL); ivan@161: