clear
load Wiltonsam
load Wiltonsblue
load Wiltonscar

y1 = Wiltonsam;
y2 = Wiltonsblue;
y3 = Wiltonscar;


% Wilton: I commented out the following 3 lines--they were ok as a
% check, but once you've checked, you can comment them out.

% subplot(3,1,1);plot(y1);title('Wiltonsam');
% subplot(3,1,2);plot(y2);title('Wiltonsblue');
% subplot(3,1,3);plot(y3);title('Wiltonscar');

% Here is one mistake: the scale needs to be multiplied
% by 10^5----look at the scale on your previous 3 subplots
% and you'll see it. I've fixed it in the next 3 lines. Also,
% you need to do a level one Haar decompostion, so these
% aren't the right y1d's. I've commented them out and put
% in the lines you need after them

% y1da = y1(1.46e5:1.48e5);
% y1db = y1(1.49e5:1.51e5);
% y1dc = y1(1.53e5:1.54e5);
% y1dd = y1(1.55e5:1.57e5);

% Here is the level one Haar decompostion:

n = 1;
fam = 'db1';
[C1,L1]=wavedec( y1,n,fam);[C2,L2]=wavedec( y2,n,fam);[C3,L3]=wavedec( y3,n,fam);


% Now extract the level one details:

y1d= wrcoef('d',C1,L1,fam,n);
y2d= wrcoef('d',C2,L2,fam,n);
y3d= wrcoef('d',C3,L3,fam,n);

% Now pick out the four good repetitions:

y1da = y1d(1.46e5:1.48e5);
y1db = y1d(1.49e5:1.51e5);
y1dc = y1d(1.53e5:1.54e5);
y1dd = y1d(1.55e5:1.57e5);


% Wilton, when I looked at the details on the
% plots from the wavemenu, I don't get the same
% numbers you did. For example, for the repetitions
% 1, 2, 4 and 5, I got the ranges
% 1.475e4 to 2.44e4
% 4.189e4 to 5.289e4
% 9.493e4 to 10.8e4
% 12.2e4 to 13.133e4

% This was only for the word am; you still need to do it
% for the other two words. So you'll have to fill in
% the question marks in the next 8 lines:

% y2da = y2d(??);
% y2db = y2d(??);
% y2dc = y2d(??);
% y2dd = y2d(??);
% 
% y3da = y3d(??);
% y3db = y3d(??);
% y3dc = y3d(??);
% y3dd = y3d(??);



subplot(4,1,1);plot(y1da);
subplot(4,1,2);plot(y1db);
subplot(4,1,3);plot(y1dc);
subplot(4,1,1);plot(y1dd);

% y2da = y2(1.50:1.51);
% y2db = y2(4.36:4.37);
% y2dc = y2(4.42:4.43);
% y2dd = y2(4.45:4.46);

% y3da = y3(7.08:7.09);
% y3db = y3(9.78:9.85);
% y3dc = y3(1.26:1.27);
% y3dd = y3(1.82:1.83);

m = 2;
A1a = makemat(y1da,m);

% A1 = (A1a + A1b + A1c + A1d)/4;
% A2 = (A2a + A2b + A2c + A2d)/4;
% A3 = (A3a + A3b + A3c + A3d)/4;