function [total,percent] = implpc(data,p,tol) 
% This implements the compression scheme outlined in
% example 3 of sheet 3, plots the original data and
% the data the receiver reconstructs. It also computes
% the approximate compression; data is the data matrix, p is 
% the sent block size and tol is the tolerance
%
x = data(1,:); y = data(2,:);
[count,wc] = lpccompress(y,p,tol);
y1 = improvedrec(y,wc,p);
%
[total,percent] = lpcpercent(y,p,tol);
if total > length(x)-2*p
    fprintf('your tolerance is too small--you would be sending more processed data than original data!\n\n')
else
    cp = (length(x)-2*p)/length(x);
    plot(x,y1,'r',x,y,'k','linewidth',2)
    legend('Compressed','Signal')
    fprintf('with tolerance %f, %f extra numbers are sent,\n and the compression is %f percent\n\n',tol,count,percent)
    fprintf('when no extra data is sent, 2p=%f numbers are sent,\n and the compression is %f percent\n\n',2*p,cp*100)
    fprintf('your original data had %f points\n\n',length(x))
    
end
%