annotate Problems/generateAudioDenoiseProblem.m @ 80:16df822019f1

Setup script removed Sparco's RWT from the path
author Ivan <ivan.damnjanovic@eecs.qmul.ac.uk>
date Mon, 28 Mar 2011 12:07:07 +0100
parents 0211faef9add
children 8e660fd14774
rev   line source
idamnjanovic@10 1 function data=generateAudioDenoiseProblem(au, trainnum, blocksize, dictsize, overlap, sigma, gain, maxval, initdict);
idamnjanovic@21 2 %%% Audio Denoising Problem
idamnjanovic@21 3 %
idamnjanovic@21 4 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@21 5 % This file copyright 2010 Ivan Damnjanovic.
idamnjanovic@21 6 %
idamnjanovic@21 7 % This program is free software; you can redistribute it and/or
idamnjanovic@21 8 % modify it under the terms of the GNU General Public License as
idamnjanovic@21 9 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@21 10 % License, or (at your option) any later version. See the file
idamnjanovic@21 11 % COPYING included with this distribution for more information.
idamnjanovic@21 12 %
idamnjanovic@10 13 %
idamnjanovic@10 14 %
idamnjanovic@10 15 % generateAudioDenoiseProblem is part of the SMALLbox and generate a
idamnjanovic@10 16 % problem for comaprison of Dictionary Learning/Sparse Representation
idamnjanovic@10 17 % techniques in audio denoising scenario. It is based on KSVD image
idamnjanovic@10 18 % denoise demo by Ron Rubinstein (see bellow).
idamnjanovic@10 19 % The fuction takes as an optional input
idamnjanovic@10 20 % au - audio samples to be denoised
idamnjanovic@10 21 % trainnum - number of frames for training
idamnjanovic@10 22 % blocksize - 1D frame size (eg 512)
idamnjanovic@10 23 % dictsize - number of atoms to be trained
idamnjanovic@10 24 % overlap - ammount of overlaping frames between 0 and 1
idamnjanovic@21 25 %
idamnjanovic@10 26
idamnjanovic@10 27
idamnjanovic@10 28 disp(' ');
idamnjanovic@10 29 disp(' ********** Denoising Problem **********');
idamnjanovic@10 30 disp(' ');
idamnjanovic@10 31 disp(' This function reads an audio, adds random Gaussian noise,');
idamnjanovic@10 32 disp(' that can be later denoised by using dictionary learning techniques.');
idamnjanovic@10 33 disp(' ');
idamnjanovic@10 34
idamnjanovic@10 35 FS=filesep;
idamnjanovic@10 36 if ~ exist( 'sigma', 'var' ) || isempty(sigma), sigma = 26.74; end
idamnjanovic@10 37 if ~ exist( 'gain', 'var' ) || isempty(gain), gain = 1.15; end
idamnjanovic@10 38
idamnjanovic@10 39 if ~ exist( 'initdict', 'var' ) || isempty(initdict), initdict = 'odct'; end
idamnjanovic@10 40 if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 15/16; end
idamnjanovic@10 41 %% prompt user for wav file %%
idamnjanovic@10 42 %ask for file name
idamnjanovic@10 43
idamnjanovic@10 44 TMPpath=pwd;
idamnjanovic@10 45 if ~ exist( 'au', 'var' ) || isempty(au)
idamnjanovic@10 46 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
idamnjanovic@10 47 cd([pathstr1,FS,'data',FS,'audio',FS,'wav']);
idamnjanovic@10 48 [filename,pathname] = uigetfile({'*.wav;'},'Select a wav file');
idamnjanovic@10 49 [pathstr, name, ext, versn] = fileparts(filename);
idamnjanovic@10 50 data.name=name;
idamnjanovic@10 51
idamnjanovic@10 52 au = wavread(filename);
idamnjanovic@10 53 au = mean(au,2); % turn it into mono.
idamnjanovic@10 54 end;
idamnjanovic@10 55 if ~ exist( 'maxval', 'var' ) || isempty(maxval), maxval = max(au); end
idamnjanovic@10 56
idamnjanovic@10 57 %% generate noisy audio %%
idamnjanovic@10 58
idamnjanovic@10 59 disp(' ');
idamnjanovic@10 60 disp('Generating noisy audio...');
idamnjanovic@10 61 sigma = max(au)/10^(sigma/20);
idamnjanovic@10 62 n = randn(size(au)) .* sigma;
idamnjanovic@10 63 aunoise = au + n;% here we can load noise audio if available
idamnjanovic@10 64 % for example: wavread('icassp06_x.wav');%
idamnjanovic@10 65
idamnjanovic@10 66
idamnjanovic@10 67
idamnjanovic@10 68 %% set parameters %%
idamnjanovic@10 69
idamnjanovic@10 70 x = aunoise;
idamnjanovic@10 71 if ~ exist( 'blocksize', 'var' ) || isempty(blocksize),blocksize = 512;end
idamnjanovic@10 72 if ~ exist( 'dictsize', 'var' ) || isempty(dictsize), dictsize = 2048;end
idamnjanovic@10 73
idamnjanovic@10 74 if ~ exist( 'trainnum', 'var' ) || isempty(trainnum),trainnum = (size(x,1)-blocksize+1);end
idamnjanovic@10 75
idamnjanovic@10 76
idamnjanovic@10 77
idamnjanovic@10 78
idamnjanovic@10 79
idamnjanovic@10 80 p=1;
idamnjanovic@10 81
idamnjanovic@10 82
idamnjanovic@10 83 %
idamnjanovic@10 84 % msgdelta = 5;
idamnjanovic@10 85 %
idamnjanovic@10 86 % verbose = 't';
idamnjanovic@10 87 % if (msgdelta <= 0)
idamnjanovic@10 88 % verbose='';
idamnjanovic@10 89 % msgdelta = -1;
idamnjanovic@10 90 % end
idamnjanovic@10 91 %
idamnjanovic@10 92 %
idamnjanovic@10 93 % % initial dictionary %
idamnjanovic@10 94 %
idamnjanovic@10 95 if (strcmpi(initdict,'odct'))
idamnjanovic@10 96 initdict = odctndict(blocksize,dictsize,p);
idamnjanovic@10 97 elseif (strcmpi(initdict,'data'))
idamnjanovic@10 98 clear initdict; % causes initialization using random examples
idamnjanovic@10 99 else
idamnjanovic@10 100 error('Invalid initial dictionary specified.');
idamnjanovic@10 101 end
idamnjanovic@10 102
idamnjanovic@10 103 if exist( 'initdict', 'var' )
idamnjanovic@10 104 initdict = initdict(:,1:dictsize);
idamnjanovic@10 105 end
idamnjanovic@10 106
idamnjanovic@10 107
idamnjanovic@10 108 % noise mode %
idamnjanovic@10 109 % if (isfield(params,'noisemode'))
idamnjanovic@10 110 % switch lower(params.noisemode)
idamnjanovic@10 111 % case 'psnr'
idamnjanovic@10 112 % sigma = maxval / 10^(params.psnr/20);
idamnjanovic@10 113 % case 'sigma'
idamnjanovic@10 114 % sigma = params.sigma;
idamnjanovic@10 115 % otherwise
idamnjanovic@10 116 % error('Invalid noise mode specified');
idamnjanovic@10 117 % end
idamnjanovic@10 118 % elseif (isfield(params,'sigma'))
idamnjanovic@10 119 % sigma = params.sigma;
idamnjanovic@10 120 % elseif (isfield(params,'psnr'))
idamnjanovic@10 121 % sigma = maxval / 10^(params.psnr/20);
idamnjanovic@10 122 % else
idamnjanovic@10 123 % error('Noise strength not specified');
idamnjanovic@10 124 % end
idamnjanovic@10 125
idamnjanovic@10 126 % params.Edata = sqrt(prod(blocksize)) * sigma * gain; % target error for omp
idamnjanovic@10 127 % params.codemode = 'error';
idamnjanovic@10 128 %
idamnjanovic@10 129 % params.sigma = sigma;
idamnjanovic@10 130 % params.noisemode = 'sigma';
idamnjanovic@10 131 %
idamnjanovic@10 132 %
idamnjanovic@10 133 % % make sure test data is not present in params
idamnjanovic@10 134 % if (isfield(params,'testdata'))
idamnjanovic@10 135 % params = rmfield(params,'testdata');
idamnjanovic@10 136 % end
idamnjanovic@10 137
idamnjanovic@10 138
idamnjanovic@10 139 %%%% create training data %%%
idamnjanovic@10 140
idamnjanovic@10 141
idamnjanovic@10 142 X = buffer( x(1:trainnum),blocksize, overlap*blocksize);
idamnjanovic@10 143
idamnjanovic@10 144 % remove dc in blocks to conserve memory %
idamnjanovic@10 145 % bsize = 2000;
idamnjanovic@10 146 % for i = 1:bsize:size(X,2)
idamnjanovic@10 147 % blockids = i : min(i+bsize-1,size(X,2));
idamnjanovic@10 148 % X(:,blockids) = remove_dc(X(:,blockids),'columns');
idamnjanovic@10 149 % end
idamnjanovic@10 150 data.Original = au;
idamnjanovic@10 151 data.Noisy = aunoise;
idamnjanovic@10 152 data.b = X;
idamnjanovic@10 153 data.m = size(X,1);
idamnjanovic@10 154 data.n = size(X,2);
idamnjanovic@10 155 data.p = dictsize;
idamnjanovic@10 156 data.blocksize=blocksize;
idamnjanovic@10 157 data.sigma = sigma;
idamnjanovic@10 158 data.gain = gain;
idamnjanovic@10 159 data.maxval = maxval;
idamnjanovic@10 160 data.initdict= initdict;
idamnjanovic@10 161 data.signalDim=1;
idamnjanovic@10 162 cd(TMPpath);
idamnjanovic@10 163