% Example of the use the mathematical technique of interpolation to
% change the number of points or to equalize unequally-spaced x-axis
% intervals of signals; the results are only approximate but often close
% enough in practice. Matlab and Octave has built in functions for linear,
% cubic spline, and other forms of interpolation;
%
x = 0:2.5:20;
y = sin(x);
xx=0:.1:20;
yy=sin(xx);
Xq = 0:.25:20;
SplineInterp = spline(x,y,Xq);
LinearInterp = interp1(x,y,Xq);
% PiecewiseCubicHermite=pchip(x,y,Xq);
% AkimaInterp=makima(x,y,Xq);
clf
plot(x,y,'ok',xx,yy,':',Xq,LinearInterp,':g',Xq,SplineInterp,'linewidth',2)
title('Comparison of Linear and Cubic Spline interpolation to change the x-axis spacing')
xlabel('x')
ylabel('y')
legend('Data points','underlying signal','Linear interpolation','Spline interpolation')