%% Section 3.2-3.2 Example of signal compression

s = [56 40 8 24 48 48 40 16]'

%
% We computed the 3 scale wavelet transform of s and found it is

v = [35 -3 16 10 8 -8 0 12]'

%
% We compress the signal using the threshhold \varepsilon =4\ldotp First we need the wavelet synthesis matrix W_s. Here's a calculation of it, starting by calculating the wavelet analysis matrix.
%

T3a = sym([1/2*eye(4) 1/2*eye(4); 1/2*eye(4) -1/2*eye(4)]);
T3=T3a*downsamp(4);
T2a = sym([1/2*eye(2) 1/2*eye(2); 1/2*eye(2) -1/2*eye(2)])*downsamp(2);
T2 = [T2a zeros(4);zeros(4) eye(4)];
T1a = sym([1/2 1/2; 1/2 -1/2]);
T1 = [T1a zeros(2) zeros(2) zeros(2); zeros(2) eye(2) zeros(2) zeros(2); zeros(4) eye(4)];
Wa = T1*T2*T3

%
%
% I made the entries symbolic with the sym command so I would get fractions instead of decimals. The synthesis matrix is the inverse of the analysis matrix,

Ws = Wa^(-1)

%
% For the compression, I replace the second component of v by 0 then apply Ws.

v(2,1) = 0; v

%


y = Ws*v

%
% I compress more, using 9 as the threshhold.

v(5,1)=0; v(6,1)=0; v

%

z = Ws*v

%
% I plot the first two vectors.

plot(s,'b'), hold on
plot(y,'r--'), hold off

%
% I see that they are quite close. Now I plot them with the third.

plot(s,'b'), hold on
plot(y,'r--'), 
plot(z,'k:','LineWidth',1.5), hold off