Calibration of non-linear relations

Calibration of non-linear relations#

Non linear relations of \(y = f(x)\)#

When we expect $\(y = ax^2 + bx + c\)\(, our task is to estimate \)a, b, c$ using the best-fit, i.e that coefficients that give us the smallest error between the the model and the measurements.

In any case, the easiest and most accurate fit is of a linear type - we know that the static sensitivity is our goal and it has a lot of usefuleness in the following measurements. Therefore we always look for the way to convert our non-linear relation to linear one and then perform best-fit or regression on the transformed variables.

\[ y = ax^2 + bx \to y/x = ax + b \]
\[ y = bx^a \to \log(y) = a \log(x) + \log(b) \]
\[ y = b\exp{ax} = be^{ax} \to \ln(y) = a\ln(x) + \ln(b) \]
%pylab inline
pylab.rcParams['figure.figsize'] = 10, 8 
pylab.rcParams['font.size'] = 16 

# read the data
import numpy as np
x = np.array([0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0]) # cm
y = np.array([0.4, 1.0, 2.3, 6.9, 15.8, 36.4, 110.1, 253.2]) # Volt
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
fig = figure()
plot(x,y,'o:')
xlim(-5,110)
ylim(-5,300)
xlabel('$x$ [cm]')
ylabel('$y$ [V]')
Text(0, 0.5, '$y$ [V]')
../_images/5cd50d18e6a28675c278e26a062ddeb32d666bcccea3208255c080055733ef48.png

Conclusion:#

  1. Obviously the result is non-linear and the best sensitivity we can get is between 20 and 40 cm, but not for small distances

  2. If the relationship is a known function and it’s a physically relevant one, we could use it to show that distance to voltage should be related as a power law and not really linearly. Let’s check the logarithmic scale, since we know that:

\(\log y = \log (bx^m) = \log b + m \log x \)

fig = figure()
loglog(x,y,'o:')
# xlim(-5,110)
# ylim(-5,300)
xlabel('$x$ [cm]')
ylabel('$y$ [V]')
Text(0, 0.5, '$y$ [V]')
../_images/b0c4b3217bf0ca0f241f5fd76e034685e3852fc043be8b9aeed57f42b61ea508.png

This result shows that the result is close to linear in the log-log space. Let’s do calibration in \(\log(x)\) and \(\log(y)\). It can be either \(\log\) or \(\log_{10}\)

fig = figure()
plot(log(x),log(y),'o:')
# xlim(-5,110)
# ylim(-5,300)
xlabel('$\log (x)$ [cm]')
ylabel('$\log (y) $ [V]')
Text(0, 0.5, '$\\log (y) $ [V]')
../_images/96f0ea39df2505d3733da19f2616e6f6fa247e387ac961ad50eae88022cbb0a0.png
# linear fit
p = polyfit(log10(x),log10(y),1)
p
array([ 1.21031575, -0.01252781])
# let's check the fit:
fig = figure()
yfit = 10**(p[0]*log10(x) + p[1])
plot(x,y,'o:',x,yfit,'rs--')
xlim(-5,110)
ylim(-5,300)
xlabel('$x$ [cm]')
ylabel('$y$ [V]')
Text(0, 0.5, '$y$ [V]')
../_images/753b7aa0bf2dc81d1369865bef70a9a9095a5c757ba19fb3b748e41700cba7d7.png

how do we measure?#

  1. measure the \(y\) [V], take a \(\log_{10}(y)\), estimate the \(\log_{10}(x) \) using the calibration curve:

\( \log_{10}(x) = (\log_{10}(y) + 0.0125)/1.21 \)

  1. Note that we can use this function in the full input scale and full output scale, take:

\(10^{\log_{10} (x)}\)

  1. The sensitivity of this function is:

\(K(x) = dy/dx = d/dx ( x^{1.2} ) = 1.2 x^{0.2} \)

fig = figure()
K = 1.21*x**0.21
plot(x,K,'o:',lw=2)
xlabel('$x$ [cm]')
ylabel('Sensitivity, K(x) ')
Text(0, 0.5, 'Sensitivity, K(x) ')
../_images/70baa66323891a18f667a74a44951b062138d527b893450efa288dd52c8f0cf0.png