function cd = ipcompress(x,y,ratio)
% Data compression by recursive spline interpolation

n = length(y); 
% transform data values by recursive interpolation
y = iprectrf(x,y,@spline);
% The smallest (in modulus) coefficients will be dropped
d = min(floor((n-2)*ratio),n-2);
z = sort(abs(y(2:end-1)));
cd.idx = [1,(find(abs(y(2:end-1)) > z(d+1)) + 1),n];
cd.values = y(cd.idx);
cd.length = n;
