# How to calculate a correction factor for two sensors

Suppose one has two sensors placed in the same environment (thus should be reading the same environmental data). But not being perfect instruments, there is a discrepancy between the two sets of numbers.

Sensor 1   Sensor 2
1         1
2         1.9
3         2.7
2         2
2         1.9
3         3
2         1.8
1         1
2         2
3         2.8


How does one calculate a correction factor between these two sets of numbers. The hope being that this first set of data could be a calibration set. Then (knowing the sensors are off) one could then move the sensors to different environments and record a new set of data.

S1      S2
1   10
2   12
3   13
4   15
5   15
6   16
7   17
8   19
9   19
10  20


and then apply a correction factor (based on the initial calibration) to the new data to account for the discrepancy between instruments.

-
First, when you do your calibration you should try to cover the same range of readings that you will need to cover in the actual measurement. In this case, you want the calibration to cover the range 1 to 10 (or maybe 1 to 20), not just 1 to 3. If you can't do this, your calibration involves extrapolation and is likely to not be very accurate over the whole range where you need it. –  The Photon Aug 9 '12 at 0:05
Second, the relationship between readings on S2 and S1 seems to be different in the second environment than it was in the first environment. Or do you actually have 3 environments: E1 for calibration, E2 where S1 is used for measurements, and E3 where S2 is used for measurements? –  The Photon Aug 9 '12 at 0:06
Good points- I made up the numbers for sake of the question, but in reality they ranges would be similar. And yes- there would be three environments. 1 for the calibration between the sensors- and then 2 separate environments for measurments –  Victer Ville Aug 9 '12 at 0:08
The two word answer is "linear regression", but hopefully someone will have time to give you a more complete response. –  The Photon Aug 9 '12 at 0:11
A man with a watch always knows what time it is. A man with two watches is never sure. –  gbarry Aug 9 '12 at 0:12
show 1 more comment

If you have some reason to believe there is a simple relationship between the reading on one sensor and on the other, you can use linear regression to estimate the parameters of that relationship based on a calibration measurement like you suggest.

For example, if are measuring a parameter V, using sensors "1" and "2", and you think the only difference between these sensors is that signal conditioning circuits in these sensors have different gain and offset terms, you would guess at a model like

$V_2 = a + bV_1$.

Or, if the first sensor is a carefully calibrated instrument and sensor 2 is something you've built yourself, you might also think there's some nonlinearity in the response of sensor 2. Then you might guess a model like

$V_2 = a + bV_1 + cV_1^2$.

Notice that linear regression doesn't require the relationship between the two V's to be linear --- it only requires that one V be expressed as a linear combination of other observable values (in this case, each of these values being some function of $V_1$).

You can find formulas for linear regression at Wikipedia or any first-year statistics textbook (see the Wikipedia article on Simple Linear Regression to get the formulas written out rather than in matrix notation). These sources also clarify some additional requirements for your calibration measurement that are necessary for the standard linear regression formulas to provide an optimal least squares estimate of the true relationship.

For the simple case of a straight-line fit, you may get a result like this:

This chart shows the observations (points), the fit line, and 95% confidence intervals (dashed lines). The confidence intervals indicate the region where, if you were to repeat the calibration measurement multiple times, the calculated fitting line would lie 95% of the time.

Notice that the confidence intervals diverge from the fitting line on either end, outside the range of the observations. Because of this divergence, its much preferable for the calibration measurement to cover the same range as the actual measurements.

Edit

1. I should point out that one of the limitations of regression analysis is that the $V_1$ values in your calibration measurement should be noise-free. If sensor 1 is a more precise sensor than sensor 2, or if it can be operated in a low-noise mode (maybe with a slower input filter, or averaging multiple readings) this might be a reasonable assumption.

If it's not reasonable to assume sensor 1 is noise-free, then linear regression will still very likely get you a reasonable result. But if you want to check against a statistically more correct method, you'll need to look in to total least squares regression.

2. Geometrikal has it right in the comments. Having done your calibration, when you later make a measurement with sensor 2 and you want to know what sensor 1 would have measured, you have to invert your model. For the simple linear model you have

$V_1 = (V_2 - a) / b$.

-
Thanks for the answer. I've been using a linear regression, but maybe I'm not sure how to apply the regression analysis to the second group of numbers. If I run a simple regression I get a formula V2=0.9163V1 + 0.0857. My question is that (for the second group of numbers) I am not looking to calculate V2 based solely on V1. For this second group the sensors are in two different environments so I'm looking to take a correction factor based on the calibration, but applied to V2. –  Victer Ville Aug 9 '12 at 5:11
To be more specific- If I trust S1 more than S2- I will want to apply the regression equation from the calibration to the values in S2. So for the second group of numbers, I can leave S1 as is. But I need to adjust the numbers in S2 based on the calibration factor (not replace based on the regression equation) –  Victer Ville Aug 9 '12 at 5:15
@VicterVille The calibration problem! If you trust S1 more than S2, then S1 becomes your x values and S2 becomes your y values for the regression. After regression you get S2 = m*S1 + c. Now you invert this to get S1 = (S2 - c)/m. That is your calibration equation. –  geometrikal Aug 9 '12 at 12:17
I apologize if I am missing something basic. But I am concerned that if I use these equations to change the value of S2, I am loosing all the raw sensor information from S2. In the second example, S1 and S2 are in different environments, so I can't use the equation S2=m*S1 + C to calculate S2 as I've lost all reference to the original S2 data. I was hoping to find an equation for S2 that includes the original relationship between the two sensors (from the calibration phase), but includes the actual data from S2. –  Victer Ville Aug 9 '12 at 16:55
Something like S2= S2*(correction factor) as the final equation must reference S2 as well as the correction factor. Thanks! –  Victer Ville Aug 9 '12 at 16:55