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

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