[77a22a]: wavelets / comp_iwfbt.m Maximize Restore History

Download this file

comp_iwfbt.m    163 lines (149 with data), 6.1 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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function f=comp_iwfbt(c,wt,Ls,type,ext)
%COMP_IWFBT Compute Inverse Wavelet Filter-Bank Tree
% Usage: f=comp_iwfbt(c,wt,Ls,type,ext)
%
% Input parameters:
% c : Coefficients stored in the cell array.
% wt : Structure defining the filterbank tree (see |wfbtinit|_)
% type : 'dec','undec' Type of the wavelet transform.
% ext : 'per','zpd','sym','symw','asym','asymw','ppd','sp0' Type of the forward transform boundary handling.
%
% Output parameters:
% f : Reconstructed data.
%
% Do non-expansve transform if ext='per'
if(strcmp(ext,'per'))
doNoExt = 1;
else
doNoExt = 0;
end
% number of channels
chans = size(c{end},2);
% Nodes in the reverse BF order
treePath = nodesBForder(wt);
treePath = treePath(end:-1:1);
%
% The decimated case
if(strcmp(type,'dec'))
nodesOutLengths = zeros(length(treePath),1);
for ii=1:length(treePath)
nodesOutLengths(ii) = nodeInLen(treePath(ii),Ls,doNoExt,wt);
end
for ch=1:chans
tempca = {};
for jj=1:length(treePath)
tmpfilt = wt.nodes{treePath(jj)}.filts;
if(isempty(tmpfilt))
error('%s: Synthesis filters not defined.',upper(mfilename));
end
tmpa = wt.nodes{treePath(jj)}.a;
tmpOutLen = nodesOutLengths(jj);
tmpNoOfFilters = length(tmpfilt);
% find all unconnected outputs of the node
tmpOutRange = rangeInLocalOutputs(treePath(jj),wt);
tmpOutRange = tmpOutRange(end:-1:1);
tmpCoefOutRange = [];
if(~isempty(tmpOutRange))
tmpCoefOutRange = rangeInOutputs(treePath(jj),wt);
tmpCoefOutRange = tmpCoefOutRange(end:-1:1);
end
tempOut = zeros(tmpOutLen,1);
% first, do the filtering that uses c
for ff=1:length(tmpCoefOutRange)
ffTmpFilt = tmpfilt{tmpOutRange(ff)}.h;
ffTmpFiltD = tmpfilt{tmpOutRange(ff)}.d;
ffTmpFlen = length(ffTmpFilt);
ffTmpa = tmpa(tmpOutRange(ff));
if(doNoExt)
tmpSkip = ffTmpFiltD-1;
else
tmpSkip = ffTmpFlen-2;
end
tempOut = tempOut + up_conv_td({c{tmpCoefOutRange(ff)}(:,ch)},...
tmpOutLen,{ffTmpFilt},ffTmpa,tmpSkip,doNoExt,0);
end
% second, do other filtering
tmpOtherRange = 1:tmpNoOfFilters;tmpOtherRange(tmpOutRange)=0;tmpOtherRange=tmpOtherRange(tmpOtherRange~=0);
tmpOtherRange = tmpOtherRange(end:-1:1);
tmpOtherOutNo = length(tmpOtherRange);
for ff=1:tmpOtherOutNo
ffTmpFilt = tmpfilt{tmpOtherRange(ff)}.h;
ffTmpFiltD = tmpfilt{tmpOtherRange(ff)}.d;
ffTmpFlen = length(ffTmpFilt);
ffTmpa = tmpa(tmpOtherRange(ff));
if(doNoExt)
tmpSkip = ffTmpFiltD-1;
else
tmpSkip = ffTmpFlen-2;
end
tempOut = tempOut + up_conv_td({tempca{ff}},...
tmpOutLen,{ffTmpFilt},ffTmpa,tmpSkip,doNoExt,0);
end
% store the intermediate results
tempca = {tempca{tmpOtherOutNo+1:end},tempOut};
end
f(:,ch) = tempca{end};
end
elseif(strcmp(type,'undec'))
for ii=1:length(treePath)
nodesOutLengths(ii) = Ls;
end
for ch=1:chans
tempca = {};
for jj=1:length(treePath)
tmpfilt = wt.nodes{treePath(jj)}.filts;
tmpa = wt.nodes{treePath(jj)}.a;
for ii = 1:numel(tmpfilt)
tmpfilt{ii}.h = tmpfilt{ii}.h/sqrt(tmpa(ii));
end
tmpOutLen = nodesOutLengths(jj);
tmpNoOfFilters = length(tmpfilt);
% find all unconnected outputs of the node
tmpOutRange = rangeInLocalOutputs(treePath(jj),wt);
tmpOutRange = tmpOutRange(end:-1:1);
tmpCoefOutRange = [];
if(~isempty(tmpOutRange))
tmpCoefOutRange = rangeInOutputs(treePath(jj),wt);
tmpCoefOutRange = tmpCoefOutRange(end:-1:1);
end
tempOut = zeros(tmpOutLen,1);
% first, do the filtering that uses c
for ff=1:length(tmpCoefOutRange)
ffTmpFilt = tmpfilt{tmpOutRange(ff)}.h;
ffTmpFiltD = tmpfilt{tmpOutRange(ff)}.d;
ffTmpFlen = length(ffTmpFilt);
%ffTmpa = tmpa(tmpOutRange(ff));
ffTmpUpFac = nodeFiltUps(treePath(jj),wt);
if(doNoExt)
tmpSkip = ffTmpUpFac*(ffTmpFiltD-1);
else
error('Not done yet!');
%tmpSkip = ffTmpFlen-2;
end
tempOut = tempOut + up_conv_td({c{tmpCoefOutRange(ff)}(:,ch)},...
tmpOutLen,{ffTmpFilt},1,tmpSkip,doNoExt,ffTmpUpFac);
end
% second, do other filtering
tmpOtherRange = 1:tmpNoOfFilters;tmpOtherRange(tmpOutRange)=0;tmpOtherRange=tmpOtherRange(tmpOtherRange~=0);
tmpOtherRange = tmpOtherRange(end:-1:1);
tmpOtherOutNo = length(tmpOtherRange);
for ff=1:tmpOtherOutNo
ffTmpFilt = tmpfilt{tmpOtherRange(ff)}.h;
ffTmpFiltD = tmpfilt{tmpOtherRange(ff)}.d;
ffTmpFlen = length(ffTmpFilt);
%ffTmpa = tmpa(tmpOtherRange(ff));
ffTmpUpFac = nodeFiltUps(treePath(jj),wt);
if(doNoExt)
tmpSkip = ffTmpUpFac*(ffTmpFiltD-1);
else
tmpSkip = ffTmpFlen-2;
end
tempOut = tempOut + up_conv_td({tempca{ff}},...
tmpOutLen,{ffTmpFilt},1,tmpSkip,doNoExt,ffTmpUpFac);
end
% store the intermediate results
tempca = {tempca{tmpOtherOutNo+1:end},tempOut};
end
f(:,ch) = tempca{end};
end
end