Sei sulla pagina 1di 13

Introduction

Curve fitting is the process of constructing a curve, or mathematical function, that has the
best fir to a series of data points, possibly subject to constraints. Curve fitting can involve either
interpolation, where an exact fit to the data is required or smoothing, in which a “smooth”
function is constructed that approximately fits the data.
A related topic is regression analysis, which focuses more on questions of statistical
inference such as how much uncertainty is present in a curve that is fit to data observed with
random errors. Fitted curves can be used as an aid for data visualization, to infer values of a
function where no data are available, and to summarize the relationships among two or more
variables. Extrapolation refers to the use of a fitted curve beyond the range of the observed data
and is subject to a degree of uncertainty since it may reflect the method used to construct the
curve as much as it reflects the observed data.
There are two general approaches for curve fitting. First is that data exhibit a significant
degree of scatter. The strategy is to derive a single curve that represents the general trend of the
data. Second is that the data is very precise. The strategy is to pass a curve or a series of curves
through each of the points.
Commonly, in engineering two types of applications are encountered. First is trend
analysis. Predicting values od dependent variable , may include extrapolation beyond data points
or interpolation between data points. Second is hypothesis testing which is comparing existing
mathematical model with measured data.

1
1. Linear Model

Matlab Code
load data.mat
format long;

%retrieval of data from data.mat and assigning variables respectively


distance=distance(1,:);
receivedpower = receivedpower(1,:);
n=length(distance);
m=length(receivedpower);
total_d=sum(distance);
total_rp=sum(receivedpower);
mean_d=total_d/n;
mean_rp=total_rp/m;
square_d=sum(distance.^2);
square_rp=sum(receivedpower.^2);
sum_total=sum(distance.*receivedpower);
a1=((n*sum_total)-(total_d*total_rp))/((n*square_d)-total_d^2);
a0=(mean_rp-a1*mean_d);
a1
a0
ymean=mean(receivedpower);
St=sum((receivedpower-ymean).^2)
Sr=sum((receivedpower-a0-a1*distance).^2)
rsquare=(St-Sr)/St
a=a1;
b=a0;
a
b
y=(a1*distance)+a0;
plot(distance, y)
hold on
scatter(distance,receivedpower)
hold off
title('Linear Model')
xlabel('distance (m)');
ylabel('receivedpower (W)');

2
Figure 1 shows scaled graph pf linear model curve

Figure 2 shows the linear model curve without scaling

3
Figure 3 shows the values obtained from linear model

Figure 4 shows the values of coefficients obtained from linear model

4
2. Power Law Model

Matlab Code
load data.mat
format long;
%retrieval of data from data.mat and assigning variables respectively
distance=distance(1,:);
receivedpower = receivedpower(1,:);
log10_distance= log10(distance);
log10_receivedpower= log10(receivedpower);
n=length(log10_distance);
m=length(log10_receivedpower);
total_d=sum(log10_distance);
total_rp=sum(log10_receivedpower);
mean_d=total_d/n;
mean_rp=total_rp/m;
square_d=sum(log10_distance.^2);
square_rp=sum(log10_receivedpower.^2);
sum_total=sum(log10_distance.*log10_receivedpower);
a1=((n*sum_total)-(total_d*total_rp))/((n*square_d)-total_d^2);
a0=(mean_rp-a1*mean_d);
B2=a1;
A2=10^a0;
y=A2*distance.^B2;
figure(2)
scatter(distance, receivedpower)
hold on
plot(distance,y)
hold off
title('Power Law Model')
xlabel('distance (m)');
ylabel('receivedpower (W)');
a1
a0
ymean=mean(log10_receivedpower);
St=sum((log10_receivedpower-ymean).^2)
Sr=sum((log10_receivedpower-a0-a1*log10_distance).^2)
rsquare=(St-Sr)/St
a=10^a0;
b=a1;
a
b

5
Figure 5 shows the graph of power law model without scaling

Figure 6 shows the scaled down curve of power law model

6
Figure 7 shows the scaled down graph of power law model.

Figure 8 shows the values obtained from the power law model curve

7
Figure 9 shows the values of coefficients obtained from power law model

From Figure 9 we can see that the distance between the curve and the real data is small compared to
other type of curve. Hence power law model is preferred.

8
3. Saturation Growth Rate Model

Matlab Code
load data.mat
format long;
%retrieval of data from data.mat and assigning variables respectively
distance=distance(1,:);
receivedpower = receivedpower(1,:);
one_distance=1./distance;
one_receivedpower=1./receivedpower;
n=length(one_distance);
m=length(one_receivedpower);
total_d=sum(one_distance);
total_rp=sum(one_receivedpower);
mean_d=total_d/n;
mean_rp=total_rp/m;
square_d=sum(one_distance.^2);
square_rp=sum(one_receivedpower.^2);
sum_total=sum(one_distance.*one_receivedpower);
a1=((n*sum_total)-(total_d*total_rp))/((n*square_d)-total_d^2);
a0=(mean_rp-a1*mean_d);
a1
a0
A3=1/a0;
B3=a1*A3;
y=A3*(distance./(B3+distance));
ymean=mean(one_receivedpower);
St=sum((one_receivedpower-ymean).^2)
Sr=sum((one_receivedpower-a0-a1*one_distance).^2)
rsquare=(St-Sr)/St
figure(3)
scatter(distance, receivedpower)
hold on
plot(distance,y)
hold off
title('Saturation Growth Rate Model')
xlabel('distance (m)');
ylabel('receivedpower (W)');
a=1/a0;
b=a*a1;
a
b

9
Figure 10 shows the curve of saturation growth rate model

Figure 11 shows the scaled down curve of saturation growth rate model

10
Figure 12 shows the results obtained from saturation growth rate model

Figure 13 shows the value of coefficients obtained from saturation growth rate model.

11
Discussion
For all the three selected models a1 and a0 had been calculated using the formula:
𝑛∑𝑥𝑖 𝑦ⅈ − ∑𝑥𝑖 ∑𝑦ⅈ
𝑎1 =
𝑛𝛴𝑥𝑖2 − (𝛴𝑥𝑖 )2
𝑎0 = 𝑦̅ − 𝑎1 𝑥̅
Where 𝑦̅ and 𝑥̅ are mean of y values and x values respectively.
Calculation of 𝒓𝟐
𝑟 2 has been calculated as a measure of the goodness of fit of the curve.
𝑛 𝑛 𝑛

𝑆𝑡 = ∑(𝑦𝑖 − 𝑦̄ ) 2
𝑆𝑟 = ∑ 𝑒𝑖2 = ∑(𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 )2
𝑖=1 𝑖=1 𝑖=1

St is the total sum of the squares around the mean for the dependent variable, y.
Sr is the sum of the squares of residuals around the regression line.
St - Sr quantifies the improvement or error reduction due to describing data in terms of a straight
line rather than as an average value. Hence,
𝑆𝑡 − 𝑆𝑟
𝑟2 =
𝑆𝑡
𝑟 2 is known as the coefficient of determination.

1. Linear model
Equation for linear model is 𝑦 = 𝑎𝑥 + 𝑏.
Since 𝑎1 and 𝑎0 has been related to the linear model equation to obtain the values of a and b.
The general equation is y=a0+a1x . Hence 𝑎0 = 𝑏 𝑎𝑛𝑑 𝑎1 = 𝑎
𝑎 = −6 ⋅ 35 × 10−6
𝑏 = 0.0043
The value of 𝑟 2 calculated is 0.0416.
𝑦 == −6 ⋅ 35 × 10−6 𝑥 + 0.0043

12
2. Power Law Model
Equation for power law model is 𝑦 = 𝑎𝑥 𝑏 .
𝑎1 and 𝑎0 has been related to the power law model equation to obtain the values of a and b.
The general equation is 𝑙𝑜𝑔 𝑦 = 𝑎0 + 𝑎1 𝑙𝑜𝑔 𝑥. Hence 𝑎 = 10𝑎0 𝑎𝑛𝑑 𝑏 = 𝑎1
𝑎 = 30.221
𝑏 = −2.396
The value of 𝑟 2 calculated is 0.9244.
𝑦 = 30.221𝑥 −2.396
3. Saturation Growth Rate model.
𝑥
Equation for saturation growth rate model is 𝑦 = 𝑎 𝑏+𝑥.

𝑎1 and 𝑎0 has been related to the power law model equation to obtain the values of a and b.
1 1
The general equation is 𝑦 = 𝑎0 + 𝑎1 𝑥. Hence 𝑎 = 1⁄𝑎0 𝑎𝑛𝑑 𝑏 = 𝑎1 𝑎

𝑎 = 4.604 × 10−6
𝑏 = −33.374
The value of 𝑟 2 calculated is 0.0735.
𝑥
𝑦 = 4.604 × 10−6
−33.374 + 𝑥

Determining the most suitable mathematical model to represent the data.


𝑟 2 gives the percentage variation in y explained by x-variables. The range is 0 to 1. It gives an
idea of how many data points falls within the results of the line formed by the mathematical
models. The higher the coefficient, the higher percentage of points the line passes through when
the data points and line are plotted. A higher coefficient is an indicator of a better goodness of fit
for the observations.
Hence, the power law model has the highest 𝑟 2 value. Which is 0.9244. This means that 92.44%
of the points fall within the plotted line. Power Law Model is the most suitable mathematical
model to represent the data.
Conclusion
Coefficient of determination, 𝑟 2 shows the goodness of fit of the curve on the data points. Power
Law Model is chosen to create a path loss model.

13

Potrebbero piacerti anche