function m = lpctransmit(y,p,tol)
% y is the data set y1,...,yN; 
% p is the size of the semi-repetitive block y1,...,yp
% tol is the tolerance for acceptable error

N = length(y);

% Find v

A = lpcA(p,y);
Y = lpcY(p,y);
v = (inv(A'*A)*A'*Y)';

% reverse the order of the elements in v

Vp1 = 0;
for k =1:p
    Vp1(k) = v(p-k+1);
end

% calculate the approximations--the tildes
% z will be y1,...yp,tilde y(p+1),...tilde y(N)
z=0;
for k = 1:p
    z(k)=y(k);
end
for k = p+1:N
    z(k) = y(k-p:k-1)*Vp1';
end
% calculate the errors

e=0;
for k = 1:N-p
    e(k) = y(p+k) - z(p+k);
end
% decide which of y(p+1),...,y(N) must also be sent by comparing error 
% with tolerance

count = 0;w = 0;
for k = 1:p
    w(k) = y(k);
end

for k = p+1:N
    if abs(e(k-p))<= tol
        count(k-p) = 1;
    else
        count(k-p) = 0;
    end
end
tr = 0; c2 = 0;
for k = p+1:N
    if count(k-p)==0
        c2 = c2+1;
        tr(c2)=y(k);
    end
end

m = [N, p, w, v, count, tr];
% N is the length of the data block
% p is the length of the semirepetitive block y1,...,yp
% w is the semirepetitive block y1,...,yp
% v is the vector of coefficients a1,...,ap
% count tells which of y(p+1),...,y(N) were also sent:
% 1 means don't send, 0 means send
% tr is the list of sent ones from  y(p+1),...,y(N)

% u = ceil((sum(count)+2*p));
% fprintf('You sent about %f points from which the original %f points can be reconstructed %f',u,N)