Coding wavelets the easy way

Here is the code for testing the parity of an integer:

function y = isodd(n)
% y = isodd(n) returns 0 if n is even, and returns
% a nonzero number if n is is not odd
% in particular, if n is an odd integer, isodd(n) = 1
y = mod(n,2);

And the code for subsample:

function y = subsample(x)
% returns the subsampled signal obtained by removing the elements
% with odd indices in x
n = length(x.s);
if isodd(x.d)==0
% the lowest degree of the z-transform of x is even
% we keep the first element of x
y.s = x.s(1:2:n);
% the degree of y is half of x.d (which is even)
y.d = (x.d)/2;
else
% the lowest degree of the z-transform of x is odd
% we do not keep the first element of x.s
y.s = x.s(2:2:n);
% the degree of the output will be half of (-x.d+1)
% i.e.
y.d = (x.d-1)/2;
end