Spline interpolation of input data

I would like to obtain a spline interpolation of the following input data contained in the attached txt file. I try to explain how this data needs to be interpolated by describing the txt file:
  • The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken. Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000) and the second goes from column 5 to 8 (Reynolds equal to 100000).
  • Each column of the two subtables contains the measurements of a specific variable. In particular, in column 1 there are the measurements of the variable "beta" at Re=60000, column 2 measurements of "CL" at Re=60000, column 3 measurements of "CD" at Re=60000, column 4 measurements of "eff" at Re=60000. Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
  • Due to the fact that the first row of the txt file contains the Re numbers, the columns of the afore listed variables all started from row number 2.
Plotting the trends of CL,CD and eff with respect to the relative beta, it can be noticed how closed the trend of the variables are and, therefore, I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables. Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same! Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3, maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4. Therefore, the spline interpolation needs to be consistent.
Thak you in advance for your help!!!

2 Comments

What have you attempted?
I simply wrote the code to read the file:
format long
clc;
clear all;
close all;
load Bruining_reviewed.txt;
polars=Bruining_reviewed;
beta_vect_60=polars(2:end,1);
CL_vect_60=polars(2:end,2);
CD_vect_60=polars(2:end,3);
eff_vect_60=polars(2:end,4);
beta_vect_100=polars(2:end,5);
CL_vect_100=polars(2:end,6);
CD_vect_100=polars(2:end,7);
eff_vect_100=polars(2:end,8);
I do not know how to correctly do the sline interpolation...

Sign in to comment.

 Accepted Answer

hello
check this
not even sure the spline option is really needed here . A basic linear interpolation is good for the job
clc
clearvars
% I would like to obtain a spline interpolation of the following input data contained in the attached txt file.
% I try to explain how this data needs to be interpolated by describing the txt file:
% The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken.
% Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000)
% and the second goes from column 5 to 8 (Reynolds equal to 100000).
%
% Each column of the two subtables contains the measurements of a specific variable.
% In particular, in column 1 there are the measurements of the variable "beta" at Re=60000,
% column 2 measurements of "CL" at Re=60000,
% column 3 measurements of "CD" at Re=60000,
% column 4 measurements of "eff" at Re=60000.
% Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
%
% Due to the fact that the first row of the txt file contains the Re numbers,
% the columns of the afore listed variables all started from row number 2.
% Plotting the trends of CL,CD and eff with respect to the relative beta,
% it can be noticed how closed the trend of the variables are and, therefore,
% I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables.
% Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same!
% Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3,
% maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4.
% Therefore, the spline interpolation needs to be consistent.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readmatrix('Bruining_reviewed.txt');
%% data at Re=60000,
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
%% data at Re=100000,
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
figure(1)
plot(beta1,CL1,beta1,CD1,beta1,EFF1);
hold on
plot(beta2,CL2,beta2,CD2,beta2,EFF2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample all the data on common new beta axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
new_CL1 = interp1(beta1,CL1,new_beta,'spline');
new_CD1 = interp1(beta1,CD1,new_beta,'spline');
new_EFF1 = interp1(beta1,EFF1,new_beta,'spline');
new_CL2 = interp1(beta2,CL2,new_beta,'spline');
new_CD2 = interp1(beta2,CD2,new_beta,'spline');
new_EFF2 = interp1(beta2,EFF2,new_beta,'spline');
figure(2)
plot(new_beta,new_CL1,new_beta,new_CD1,new_beta,new_EFF1);
hold on
plot(new_beta,new_CL2,new_beta,new_CD2,new_beta,new_EFF2);

11 Comments

Emilio Pulli
Emilio Pulli on 6 Dec 2021
Edited: Emilio Pulli on 6 Dec 2021
In this way you do not interpolate between the values of the same variable at Re=60k and Re=100k. The variables that you called "new_CL","new_CD","new_EFF" need to be a spline interpolation respectively between CL1 and CL2 at the same value of beta, CD1 and CD2 at the same value of beta, EFF1 and EFF2 at the same value of beta. Is it cleare now? Maybe, I was a bit confusionary in the description of the txt file before...
If I understand corretly , you need a 2D map of each data (CL, CD) vs beta (in one dimension) and vs Re (the 2nd dimension of the array)
check this update
now we interpolate the data vs beta and Re - here an example with 3 new values both for beta and Re
as we have only Re = 60,000 and Re = 100,000 values there is no need to do a spline for interpolate vs Re. This option works if you have at least 3 points of reference data
clc
clearvars
% I would like to obtain a spline interpolation of the following input data contained in the attached txt file.
% I try to explain how this data needs to be interpolated by describing the txt file:
% The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken.
% Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000)
% and the second goes from column 5 to 8 (Reynolds equal to 100000).
%
% Each column of the two subtables contains the measurements of a specific variable.
% In particular, in column 1 there are the measurements of the variable "beta" at Re=60000,
% column 2 measurements of "CL" at Re=60000,
% column 3 measurements of "CD" at Re=60000,
% column 4 measurements of "eff" at Re=60000.
% Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
%
% Due to the fact that the first row of the txt file contains the Re numbers,
% the columns of the afore listed variables all started from row number 2.
% Plotting the trends of CL,CD and eff with respect to the relative beta,
% it can be noticed how closed the trend of the variables are and, therefore,
% I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables.
% Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same!
% Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3,
% maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4.
% Therefore, the spline interpolation needs to be consistent.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readmatrix('Bruining_reviewed.txt');
%% data at Re=60000,
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
%% data at Re=100000,
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
figure(1)
plot(beta1,CL1,beta1,CD1,beta1,EFF1);
hold on
plot(beta2,CL2,beta2,CD2,beta2,EFF2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample (interp) all the data on common new beta data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
new_beta = [-2 0 5]'; % must be a row vector
new_CL1 = interp1(beta1,CL1,new_beta);
new_CD1 = interp1(beta1,CD1,new_beta);
new_EFF1 = interp1(beta1,EFF1,new_beta);
new_CL2 = interp1(beta2,CL2,new_beta);
new_CD2 = interp1(beta2,CD2,new_beta');
new_EFF2 = interp1(beta2,EFF2,new_beta');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample (interp) all the data on common new Re data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
my_Re = [70000 80000 90000]; % must be a col vector
for ci = 1:numel(new_beta)
my_CL(ci,:) = interp1([60e3 100e3],[new_CL1(ci) new_CL2(ci)],my_Re);
my_CD(ci,:) = interp1([60e3 100e3],[new_CD1(ci) new_CD2(ci)],my_Re);
my_EFF(ci,:) = interp1([60e3 100e3],[new_EFF1(ci) new_EFF2(ci)],my_Re);
end
Emilio Pulli
Emilio Pulli on 6 Dec 2021
Edited: Emilio Pulli on 6 Dec 2021
Soory man, I wrongly posed my question...I would like to smooth the trend of CL,CD against their beta angles so that I can smooth their original edgy trends. If you plot CL1 against beta1 and CD1 against beta1 (and the same for CL2 and CD2), you can immediately see some traits of the curves where there are some edgy slopes...I would like to approximate the whole trend with a curve "passing through" this edgy trends in order to obtain a smoother trend. Is it possible?
haha !
ok - the key word would have been "smoothing" rather than interpolating ...
but no problem , I wil survive and give you the code you want...
Emilio Pulli
Emilio Pulli on 6 Dec 2021
Edited: Emilio Pulli on 6 Dec 2021
Thank you man! Sorry for the misunderstanding! I will wait for your code, thank you for the patience!
check this :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readmatrix('Bruining_reviewed.txt');
%% data at Re=60000,
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
%% data at Re=100000,
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
figure(1)
plot(beta1,CL1,beta1,CD1,beta1,EFF1);
hold on
plot(beta2,CL2,beta2,CD2,beta2,EFF2);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample (interp) all the data on common new beta data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
% new_beta = [-2 0 5]'; % must be a row vector
new_CL1 = interp1(beta1,CL1,new_beta,'spline');
new_CD1 = interp1(beta1,CD1,new_beta,'spline');
new_EFF1 = interp1(beta1,EFF1,new_beta,'spline');
new_CL2 = interp1(beta2,CL2,new_beta,'spline');
new_CD2 = interp1(beta2,CD2,new_beta','spline');
new_EFF2 = interp1(beta2,EFF2,new_beta','spline');
%% smoothing %%
N = 8;
new_CL1 = smoothdata(new_CL1,'sgolay',N);
new_CD1 = smoothdata(new_CD1,'sgolay',N);
new_EFF1 = smoothdata(new_EFF1,'sgolay',N);
new_CL2 = smoothdata(new_CL2,'sgolay',N);
new_CD2 = smoothdata(new_CD2,'sgolay',N);
new_EFF2 = smoothdata(new_EFF2,'sgolay',N);
figure(2)
plot(new_beta,new_CL1,new_beta,new_CD1,new_beta,new_EFF1);
hold on
plot(new_beta,new_CL2,new_beta,new_CD2,new_beta,new_EFF2);
hold off
Can't I use simply this:
format long
clc;
clear all;
close all;
data = readmatrix('Bruining_reviewed.txt');
% data at Re=60000
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
% data at Re=100000
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample all the data on common new beta axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
new_CL1 = csaps(beta1,CL1,0.5,new_beta);
new_CD1 = csaps(beta1,CD1,0.5,new_beta);
new_EFF1 = csaps(beta1,EFF1,0.5,new_beta);
new_CL2 = csaps(beta2,CL2,0.5,new_beta);
new_CD2 = csaps(beta2,CD2,0.5,new_beta);
new_EFF2 = csaps(beta2,EFF2,0.5,new_beta);
figure (1)
plot(beta1,CL1,beta2,CL2,new_beta,new_CL1,new_beta,new_CL2,'LineWidth',1);
legend('60k','100k','spline 60k','spline 100k');
title('Lift coefficient');
xlabel('beta inf');
ylabel('Cl');
figure (2)
plot(beta1,CD1,beta2,CD2,new_beta,new_CD1,new_beta,new_CD2,'LineWidth',1);
legend('60k','100k','spline 60k','spline 100k');
title('Drag coefficient');
xlabel('beta inf');
ylabel('Cd');
hello
sure - I was about to search myself for an equivalent function of csaps - as I don't have the Curve Fitting Toolbox .
this is my result so far
code
clc
clearvars
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readmatrix('Bruining_reviewed.txt');
%% data at Re=60000,
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
%% data at Re=100000,
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
figure(1)
plot(beta1,CL1,beta1,CD1,beta1,EFF1);
hold on
plot(beta2,CL2,beta2,CD2,beta2,EFF2);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample (interp) all the data on common new beta data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
new_CL1 = interp1(beta1,CL1,new_beta,'spline');
new_CD1 = interp1(beta1,CD1,new_beta,'spline');
new_EFF1 = interp1(beta1,EFF1,new_beta,'spline');
new_CL2 = interp1(beta2,CL2,new_beta,'spline');
new_CD2 = interp1(beta2,CD2,new_beta','spline');
new_EFF2 = interp1(beta2,EFF2,new_beta','spline');
% %% smoothing %%
% N = 8;
% new_CL1 = smoothdata(new_CL1,'sgolay',N);
% new_CD1 = smoothdata(new_CD1,'sgolay',N);
% new_EFF1 = smoothdata(new_EFF1,'sgolay',N);
% new_CL2 = smoothdata(new_CL2,'sgolay',N);
% new_CD2 = smoothdata(new_CD2,'sgolay',N);
% new_EFF2 = smoothdata(new_EFF2,'sgolay',N);
% spline fit
order = 13;
new_CL1_sp = ppval(splinefit(new_beta,new_CL1,order,'r'),new_beta);
new_CD1_sp = ppval(splinefit(new_beta,new_CD1,order,'r'),new_beta);
new_EFF1_sp = ppval(splinefit(new_beta,new_EFF1,order,'r'),new_beta);
new_CL2_sp = ppval(splinefit(new_beta,new_CL2,order,'r'),new_beta);
new_CD2_sp = ppval(splinefit(new_beta,new_CD2,order,'r'),new_beta);
new_EFF2_sp = ppval(splinefit(new_beta,new_EFF2,order,'r'),new_beta);
figure(2)
plot(new_beta,new_CL1_sp,new_beta,new_CD1_sp,new_beta,new_EFF1_sp);
hold on
plot(new_beta,new_CL2_sp,new_beta,new_CD2_sp,new_beta,new_EFF2_sp);
hold off
Ok perfect, thank you! I will tale into consideration your method as alternatives to the one using csaps. Anyway your answer helped me to better tackle the problem!
My pleasure ! have a good day

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!