Monday, October 15, 2012

Matlab Interpolation

Here is a quick example of linear interpolation.




%% Linear Interpolation Example
% James Eastham, Member IEEE
% 10/15/2012
close all;
clear all;
x = 0:100; %Original Data Points
y = sin(x); % sin of original data points
xi = 0:.5:100; % points to interpolate
yi = interp1(x,y,xi); % interpolated vector
figure('Color',[1 1 1]);
subplot(3,1,1);
plot(x,y,'o-g',xi,yi,'.-b')
title('Interpolation Example 1 Points');
xlabel('point');
ylabel('sin(x)');
x = 0:100; %Original Data Points
y = sin(x); % sin of original data points
xi = 0:.25:100; % points to interpolate
yi = interp1(x,y,xi); % interpolated vector
subplot(3,1,2);
plot(x,y,'o',xi,yi,'.-r')
title('Interpolation Example 3 Points');
xlabel('point');
ylabel('sin(x)');
x = 0:100; %Original Data Points
y = sin(x); % sin of original data points
xi = 0:.1:100; % points to interpolate
yi = interp1(x,y,xi); % interpolated vector
subplot(3,1,3);
plot(x,y,'o',xi,yi,'.-g')
title('Interpolation Example 9 Points');
xlabel('point');
ylabel('sin(x)');