% Inverse wavelet transform in dimension one
%
% Arguments:
% tr   transform (a vector of power-of-two length)
% h    high-pass filter
% g    low-pass filter
% J    number of scales
%
% Returns:
% f    inverse transformed signal
%
% Samuli Siltanen October 2016

function f = Wavelet_tr_inv(tr,h,g,J)

% Test that tr is not a matrix
[row,col] = size(tr);
if (row>1) & (col>1)
    error('tr should be a vector')
end

% Test that the input signal has power-of-two length
tr = tr(:).';
J0 = log2(length(tr));
if (J0-floor(J0))>0
    error('tr must have power-of-two length')
end

% Test that J is not too big
if J>J0
    error('Vector tr is too short for J steps of the transform')
end

tr_curr = tr;
for jjj = 1:J
    tmp = tr_curr(1:2^(J0-J+jjj));    
    tr_curr(1:2^(J0-J+jjj)) = Wavelet_tr_inv_onestep(tmp,h,g);
end
f = tr_curr;
