clc;
close all;
clear all;
workspace;
lengthX = 10;
x = 1:lengthX;
y = rand (lengthX,1);
plot(x, y, '-sr', 'LineWidth', 2);
set(gcf, 'Position', get(0,'Screensize'));
samplingRateIncrease = 10;
newXSamplePoints = linspace(1, max(x), lengthX * samplingRateIncrease);
smoothedY = spline(x, y, newXSamplePoints);
hold on;
plot(newXSamplePoints, smoothedY, '-ob');
title('Spline Interpolation Demo', 'FontSize', 20);
legend('Original Points', 'Spline Points');
slopes = [0, diff(smoothedY)];
plot(newXSamplePoints, slopes, 'k-', 'LineWidth', 3);
line(xlim, [0,0], 'Color', 'k', 'LineWidth', 2);
grid on;
legend('Original Points', 'Spline Points', 'Slope');