Challenge

Project - Data Handling and Interpolation

Aim: In a laboratory experiment, data of voltage and current has been recorded and the same is attached in an excel file. Read the excel file in the Matlab program and perform the interpolation in the range of -17.3:0.1:0.9. Generate the interactive plot for the interpolated data and store them in a text file.

Theory:

Interpolation

Interpolation is a method of deriving a simple function from the given discrete data set such that the function passes through the provided data points. This helps to determine the data points in between the given data ones. This method is always needed to compute the value of a function for an intermediate value of the independent function. In short, interpolation is a process of determining the unknown values that lie in between the known data points. It is mostly used to predict the unknown values for any geographical related data points such as noise level, rainfall, elevation, and so on.

A closely related problem is the approximation of a complicated function by a simple function. Suppose the formula for some given function is known, but too complicated to evaluate efficiently. A few data points from the original function can be interpolated to produce a simpler function which is still fairly close to the original. The resulting gain in simplicity may outweigh the loss from interpolation error and give better performance in calculation process.

Types of interpolation method are

  1. Linear interpolation
  2. Nearest neighbour interpolation or Piecewise constant interpolation
  3. Polynomial interpolation
  4. Spline interpolation
  5. Mimetic interpolation

1. Linear interpolation

The Linear Interpolation Method applies a distinct linear polynomial between each pair of the given data points for the curves, or within the sets of three points

The unknown value on the data points can be found using the linear interpolation formula.

2. Nearest Nehibour Method

In this method the value of an interpolated point is inserted to the value of the most adjacent data point.Therefore the nearest neighbour method does not produce any new data points.

3. Polynomial interpolation

Polynomial interpolation is a generalization of linear interpolation. Note that the linear interpolant is a linear function. We now replace this interpolant with a polynomial of higher degree.

if we have n data points, there is exactly one polynomial of degree at most n−1 going through all the data points. The interpolation error is proportional to the distance between the data points to the power n. Furthermore, the interpolant is a polynomial and thus infinitely differentiable. So, we see that polynomial interpolation overcomes most of the problems of linear interpolation.

4. Spline Interpolation

The linear interpolation uses a linear function for each of intervals [xk,xk+1]. Spline interpolation uses low-degree polynomials in each of the intervals, and chooses the polynomial pieces such that they fit smoothly together. The resulting function is called a spline.

For instance, the natural cubic spline is piecewise cubic and twice continuously differentiable. Furthermore, its second derivative is zero at the end points.

5. Mimetic interpolation

A key feature of mimetic interpolation is that vector calculus identites are satisfied, including Stoke's theorem and the divergence theorem. As a result, mimetic interpolation conserves line, area and volume integrals.Conservation of line integrals might be desirable when interpolating the electric field, for instance, since the line integral gives the electric potential difference at the endpoints of the integration path.Mimetic interpolation ensures that the error of estimating the line integral of an electric field is the same as the error obtained by interpolating the potential at the end points of the integration path, regardless of the length of the integration path.

Linear, bilinear and trilinear interpolation are also considered mimetic, even if it is the field values that are conserved (not the integral of the field). Apart from linear interpolation, area weighted interpolation can be considered as one of the first mimetic interpolation method to have been developed

Here, we write a program to for the given laboratory experiment, wherein we read the file & interpolate the data to finally plot all the data on two graphs. We also store the interpolated data in a text file.

Linear interpolation:

We observe that for linear interpolation many of the points pass through the curve however, the goodness of fit is visibly poor. Hence we try another interpolation

Spline Interpolation:

We observe that for spline interpolation, most of the points lie on the curve & this interpolation has an emmaculate goodness of fit. Hence, the spline interpolation is precise & the solution is accurate.

vi=xlsread('VI');               %reading excel file
v=vi(:,1);                      %separating voltage value
i=vi(:,2);                      %separating current value 
xq=[-17.3:0.1:0.9];             %setting interpolation range
yq1=interp1(v,i,xq);            %linear interpolated value
yq2=interp1(v,i,xq,'spline');   %spline interpolated value

figure(1)
plot(v,i,'d',xq,yq1,':.');      %ploting linear interpolation
title('Linear interpolation');
xlabel('Voltage [V]');
ylabel('Current [I]');
legend('Actual value','Interpolated value','Location','NorthWest');
grid on;

figure(2)
plot(v,i,'d',xq,yq2,'m:.');
title('Spline interpolation');  %ploting spline interpolation 
xlabel('Voltage [V]');
ylabel('Current [I]');
legend('Actual value','Interpolated value','Location','NorthWest');
grid on;

val=fopen('vi.txt','w');                 %opening text file
fprintf(val,' Voltage    Current\n');
fprintf(val,'%3.3f    %3.3f\n',xq,yq2);  %writing voltage & current value
savefig(1,'vilinear.fig');               %saving linear interpolation graph
savefig(2,'vispline.fig');               %saving spline interpolation graph
fclose(val);

The text file data is as follows:

Voltage Current
-17.300 -17.200
-17.100 -17.000
-16.900 -16.800
-16.700 -16.600
-16.500 -16.400
-16.300 -16.200
-16.100 -16.000
-15.900 -15.800
-15.700 -15.600
-15.500 -15.400
-15.300 -15.200
-15.100 -15.000
-14.900 -14.800
-14.700 -14.600
-14.500 -14.400
-14.300 -14.200
-14.100 -14.000
-13.900 -13.800
-13.700 -13.600
-13.500 -13.400
-13.300 -13.200
-13.100 -13.000
-12.900 -12.800
-12.700 -12.600
-12.500 -12.400
-12.300 -12.200
-12.100 -12.000
-11.900 -11.800
-11.700 -11.600
-11.500 -11.400
-11.300 -11.200
-11.100 -11.000
-10.900 -10.800
-10.700 -10.600
-10.500 -10.400
-10.300 -10.200
-10.100 -10.000
-9.900 -9.800
-9.700 -9.600
-9.500 -9.400
-9.300 -9.200
-9.100 -9.000
-8.900 -8.800
-8.700 -8.600
-8.500 -8.400
-8.300 -8.200
-8.100 -8.000
-7.900 -7.800
-7.700 -7.600
-7.500 -7.400
-7.300 -7.200
-7.100 -7.000
-6.900 -6.800
-6.700 -6.600
-6.500 -6.400
-6.300 -6.200
-6.100 -6.000
-5.900 -5.800
-5.700 -5.600
-5.500 -5.400
-5.300 -5.200
-5.100 -5.000
-4.900 -4.800
-4.700 -4.600
-4.500 -4.400
-4.300 -4.200
-4.100 -4.000
-3.900 -3.800
-3.700 -3.600
-3.500 -3.400
-3.300 -3.200
-3.100 -3.000
-2.900 -2.800
-2.700 -2.600
-2.500 -2.400
-2.300 -2.200
-2.100 -2.000
-1.900 -1.800
-1.700 -1.600
-1.500 -1.400
-1.300 -1.200
-1.100 -1.000
-0.900 -0.800
-0.700 -0.600
-0.500 -0.400
-0.300 -0.200
-0.100 0.000
0.100 0.200
0.300 0.400
0.500 0.600
0.700 0.800
0.900 -28.000
-28.173 -24.000
-19.000 -15.869
-14.000 -12.235
-10.502 -9.000
-7.881 -7.106
-6.591 -6.251
-6.000 -5.767
-5.539 -5.316
-5.101 -4.893
-4.693 -4.503
-4.324 -4.156
-4.000 -3.857
-3.727 -3.608
-3.499 -3.399
-3.308 -3.223
-3.144 -3.070
-3.000 -2.933
-2.868 -2.806
-2.746 -2.689
-2.633 -2.580
-2.528 -2.478
-2.430 -2.383
-2.337 -2.292
-2.249 -2.206
-2.164 -2.122
-2.081 -2.041
-2.000 -1.960
-1.919 -1.879
-1.839 -1.800
-1.761 -1.722
-1.684 -1.647
-1.610 -1.574
-1.540 -1.506
-1.473 -1.441
-1.410 -1.380
-1.352 -1.325
-1.300 -1.276
-1.254 -1.233
-1.213 -1.194
-1.177 -1.161
-1.145 -1.130
-1.116 -1.103
-1.091 -1.078
-1.067 -1.055
-1.044 -1.033
-1.022 -1.011
-1.000 -0.989
-0.977 -0.966
-0.954 -0.942
-0.930 -0.917
-0.905 -0.892
-0.879 -0.867
-0.853 -0.840
-0.827 -0.813
-0.800 -0.786
-0.772 -0.759
-0.745 -0.730
-0.716 -0.702
-0.688 -0.673
-0.659 -0.644
-0.629 -0.615
-0.600 -0.585
-0.570 -0.556
-0.541 -0.526
-0.512 -0.498
-0.483 -0.470
-0.456 -0.443
-0.430 -0.417
-0.405 -0.394
-0.383 -0.372
-0.362 -0.353
-0.344 -0.336
-0.329 -0.322
-0.316 -0.311
-0.307 -0.304
-0.302 -0.300
-0.300 -0.301
-0.302 -0.304
-0.305 -0.306
-0.306 -0.305
-0.303 -0.298
-0.291 -0.281
-0.267 -0.251
-0.230 -0.205
-0.175 -0.140
-0.100 -0.056
-0.018 0.001
-0.000 0.000
0.013 0.170
1.230 10.043
39.070 101.110

Conclusion:

  1. Excel file was read in matlab and we performed linear and spline interpolation.
  2. After comparison of the two interpolation methods it was found that the spline interpolation is more accurate.
  3. Generated the plot of the interpolated data and saved the data in the text file.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.