function dum = wcintro()

% The example of the introduction
% elementary Haar wavelet analysis
% the basis functions and the coordinates
% for a signal of 8 samples

% the signal has 8 samples

x0 = [1 3 5 7 2 -1 -3 -2]';
figure(1), xst = (1 : 9) - 0.5;
subplot(4, 2, 1), stairs(xst, exex(x0)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r'), hold off
title('the originl signal: 8 samples')

% first transform step

H1 = [1 1 0 0 0 0 0 0;...
      0 0 1 1 0 0 0 0;...
      0 0 0 0 1 1 0 0;...
      0 0 0 0 0 0 1 1]/sqrt(2);
G1 = [1 -1 0 0 0 0 0 0;...
      0 0 1 -1 0 0 0 0;...
      0 0 0 0 1 -1 0 0;...
      0 0 0 0 0 0 1 -1]/sqrt(2);

X1 = H1 * x0; x1 = H1' * X1; Y1 = G1 * x0; y1 = G1' * Y1;

subplot(4, 2, 3); stairs(xst, exex(x1)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r')
plot(1.5 : 2 : 7.5, X1, 'r*'), hold off
subplot(4, 2, 4); stairs(xst, exex(y1)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r')
plot(1.5 : 2 : 7.5, Y1, 'r*'), hold off

% second transform step

H2 = H1(1 : 2, 1 : 4);
G2 = G1(1 : 2, 1 : 4);
X2 = H2 * X1; Y2 = G2 * X1;
x2 = H1' * H2' * X2; y2 = H1' * G2' * Y2;

subplot(4, 2, 5); stairs(xst, exex(x2)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r'),
plot(2.5 : 4 : 6.5, X2, 'r*'), hold off
subplot(4, 2, 6); stairs(xst, exex(y2)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r')
plot(2.5 : 4 : 6.5, Y2, 'r*'), hold off

% third transform step

H3 = H2(1 : 1, 1 : 2);
G3 = G2(1 : 1, 1 : 2);
X3 = H3 * X2; Y3 = G3 * X2;
x3 = H1' * H2' * H3' * X3; y3 = H1' * H2' * G3' * Y3;

subplot(4, 2, 7); stairs(xst, exex(x3)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r')
plot(4.5, X3, 'r*'), hold off
subplot(4, 2, 8); stairs(xst, exex(y3)), axis([0 9 -5 10])
hold on, plot(xst, zeros(size(xst)), 'r')
plot(4.5, Y3, 'r*'), hold off
subplot(4, 2, 2), plot(1 : 8, [X3' Y3' Y2' Y1'], 'r*'), axis([0 9 -5 10])
hold on, plot(0.5 : 8.5, zeros(1, 9), 'r'), vert = [-5; 10];
plot([0.5 0.5], vert, 'b--', [1.5 1.5], vert, 'b--',...
   [2.5 2.5], vert, 'b--',...
   [4.5 4.5], vert, 'b--', [8.5 8.5], vert, 'b--'), hold off

function xex = exex(x)
l = length(x);
xex(1 : l, : ) = x;
xex(l + 1, : ) = x(l, : );
