IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
wden.m
Go to the documentation of this file.
1 %>@ingroup maths
2 %>@file
3 %>@brief Wavelet De-noising
4 %>
5 %> This function uses MATLAB Wavelet toolbox swt() and wthresh() functions to de-noise the rows of X.
6 %> <h3>References</h3>
7 %> [1] M. Misiti, Y. Misiti, G. Oppenheim, and J.-M. Poggi, Wavelet Toolbox User’s Guide R2012b. Mathworks, 2012.
8 %
9 %> @param X
10 %> @param no_levels Number of times the signal will be decimated
11 %> @param thresholds Vector of thresholds, one value for each level. Thresholds are best determined by using the SWT denoising 1-D GUI tool from the Wavelet toolbox
12 %> @param waveletname examples: 'haar', 'db2', 'db3' (see Wavelet toolbox)
13 %> @return X
14 function X = wden(X, no_levels, thresholds, waveletname)
15 
16 [no, nf] = size(X);
17 
18 % Number of points of new signal needs to be determined the following way
19 % 1) Think about the number of levels: l
20 % 2) calculate ceil(nf/2^l)*2^l
21 %
22 % Example: for nf = 1336 and l = 6, this will give 1344
23 nfnew = ceil(nf/2^no_levels)*2^no_levels;
24 no_extend = ceil((nfnew-nf)/2);
25 
26 ipro = progress2_open('Wavelet de-noising', [], 0, no);
27 for i = 1:no
28  Xext = wextend(1, 'sym', X(i, :), no_extend, 'b');
29  Xext = Xext(:, 1:nfnew); % In case nf was odd, Xext will have one column more
30 
31 
32  % SWC contains the decompositions in rows: finest first, ..., then approximation
33  % level 1
34  SWC = swt(Xext, no_levels, waveletname);
35 
36  for j = 1:no_levels
37  SWC(j, :) = wthresh(SWC(j, :), 'h', thresholds(no_levels+1-j));
38  end;
39 
40  Xafter = iswt(SWC, waveletname);
41 
42  X(i, :) = Xafter(no_extend+1:no_extend+nf);
43 
44 
45  ipro = progress2_change(ipro, [], [], i);
46 end;
47 progress2_close(ipro);
function progress2_change(in prgrss, in title, in perc, in i, in n)
function progress2_open(in title, in perc, in i, in n)
function wden(in X, in no_levels, in thresholds, in waveletname)
function progress2_close(in prgrss)