Coding wavelets the easy way

function y = zeroinsert(x)
% inserts zeros between every sample of a discrete signal/filter
% the signal/filter is structured, i.e. it has two fields

% we determine here if the the input is a row or column vector
% and create a zero vector whose size is equal to the size of the output
% vector. If the length of the original data field is n,
% then we insert n-1 zeros and the length of the output is 2*n-1
n = size(x.s);
if (n(1) == 1)
y.s = zeros(1,n(2)*2-1);
else
y.s = zeros(n(1)*2-1,1);
end
% we insert the value of the original data field. Since the beginning
% and the end of the output data contains the boundary values of the original
% data, our subindexing begins at the start index 1
y.s(1:2:end) = x.s;
% now we handle the delay term. This is easier to understand if we use the
% z-transform of the input. The output z-transform is obtained from the
% input z-transform by replacing every monomial z^k by its square z^(2*k)
% hence the minimum degree that appears in the z-transform is doubled in
% the operation.
y.d = 2*x.d;