Coding wavelets the easy way

% clear workspace
clear all
% Prepare data
load PieceRegSig;
u.s = sig;
u.d = 0;
% Prepare the filters
load Daub4;
h.s = h;
h.d = 0; % degree is 3
g.s = g;
g.d = 0;
rh.s = rh;
rh.d = 3; % degree is -3
rg.s = rg;
rg.d = 3;
% -----------------
NumEl = round(length(sig)/10);
scale = 6;
%-----------------
WT = WaveTransform(u,h,g,scale);
t = thresholdValue(WT,NumEl);
WT = threshold(WT,t)
v = InvWaveTransform(WT,rh,rg,scale);
l = length(sig);
w = v.s(v.d+1:v.d+l);
figure(1);
hold on;
plot(sig,'b');
plot(w,'r');
hold off;
figure(2);plot(w-sig);

and here is the superposition plot

ApproximationDiff