Challenge

Project - Data Handling and Interpolation

AIM OF PROJECT:-

In a laboratory experiment, data of voltage and current has been recorded and the same is attached in an excel file ( Click on this link VI.xlsx ). 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.

Key Highlights:

  • Graphical solutions are more visual and appealing
  • Interpolation of data
  • Read excel file
  • Write to text file

Deliverables:

  • Find missing data and save it in text
  • Interpolate the data set
  • Save your program and attach the same.
  • Save txt file and upload in attachment

PROGRAM SOLUTION:-

1.Interpolation

Interpolation is a useful Mathematical and Statistical tool that is used to estimate values between any two given points.

  • Interpolation can be defined as the process of finding a value between two points on a line or curve.

  • Now to help us remember what it means, we should think of the first part of the word, which is 'inter,' and which means 'enter,' and that reminds us to look 'inside' the data we originally had.

  • Interpolation is a tool which is not only useful in Statistics, but is a tool that is also useful in the field of science, business or any time whenever there is a need to predict values that fall within any two existing data points.

  • MATLAB Functiions used for Interpolation are interp1 and interp2.
  • interp1 is a 1Dimensional Interpolation for ex:- tempvstime, tempvsday
  • interp2 is a 2Dimensional Interpolation
  • In Engineering Applications, there are situations where x data may be available and y data may not be available or there may be some missing data between x and y, so Interpolation can be used to determine those values.

In this Project values are plotted by using Linear Interpolation and Spline Interpolation.

2. LINEAR INTERPOLATION

Linear interpolation is a form of interpolation, which involves the generation of new values based on an existing set of values. Linear interpolation is achieved by geometrically rendering a straight line between two adjacent points on a graph or plane. All points on the line other than the original two can be considered interpolated values.

PROGRAM CODE

fileid1=xlsread('VI'); %Excel file Read from this command
V = fileid1(:,1); %Variable V defined from Excel file and seperated
I = fileid1(:,2); %Variable I defined from Excel file and seperated
VV = [-17.3:0.1:0.9]; %Interpolation Range Defined as per Question
VV1 = interp1(V,I,VV); %Using Interpolation Command and storing data in VV1
VV2 = interp1(V,I,VV,'spline'); %Using Spline Interpolation
figure(1);
plot(V,I,'o',VV,VV1,':.'); %Graph Plotted
grid;
xlabel('Voltage'); ylabel('Current'); %Labelled X-axis and Y-axis
title('Linear Interpolation(VoltagevsCurrent)');
legend('Actual Value', 'Interpolated value');
figure(2);
plot(V,I,'o',VV,VV2,'r-.');
grid;
xlabel('Voltage'); ylabel('Current');
title('Spline Interpolation(VoltagevsCurrent)');
legend('Actual Value', 'Spline Interpolated value');
fileid = fopen('Interpolationoutput.txt','w'); %Text File opened in written mode
fprintf(fileid,' Voltage Current\n');
fprintf(fileid,'%4f %4f\n',VV,VV1); % Storing the interpolation data in txt file
fileid2 = fopen('Spline Interpolationoutput.txt','w'); %Text File opened in written mode
fprintf(fileid2,' Voltage Current\n');
fprintf(fileid2,'%4f %4f\n',VV,VV2); % Storing the Spline interpolation data in txt file

fclose(fileid);
fclose(fileid2);

VIunknown = [-17.2 -13 -11 -9 -6 -1 0.11 0.25 0.5 0.61 0.66]'; %Voltage Value from Sheet 2 of excel file VI.xlsx
IS1 = interp1(V,I,VIunknown);
figure(3);
plot(V,I,'o',VIunknown,IS1,'-.');
grid;
xlabel('Voltage'); ylabel('Current');
legend('Actual Value', 'Interpolated value');
fileid3 = fopen('VIunknown calculated output.txt','w'); %Text File opened in written mode
fprintf(fileid3,' Voltage Current\n');
fprintf(fileid3,'%4f %4f\n',VV,IS1); % Storing the interpolation data in txt file
fclose(fileid3);

OUTPUT:-

program.m file attached as interpolation.m and 3 text files attached

Program Code

WORKSPACE VARIABLES

Linear Interpolation Graph in which actual values and interpolated values of voltage and current are plotted.

Spline Interpolation Graph in which actual values and interpolated values of voltage and current are plotted.

Current value plotted by interpolation with only voltage value available

Output Saved in .txt file

SUMMARY OF THE CODE:-

  • First the variable fileid1 is created to read the given excel file VI.xlxs.
  • Variable V (Voltage) is created to extract or separate the voltage data from excel file.
  • Similarly Variable I (Current) is created to extract or separate the current data from excel file.
  • Then the interpolation range is defined as per the given question in Variable VV.
  • Linear Interpolation is plotted by using command interp1() in which Variable V,I and VV interpolation range is entered and output is stored in variable VV1.
  • Similarly Spline Interpolation is plotted by using command interp1() in which Variable V, I and VV i.e interpolation range and Spline command is entered and output is stored in variable VV2.
  • figure(1) command is entered to generate the figure and plot(' ') command is used to plot the graph between the given interpolation range.
  • The graph generated is by using Linear Interpolation method.
  • 'xlabel()' and 'ylabel()' commands are used to give the name to X-axis and Y-axis.
  • 'title()' command is used to give name to the graph and 'legend()' command is used to differentiate between the actual values and the interpolated values.
  • Similarly figure(2) is generated and graph is plotted using 'plot()' command to plot the graph for Spline Interpolation.
  • fileid = fopen('Interpolationoutput.txt','w'); command is used to open the file in text mode.
  • 'fprintf()' command is used to store the interpolated data into text file.
  • Here 2 .txt files are saved one for linear interpolation and 2nd for Spline Interpolation.
  • Data from Sheet 2 of VI.xlsx loaded int o worksapce which has only Voltage values as variable named VIunknown.
  • Linear Interpolation is plotted by using command interp1() in which Variable V,I and VIunknown is entered and output is stored in variable IS1.
  • The graph generated is by using Linear Interpolation method in which missing data of current is plotted.
  • 'fopen()' and 'fprintf()' command is used to open .txt file and save the output of IS1 in .txt 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.