function error=fftcompress(t,y,r)
% Input is an array y, which represents a digitized signal 
% associated with the discrete time array t. 
% Also input r which is a decimal
% number between 0 and 1 representing the compression rate
% e.g. 80 percent would be r=0.8.
% Outputs are the graph of y and its compression as well as
% the relative error. This routine uses compress.m
%
% Francis J. Narcowich--3/23/03 (Revised 3/31/04)
%
if (r<0) | (r>1)
  error('r should be between 0 and 1')
end;
fy=fft(y);
fyc=compress(fy,r);
yc=ifft(fyc);
subplot(3,1,3),plot(t,abs(y-real(yc))),...
    legend('Difference')
subplot(3,1,1),plot(t,y),...
    legend('Signal')
subplot(3,1,2),plot(t,real(yc)),...
    legend('Compressed')
error=norm(y-yc,2)/norm(y)
