[go: up one dir, main page]

Menu

[17deec]: / comp / comp_fwt.m  Maximize  Restore  History

Download this file

65 lines (52 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function c = comp_fwt(f,h,a,J,ext)
%COMP_FWT Compute DWT using FWT
% Usage: c=comp_fwt(f,h,J,a,Lc,ext);
%
% Input parameters:
% f : Input data - L*W array.
% h : Analysis Wavelet filters - cell-array of length *filtNo*.
% J : Number of filterbank iterations.
% a : Subsampling factors - array of length *filtNo*.
% ext : 'per','zero','even','odd' Type of the forward transform boundary handling.
%
% Output parameters:
% c : Cell array of length M. Each element is Lc(m)*W array.
%
% This could be removed with some effort. The question is, are there such
% wavelet filters? If your filterbank has different subsampling factors following the first two filters, please send a feature request.
assert(a(1)==a(2),'First two elements of *a* are not equal. Such wavelet filterbank is not suported.');
% Time-reversed, complex conjugate impulse responses.
filtNo = length(h);
%hCell = cellfun(@(hEl) conj(flipud(hEl.h(:))),h,'UniformOutput',0);
hCell = cellfun(@(hEl) hEl.h(:),h,'UniformOutput',0);
if(strcmp(ext,'per'))
% Initial shift of the filter to compensate for it's delay.
% "Zero" delay transform is produced
% offset = cellfun(@(hEl) 1-numel(hEl.h)-hEl.offset,h);
offset = cellfun(@(hEl) hEl.offset,h);
elseif strcmp(ext,'valid')
offset = -cellfun(@(hEl) numel(hEl.h)-1,h);
else
% No compensation for the filter delay (filters are made causal with respect to the output sequences).
% This creates relative shift between levels of coefficients.
% Initial shift determines type of subsampling.
% This is even subsampling. e.g. subs. [1,2,3,4,5,6] by a factor 3 becomes [3,6]
% The number of output coefficients depends on it.
offset = -(a-1);
% For odd subsampling skip = 0; but it requires slight touches
% elsewhere.
end
M = (filtNo-1)*J+1;
c = cell(M,1);
runPtr = M-filtNo+2;
ctmp = f;
for jj=1:J
% Run filterbank
ctmp = comp_filterbank_td(ctmp,hCell,a,offset,ext);
% Bookkeeping
c(runPtr:runPtr+filtNo-2) = ctmp(2:end);
ctmp = ctmp{1};
runPtr = runPtr - (filtNo - 1);
end
% Save final approximation coefficients
c{1} = ctmp;