Challenge

Project - Data Handling and Interpolation

AIM-

Performing Interpolation of Data and Generating the Interactive Plots.

OBJECTIVE-

1.Reading the laboratory experimented data from the excel file

2.extracting the data and stired it in the variables

3.Interpolating the data.

4.compute the value of current from the given voltage data.

5.then storing the resulted data in the text file.

PROGRAM -

For linear and spline interpolation-

data = xlsread("VI.xlsx")% excel file is read by xlsread command
v=data(:,1);% column 1 data is stored
i=data(:,2);%column 2 data is stored
vq=[-17.3:0.1:0.9] %interpolation range is defined
vq1=interp1(v,i,vq)%interpolating the data of v and i in range of vq
vq2=interp1(v,i,vq,'spline')% in spline form inter polation done
figure(1);
plot(v,i,'o',vq,vq1,':.');%plotting the interpolated data
grid; %griding done on plot
title('linear interpolation');%title giving to plot
xlabel('voltage');%x-axis named as voltage
ylabel('current');%y-axis named as current
legend('actual values','interpolated values','Location','best');% legends are marked
figure(2);
plot(v,i,'o',vq,vq2,':.');%plotting the interpolated data
grid;
title('spline interpolation');%title giving to plot
xlabel('voltage');%x-axis named as voltage
ylabel('current');%y-axis named as current
legend('actual values','interpolated values','Location','best');% legends are marked
val=fopen('vi.txt','w'); %opening text file
fprintf(val,' Voltage Current\n');%storing values
fprintf(val,'%4.3f %6.3f\n',vq,vq1); %writing voltage & current value
fclose(val);%closing text file

For linear interpolation using fine grid and cubic interpolation over fine grid -

[v,i]=meshgrid(-4: 4,-4:4);%meshgrid of v and i
z=i.*exp(v.^2-i.^2)% z is assigned with a fuction
figure(1);
surf(v,i,z);%plotting surf
title('original sampling');% title given to the plot
[vq1,iq1]=meshgrid(-17.3:0.1:0.9,-17.3:0.1:0.9);%meshgrid values defined
zq1=interp2(v,i,z,vq1,iq1)%interpolating the data
figure(2);
surf(vq1,iq1,zq1);%plotting surf
title('linear interpolation using finer grid');%title given to the plot
xlabel('voltage');%x-axis named as voltage
ylabel('current');%y-axis named as currentlegend('actual values','interpolated values','Location','best');% legends are marked
[vq2,iq2]=meshgrid(-17.3:0.1:0.9,-17.3:0.1:0.9);%%meshgrid values defined
zq2=interp2(v,i,z,vq2,iq2)%interpolating the data
figure(3);
surf(vq2,iq2,zq2);%plotting surf
title('cubic interpolation over finer grid');%title given to the plot
xlabel('voltage');%x-axis named as voltage
ylabel('current');%y-axis named as current
After running the program, results are shown below -
linear interpolation shown in below fiq.1
below fig,2 shows the plot for spline interpolation
output vq1 and vq2 are shown in the command window

Plot of Original sampling ,linear interpolation using finer grid and linear interpolation over finer grid are shown below

Output stored in txt file-
Program which is used to stored the output in text file and text file data are shown below

EXPLANATION-

By using xlsread function data is read and stored in the variable named as data as shown in the program.

First column data which is voltage is stored in variable v and second column data of current is stored in i are seperated by giving the command(:,1) and (:,2) as shown in the program.

Then the interpolation range which is given in the question id stored in the vq after that linear interpolation is done by using the 'intrep1()' command by providing the v,i and vq(interpolating range).then spline interpolation is carried out using 'interp1()'s specifies the spline interpolation method

The linear interpolation is plotted using the figure(1) command and plot command and interpolated data is also drawn in this plot by using vq and vq1 then grid is done by using the grid command.

Then title is given to the plot by using title() command and labelling of x- axis and y-axis is done by using the command xlabel() and ylabel() .

Legends command is give to distinguish the actual values and interpolated values in the plot and the location is selected as 'best' in the program which give the legends according to the plot behaviour.

Then figure(2) gives the spline interpolation plot by using the plot command which shows the interpolated values after that labelling of x- axis and y-axis are done by xlabel() and y-label command . Also legends are provided by using the legends() command.

The txt file vi.txt is opened in write mode shown as 'w' by giving fopen()command.Then by using fprintf() command the interpolated values after performing spline interpolation is saved in text file.

For performing linear interpolation using finer grid and cubic interpolation over finer grid , meshgrid is created as shown in the program whose variables are v and i. Then z is the variable having exponential term.By using surf() plotting the graphs showing the v,i and z values .This plot named as 'original sampling' by using title() command

As mentioned range in the question , vq1 and iq1 assigned the values by meshgrid and interpolation done by interp2() command. zq1 gives the interpolated data of v,i,z ,vq and iq.Then graph is plotted showing v,i and interpolated values by using surf()command.

Figure (2) shows the plot of linear interpolation under finer grid and figure(3) shows the plot of cubic interpolation over finer grid.In cubic interpolation the program is same as performed in linear interpolation in finer grid but the variables are changed as vq2 and iq2.Title,labels and legends are given as shown in the program.

CONCLUSION -

In this project, we learned the interpolation of data within specified range and generating the interactive plots for the interpolated data.

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.