Challenge

Project - Data Handling and Interpolation

Answer:-

Code :-

% Project - Data Handling and Interpolation


% Read excel file


clc
clear
close all
v=xlsread('VI.xlsx','a2:a25'); % Read Voltage data from excel file 'VI.xlsx'
i=xlsread('VI.xlsx','b2:b25'); % Read Current data from excel file 'VI.xlsx'

vi=(-17.3:0.1:0.9); %Interpolation Range as defined (-17.3:0.1:0.9)

%Interpolation of data

vi1=interp1(v,i,vi,'linear'); % Linear interpolation
vi2=interp1(v,i,vi,'spline'); % Spline interpolation
vi3=interp1(v,i,vi,'pchip'); % cubic interpolation

figure(1);
plot(v,i,'b*',vi,vi1,'r-'); % To plot Linear interpolation
xlabel('v')
ylabel('i')
grid; % to add grid to the plot
title('Linear interpolation');


figure(2);
plot(v,i,'b*',vi,vi2,'r-'); % To plot Spline interpolation
xlabel('v')
ylabel('i')
grid; % to add grid to the plot
title('spline interpolation');

figure(3);
plot(v,i,'b*',vi,vi3,'r-'); % To plot Cubic interpolation
xlabel('v')
ylabel('i')
grid; % to add grid to the plot
title('cubic interpolation');


% compute the current values for given voltages VV %

p = polyfit(v,i,5); % TO make a 5th order polynomial fit to this v,i data
vv=xlsread('VI.xlsx','sheet2!a1:a15'); % reading the Volatage (VV) Values provides
yi=polyval(p,vv); % evaluate the fitting polynomial on the VV grid.
figure(4);
plot(v,i,'b*',vv,yi,'r-'); % To plot VV and yi
legend('VI Data','VV Fitdata')
xlabel('v')
ylabel('i')
grid; % to add grid to the plot
title('Current Values for Values of Voltages ');

% Write to text file .


fid = fopen('Current_value.txt','w'); % Create Current_value.text file
len = length(j);
for j=1:len
fprintf(fid,'%d\n',yi); %Write the yi current value to the text file
end
fclose(fid);

Result:-

Computed value of Current is:-

-24.9837
-22.0939
-3.4828
-3.5905
-3.5652
-3.2829
-1.6131
-0.4803
-1.5083
-1.5507
-0.5883
-0.5138
-0.1038
1.0462
1.7573

The Same is ploted in the graph currentvalue_forVV. attached below.and is writen to the text file CurrentValue.text.

The required Interpolation Figure and Files are attached below.

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.