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
|
function f = ifwt(c,par,varargin)
%-*- texinfo -*-
%@deftypefn {Function} ifwt
%@verbatim
%IFWT Inverse Fast Wavelet Transform
% Usage: f = ifwt(c,info)
% f = ifwt(c,w,J,Ls)
% f = ifwt(c,w,J,Ls,dim)
%
% Input parameters:
% c : Wavelet coefficients.
% info,w : Transform parameters struct/Wavelet filters definition.
% J : Number of filterbank iterations.
% Ls : Length of the reconstructed signal.
% dim : Dimension to along which to apply the transform.
%
% Output parameters:
% f : Reconstructed data.
%
% f = IFWT(c,info) reconstructs signal f from the wavelet coefficients
% c using parameters from info struct. both returned by FWT
% function.
%
% f = IFWT(c,w,J,Ls) reconstructs signal f from the wavelet coefficients
% c using J*-iteration synthesis filterbank build from the basic
% filterbank defined by w. The Ls parameter is mandatory due to the
% ambiguity of lengths introduced by the subsampling operation and by
% boundary treatment methods. Note that the same flag as in the FWT
% function have to be used, otherwise perfect reconstruction cannot be
% obtained.
%
% In both cases, the fast wavelet transform algorithm (Mallat's algorithm)
% is employed. The format of c can be either packed, as returned by the
% FWT function or cell-array as returned by WAVPACK2CELL function.
%
% Please see the help on FWT for a detailed description of the parameters.
%
% Examples:
% ---------
%
% A simple example showing perfect reconstruction:
%
% f = gspi;
% J = 8;
% c = fwt(f,'db8',J);
% fhat = ifwt(c,'db8',J,length(f));
% % The following should give (almost) zero
% norm(f-fhat)
%
%
% References:
% S. Mallat. A wavelet tour of signal processing. Academic Press, San
% Diego, CA, 1998.
%
%
%@end verbatim
%@strong{Url}: @url{http://ltfat.github.io/doc/wavelets/ifwt.html}
%@seealso{fwt, wavpack2cell, wavcell2pack}
%@end deftypefn
% Copyright (C) 2005-2016 Peter L. Soendergaard <peter@sonderport.dk>.
% This file is part of LTFAT version 2.3.1
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% AUTHOR: Zdenek Prusa
complainif_notenoughargs(nargin,2,'IFWT');
if ~(iscell(c) || isnumeric(c)) || isempty(c)
error('%s: Unrecognized coefficient format.',upper(mfilename));
end
if(isstruct(par)&&isfield(par,'fname'))
complainif_toomanyargs(nargin,2,'IFWT');
if ~strcmpi(par.fname,'fwt')
error(['%s: Wrong func name in info struct. ',...
' The info parameter was created by %s.'],...
upper(mfilename),par.fname);
end
% process info struct
w = fwtinit({'dual',par.wt});
J = par.J;
Lc = par.Lc;
Ls = par.Ls;
dim = par.dim;
ext = par.ext;
L = fwtlength(Ls,w,J,ext);
else
complainif_notenoughargs(nargin,4,'IFWT');
%% PARSE INPUT
definput.import = {'fwt'};
definput.keyvals.dim = [];
definput.keyvals.Ls = [];
definput.keyvals.J = [];
[flags,~,J,Ls,dim]=ltfatarghelper({'J','Ls','dim'},definput,varargin);
complainif_notposint(J,'J');
complainif_notposint(Ls,'Ls');
ext = flags.ext;
%If dim is not specified use the first non-singleton dimension.
if(isempty(dim))
dim=find(size(c)>1,1);
else
if(~any(dim==[1,2]))
error('%s: Parameter *dim* should be 1 or 2.',upper(mfilename));
end
end
% Initialize the wavelet filters structure
w = fwtinit(par);
%% ----- Determine input data length.
L = fwtlength(Ls,w,J,ext);
%% ----- Determine number of ceoefficients in each subband
Lc = fwtclength(L,w,J,ext);
end
%% ----- Change c to correct shape according to the dim.
if(isnumeric(c))
%Check *Lc*
if(sum(Lc)~=size(c,dim))
error('%s: Coefficient subband lengths does not comply with parameter *Ls*.',upper(mfilename));
end
%Change format
c = wavpack2cell(c,Lc,dim);
elseif(iscell(c))
%Just check *Lc*
if(~isequal(Lc,cellfun(@(x) size(x,1),c)))
error('%s: Coefficient subband lengths does not comply with parameter *Ls*.',upper(mfilename));
end
else
error('%s: Unrecognized coefficient format.',upper(mfilename));
end;
%% ----- Run computation
f = comp_ifwt(c,w.g,w.a,J,L,ext);
f = postpad(f,Ls);
%% ----- FINALIZE: Reshape back according to the dim.
if(dim==2)
f = f.';
end
%END IFWT
|