1function x = indwt(varargin)
2// Inverse nondecimated 1-D wavelet transform
3// Calling Sequence
4// C=indwt(W,type,[N])
5// Parameters
6// W:ndwt structure
7// type : type ('a' for low-pass components or 'd' for high-pass components)
8// N: Level of decomposition
9// C: reconstructed components at level N
10// Description
11// indwt performs a multilevel nondecimate reconstruction.
12// Examples
13// x=rand(1,100);
14// W1 = ndwt(x,3,'db1');
15//  a0 = indwt(W1,'a',0);
16//
17//  //reconstruction error
18// err = max(abs(x(:)-a0(:)))
19//
20// Authors
21// H. Nahrstaedt - 2013
22// See Also
23// ndwt
24// ndwt2
25// indwt2
26[nargout,nargin]=argn(0);
27
28
29if ~isstruct(varargin(1))
30    error('first argument shoud be a struct!');
31end
32
33wt = varargin(1);
34ndList = wt.dec;
35LoR = wt.filters.LoR;
36HiR = wt.filters.HiR;
37LX  = wt.longs($);
38level = wt.level;
39nextArg = 2;
40
41nam_Rec = 's';
42lev_Rec = 0;
43while nargin>=nextArg
44    argName = convstr(varargin(nextArg));
45    argVal  = varargin(nextArg+1);
46    nextArg = nextArg + 2;
47    if or( argName== {'a','d','ca','cd'})
48            nam_Rec = argName;
49            lev_Rec = argVal;
50    end
51end
52
53lastSTEP = level;
54select nam_Rec
55    case 's'
56
57    case 'cd'
58        x = ndList(level+1-(lev_Rec-1));
59        return;
60
61    case 'ca'
62        if lev_Rec==level
63             x = ndList(1);
64             return
65        end
66        for k = level+1:-1:2+(level-lev_Rec)
67            ndList(k) = zeros(ndList(k));
68        end
69        lastSTEP = level-lev_Rec;
70
71    case 'd'
72        set2zero = setdiff((1:level+1),level+2-lev_Rec);
73        for k = set2zero
74            ndList(k) = zeros(ndList(k));
75        end
76
77    case 'a'
78        for k = level+1:-1:2+(level-lev_Rec)
79            ndList(k) = zeros(ndList(k));
80        end
81end
82
83index = 1;
84for k=1:lastSTEP
85    a = conv(ndList(index),LoR);
86    d = conv(ndList(index+1),HiR);
87    ndList(index+1) = (a+d)/2;
88    if index<level
89        ndList(index+1) = wkeep(ndList(index+1),length(ndList(index+2)),'c');
90    end
91    index = index+1;
92end
93if (nam_Rec=='ca') & ~(lev_Rec==0)
94    x = ndList(index); return;
95end
96x = wkeep(ndList($),LX,'c');
97
98endfunction