annotate Problems/generateAudioDenoiseProblem.m @ 10:207a6ae9a76f version1.0

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