AN-1021: MMSE-Based Multipoint Calibration Algorithm for Touch Screen...

AN-1021
APPLICATION NOTE
One Technology Way • P.O. Box 9106 • Norwood, MA 02062-9106, U.S.A. • Tel: 781.329.4700 • Fax: 781.461.3113 • www.analog.com
MMSE-Based Multipoint Calibration Algorithm for Touch Screen Applications
by Ning Jia
INTRODUCTION
Modern devices typically use LCDs with touch screen
technology as user interfaces. Due to their simple construction
and well-known operation, resistive-type touch screens are the
most popular in cost-conscious designs. However, the mechanical
misalignments and scaling factors of resistive-type touch screens
affect the X and Y coordinates produced by the touch screens.
Therefore, it is difficult to perfectly align the coordinates of the
touch screen to the display (LCD or otherwise) behind it. When
the final product that includes a touch screen comes out of the
box, a calibration algorithm must first be done.
The classical calibration algorithm for a touch screen is a threepoint calibration algorithm that uses three reference points. The
classical three-point calibration algorithm is both efficient and
effective, but its performance is low when the touch screen is
comparatively large. This application note proposes the minimum
mean square error (MMSE)-based multipoint calibration algorithm,
which uses more than three reference points, for resistive-type
touch screens. Both mathematical deduction and experimentation
prove that this algorithm is more accurate than the classical threepoint calibration algorithm.
Rev. 0
Information furnished by Analog Devices is believed to be accurate and reliable. However, no
responsibility is assumed by Analog Devices for its use, nor for any infringements of patents or other
rights of third parties that may result from its use. Specifications subject to change without notice. No
license is granted by implication or otherwise under any patent or patent rights of Analog Devices.
Trademarks and registered trademarks are the property of their respective owners.
One Technology Way, P.O. Box 9106, Norwood, MA 02062-9106, U.S.A.
Tel: 781.329.4700
www.analog.com
Fax: 781.461.3113
©2009 Analog Devices, Inc. All rights reserved.
AN-1021
Application Note
TABLE OF CONTENTS
Introduction ...................................................................................... 1 Examples .........................................................................................7 Mathematics ...................................................................................... 3 Conclusion .....................................................................................8 Classical Three-Point Calibration Algorithm........................... 4 Code Implementation ...................................................................8 MMSE-Based Multipoint Calibration Algorithm .................... 4 Coding ............................................................................................9 Analysis for MMSE-Based Multipoint Calibration Algorithm
......................................................................................................... 6 References .................................................................................... 11 Steps for MMSE-Based Multipoint Calibration Algorithm.... 6 Rev. 0 | Page 2 of 12
Application Note
AN-1021
MATHEMATICS
Figure 1 shows a circle in red where its ideal center is O (origin)
and its ideal radius is R. Consider that the red circle represents
an image shown by the LCD under the touch screen. The blue
ellipse represents an exaggerated set of points produced by the
touch screen when the user traces the red circle shown by the
LCD. Therefore, the reconstructed image appears rotated,
translated, and scaled by a different factor in each axis because of
mechanical misalignments and scaling factors of resistive-type
touch screens. The challenge for the calibration algorithm is to
translate the set of coordinates reported by the touch screen into a
set of coordinates that accurately represent the displayed image.
To make the analysis easy to understand, assume that P’(x’, y’)
are the coordinates directly produced by the touch screen, and
its equivalent representation in polar coordinates is P’(Rcos θ0,
Rsin θ0). In addition, assume that the corresponding ideal
coordinates of P’(x’, y’) are P(x, y). Because of the relationship
between P’(x’, y’) and P(x, y), it is reasonable to get the following:
P(x, y) = P(KXRcos(θ0 + θ) + TX, KYRsin(θ0 + θ) + TY)
According to the trigonometric function,
cos(θ0 + θ) = cosθ0 cosθ − sinθ0 sinθ
and
sin(θ0 + θ) = sinθ0 cosθ + cosθ0 sinθ
The following equations can then be obtained:
⎧x′ = Rcosθ0
⎨ ′
⎩ y = Rsinθ0
⎧x = K X Rcos(θ0 + θ ) + TX = K X R(cosθ0 cosθ − sin θ0 sin θ ) + TX
⎨
⎩ y = KY Rsin(θ0 + θ ) + TY = KY R(sinθ0 cosθ + cos θ0 sin θ ) + TY
P (x , y )
P(x, y)
And then,
⎧x = cosθK X x′ − sinθK X y′ + TX
⎨
⎩ y = cosθKY y′ + sinθK Y x′ + TY
O
O
where:
θ, KX, KY, TX, and TY are all constants.
Let:
cosθKX = KX1
08183-001
−sinθKX = KX2
TX = KX3
Figure 1. Errors in Touch Screen
sinθKY = KY1
If there is a point where its ideal coordinates are P(x, y), and the
coordinates produced by touch screen are P’(x’, y’). (Point P is
on the red circle, and that Point P’ is the corresponding point
on the blue ellipse.) Suppose that P’(x’, y’) could return to its ideal
coordinates, P(x, y), after it rotates by θ, is scaled by KX and KY in
each axis, and is translated by TX and TY in each axis. The purpose
of the calibration algorithm is to calculate the coefficients of θ,
KX, KY, TX, and TY. The coefficients can then be used to calibrate
the coordinates directly produced by the touch screen.
cosθKY = KY2
TY = KY3
Then the previous equations can be rewritten as
⎧x = KX1x′ + KX 2 y′ + KX 3
⎨
⎩ y = KY1x′ + KY2 y′ + KY3
These equations can be used to calibrate the P’(x’, y’) back to
P(x, y). There are three unknown coefficients in each equation
for either the X axis or the Y axis.
Rev. 0 | Page 3 of 12
AN-1021
Application Note
CLASSICAL THREE-POINT CALIBRATION
ALGORITHM
MMSE-BASED MULTIPOINT CALIBRATION
ALGORITHM
The previous analysis produces the calibration equation for
either the X axis or the Y axis. Each equation has three unknown
coefficients for either the X axis or the Y axis. Therefore, if the
information for the three irrelative reference points was available,
one can construct a linear system of equations and get the
solution for the unknown coefficients by solving the equations.
Using the coefficients calculated by the classical three-point
calibration algorithm, the three reference points can be calibrated
to the exact ideal position. However, for other points that are
not close to the reference points, the calibration performance is
not good enough, especially when the size of the touch screen is
comparatively large. The experimental result in the Examples
section also proves this problem. Therefore, consider using more
than three reference points to get the best calibration coefficients.
Assuming that the ideal coordinates of the three reference points
are (x0, y0), (x1, y1), and (x2, y2), and their corresponding sampled
coordinates are (x’0, y’0), (x’1, y’1), and (x’2, y’2), then the
equations for both the X axis and the Y axis are
⎧ x0 = KX1x′0 + KX 2 y0′ + KX 3
⎪
⎨ x1 = KX1x1′ + KX 2 y1′ + KX 3
⎪x = KX x′ + KX y′ + KX
1 2
2 2
3
⎩ 2
Assuming that there are N + 1 reference points (N + 1 > 3), whose
ideal coordinates are (x0, y0), (x1, y1), …, (xN, yN), and whose
corresponding sampled coordinates are (x’0, y’0), (x’1, y’1), …,
(x’N, y’N), then the equations are as follows:
⎧ x0 = KX1x′0 + KX 2 y0′ + KX 3
⎪ x = KX x′ + KX y′ + KX
⎪ 1
1 1
2 1
3
⎨
M
⎪
⎪x N = KX1x′N + KX 2 y′N + KX 3
⎩
and
⎧ y0 = KY1x0′ + KY2 y0′ + KY3
⎪
⎨ y1 = KY1x1′ + KY2 y1′ + KY3
⎪ y = KY x′ + KY y′ + KY
1 2
2 2
3
⎩ 2
and
⎧ y0 = KY1x′0 + KY2 y′0 + KY3
⎪ y = KY x′ + KY y′ + KY
⎪ 1
1 1
2 1
3
⎨
M
⎪
⎪ y N = KY1x′N + KY2 y′N + KY3
⎩
The equations can then be rewritten as matrix type:
⎡ x 0′
⎢
⎢ x 1′
⎢ x ′2
⎣
y 0′
y 1′
y ′2
1⎤ ⎡ KX 1 ⎤ ⎡ x 0 ⎤
⎥ ⎢ ⎥
⎥ ⎢
1⎥ • ⎢KX 2 ⎥ = ⎢ x 1 ⎥
1⎥⎦ ⎢⎣ KX 3 ⎥⎦ ⎢⎣ x 2 ⎥⎦
⎡ x 0′
⎢
⎢ x 1′
⎢ x ′2
⎣
y 0′
y 1′
y ′2
1⎤ ⎡ KY1 ⎤ ⎡ y 0 ⎤
⎥ ⎢ ⎥
⎥ ⎢
1⎥ • ⎢KY 2 ⎥ = ⎢ y 1 ⎥
1⎥⎦ ⎢⎣ KY3 ⎥⎦ ⎢⎣ y 2 ⎥⎦
Note that the number of equations in each equation system (N + 1)
is larger than the number of unknown coefficients (3).
and
The purpose is to then calculate the best calibration coefficients
to fit all the (N + 1) reference points. The method to get the best
coefficients is to follow the MMSE rule. This is why the algorithm
is called MMSE-based multipoint calibration algorithm.
The calibration coefficients, KX1, KX2, KX3, KY1, KY2, and KY3,
can then be calculated by solving the equations.
The results calculated by using the elimination method are as
follows:
Taking the X axis as an example, define an aim function
N
FX = ∑ (KX1xi′ + KX 2 yi′ + KX 3 − xi )2
i =0
where FX is the sum of the square error for the reference points.
Let k = ( x0′ − x′2 )( y1′ − y′2 ) − (x1′ − x′2 )( y0′ − y′2 ) , then
KX 1 =
(x 0 − x 2 )( y 1′ − y ′2 ) − (x 1 − x 2 )( y 0′ − y ′2 )
k
KX 2 =
(x 1 − x 2 )(x 0′ − x ′2 ) − ( x 0 − x 2 )(x 1′ − x ′2 )
k
KX 3 =
y ′0 (x ′2 x 1 − x 1′ x 2 ) + y 1′ ( x ′0 x 2 − x ′2 x 0 ) + y ′2 ( x 1′ x 0 − x ′0 x 1 )
k
KY1 =
( y 0 − y 2 )( y 1′ − y ′2 ) − ( y 1 − y 2 )( y 0′ − y ′2 )
k
KY 2 =
( y 1 − y 2 )(x ′0 − x ′2 ) − ( y 0 − y 2 )(x 1′ − x ′2 )
k
KY3 =
y 0′ (x ′2 y 1 − x 1′ y 2 ) + y 1′ ( x ′0 y 2 − x ′2 y 0 ) + y ′2 ( x 1′ y 0 − x ′0 y 1 )
k
Rev. 0 | Page 4 of 12
Application Note
AN-1021
The best coefficients of KX1, KX2, and KX3 are the coefficients
that can minimize the aim function, FX. Therefore, the following
equations can be used:
The results calculated by using the elimination method are
as follows:
Let
⎧ ∂FX
=0
⎪
⎪ ∂KX1
⎪ ∂FX
=0
⎨
⎪ ∂KX 2
⎪ ∂FX = 0
⎪ ∂KX
3
⎩
that is
N
⎧ ∂FX
= ∑ 2 xi′(KX1xi′ + KX 2 yi′ + KX 3 − xi ) = 0
⎪
⎪ ∂KX1 i =N0
⎪ ∂FX
= ∑ 2 yi′(KX1xi′ + KX 2 yi′ + KX 3 − xi ) = 0
⎨
⎪ ∂KX 2 i =0
⎪ ∂FX = N 2(KX x ′ + KX y′ + KX − x ) = 0
∑
1 i
2 i
3
i
⎪ ∂KX
i =0
3
⎩
N
⎤
i =0
N
∑ yi′
i =0
N
2
∑ yi′
i =0
⎡ KX 1 ⎤
⎥
⎥
⎢
⎥
∑ yi′ ⎥ , KX = ⎢KX 2 ⎥ ,
i =0
⎢ KX 3 ⎥
⎥
⎦
⎣
N ⎥
⎦
i =0
N
∑ xi′ yi′ , b = ∑ yi′2
1
∑ xi′
∑ yi′
c0 =
∑ xi′xi
∑ xi′
, c1 =
∑ yi′xi
∑ yi′
d0 =
∑ xi′ yi
∑ xi′
, d1 =
∑ yi′ yi
∑ yi′
∑•
∑ xi′ yi′ ,
∑ yi′
∑ xi′
a2 =
, b2 =
, c2 =
N
∑ yi′
N
∑ xi
, d2 =
N
,
,
∑ yi
N
N
represents
∑•
i =0
⎡a 0
⎢
⎢ a1
⎢a 2
⎣
b2
1⎤ ⎡ KX 1 ⎤ ⎡c 0 ⎤
⎥ ⎢
⎥ ⎢ ⎥
1⎥ • ⎢KX 2 ⎥ = ⎢ c 1 ⎥
1⎥⎦ ⎢⎣ KX 3 ⎥⎦ ⎢⎣c 2 ⎥⎦
⎡a 0
⎢
⎢ a1
⎢a 2
⎣
b0
b1
b2
1⎤ ⎡KY 1 ⎤ ⎡d 0 ⎤
⎥ ⎢
⎥ ⎢ ⎥
1⎥ • ⎢ KY 2 ⎥ = ⎢ d 1 ⎥ ,
1⎥⎦ ⎢⎣ KY3 ⎥⎦ ⎢⎣d 2 ⎥⎦
b0
b1
and
Let
N
b0 =
, a1 =
The equation systems R • KX = BX and R • KY = BY can then
be rewritten as
N
N
N
⎧ N 2
⎪(∑ x i′ )KX 1 + (∑ x i′ y i′ )KX 2 + (∑ x i′ )KX 3 = ∑ x i′ x i
i =0
i =0
i =0
⎪ iN=0
N
N
N
⎪
2
′
′
′
′
x
y
KX
y
KX
y
KX
(
)
(
)
(
)
+
+
=
∑
∑
∑
∑ y i′ x i
⎨
1
2
3
i i
i
i
i =0
i =0
i =0
⎪ i =0 N
N
N
⎪
(∑ x i′ )KX 1 + (∑ y i′ )KX 2 + N ⋅ KX 3 = ∑ x i
⎪⎩
i =0
i =0
i =0
∑ xi′ yi′ ∑ xi′ ⎥
∑ x i′ 2
∑ x i′
where
These equations can be simplified as
⎡N 2
⎢ ∑ xi′
⎢ iN=0
R = ⎢∑ xi′ yi′
⎢i = 0
⎢ N
⎢ ∑ xi′
⎣ i =0
a0 =
⎡N
⎤
⎢ ∑ xi′xi ⎥
i =0
⎢N
⎥
BX = ⎢∑ yi′xi ⎥
⎢i = 0
⎥
⎢ N
⎥
⎢ ∑ xi ⎥
⎣ i =0 ⎦
It is easy to see that the equation systems have the same format
as the former equation systems for the classical three-point
algorithm:
The equations can then be rewritten in matrix type as R • KX = BX,
and the best coefficients, KX = R−1 • BX, can then be calculated
by solving the previous equations system.
Similar to the X axis, let
⎡ x ′0
⎢
⎢ x 1′
⎢ x ′2
⎣
y ′0
y 1′
y ′2
1⎤ ⎡ KX 1 ⎤ ⎡ x 0 ⎤
⎥ ⎢
⎥ ⎢ ⎥
1⎥ • ⎢KX 2 ⎥ = ⎢ x 1 ⎥
1⎥⎦ ⎢⎣ KX 3 ⎥⎦ ⎢⎣ x 2 ⎥⎦
⎡ x ′0
⎢
⎢ x 1′
⎢ x ′2
⎣
y 0′
y 1′
y ′2
1⎤ ⎡ KY1 ⎤ ⎡ y 0 ⎤
⎥ ⎢
⎥ ⎢ ⎥
1⎥ • ⎢KY 2 ⎥ = ⎢ y 1 ⎥
1⎥⎦ ⎢⎣ KY3 ⎥⎦ ⎢⎣ y 2 ⎥⎦
and
⎡N
⎤
⎢ ∑ xi′ yi ⎥
⎡ KY1 ⎤
i =0
⎢N
⎥
⎢
⎥
KY = ⎢KY2 ⎥ , BY = ⎢∑ yi′ yi ⎥
⎢i =0
⎥
⎢ KY3 ⎥
⎢ N
⎥
⎣
⎦
⎢ ∑ yi ⎥
⎣ i =0 ⎦
then the best coefficients for the Y axis, KY = R−1 • BY, can be
calculated by solving the equation system, R • KY = BY.
Rev. 0 | Page 5 of 12
AN-1021
Application Note
The same formula can then be used to calculate the results of
coefficients.
STEPS FOR MMSE-BASED MULTIPOINT
CALIBRATION ALGORITHM
Let
Complete the following steps for the MMSE-based multipoint
calibration algorithm:
k = (a0 − a 2 )(b1 − b2 ) − (a1 − a 2 )(b0 − b2 )
1.
Then
KX1 =
(c0 − c 2 )(b1 − b2 ) − (c1 − c 2 )(b0 − b2 )
k
KX 2 =
(c1 − c 2 )(a0 − a2 ) − (c0 − c 2 )(a1 − a2 )
k
KX 3 =
b0 (a2c1 − a1c 2 ) + b1(a0c 2 − a2c0 ) + b2 (a1c0 − a0c1 )
k
KY1 =
(d0 − d2 )(b1 − b2 ) − (d1 − d2 )(b0 − b2 )
k
KY2 =
(d1 − d2 )(a0 − a2 ) − (d0 − d2 )(a1 − a2 )
k
KY3 =
b0 (a2d1 − a1d 2 ) + b1 (a0d 2 − a2d0 ) + b2 (a1d0 − a0d1 )
k
2.
3.
ANALYSIS FOR MMSE-BASED MULTIPOINT
CALIBRATION ALGORITHM
By the a0, a1, a2; b0, b1, b2; c0, c1, c2; and d0, d1, d2 calculation, it is
clear that a0, a1, a2 can be treated as the weighted averages of x’i
by three different methods, and b0, b1, b2 can be treated as the
weighted averages of y’i by three different methods. Similarly, c0,
c1, c2 can be treated as the weighted averages of xi by three different
methods, and d0, d1, d2 can be treated as the weighted averages
of yi by three different methods.
4.
Because the final equation systems have the same format as the
previous equation systems for a classical three-point algorithm, the
algorithm-based MMSE rule can be consider as another threepoint algorithm. However, the difference in the MMSE-based
algorithm is that, instead of direct information of any reference
point being used, the weighted average information of the
reference points is used. That is, first calculate three weighted
average points (a0, b0), (a1, b1), (a2, b2) of N + 1 direct sampled
points (x’0, y’0), (x’1, y’1), …, (x’N, y’N). The corresponding ideal
coordinates of the three weighted average points are considered
(c0, d0), (c1, d1), and (c2, d2). The MMSE-based algorithm is then
equivalent to the classical three-point algorithm for these three
weighted average points.
Rev. 0 | Page 6 of 12
Select N +1 (N + 1 > 3) reference points (x0, y0), (x1, y1), … ,
(xN, yN).
Get the sampled coordinates of the reference points that
were produced by the touch screen, (x’0, y’0), (x’1, y’1), …,
(x’N, y’N).
Use the formulas given in this application note to calculate
the calibration coefficients, KX and KY. These include the
following:
k = (a0 − a 2 )(b1 − b2 ) − (a1 − a 2 )(b0 − b2 )
KX 1 =
(c 0 − c 2 )(b1 − b 2 ) − (c 1 − c 2 )(b0 − b 2 )
k
KX 2 =
(c1 − c 2 )(a0 − a2 ) − (c0 − c 2 )(a1 − a2 )
k
KX 3 =
b0 (a2c1 − a1c 2 ) + b1(a0c 2 − a2c0 ) + b2 (a1c0 − a0c1 )
k
KY1 =
(d0 − d2 )(b1 − b2 ) − (d1 − d2 )(b0 − b2 )
k
KY2 =
(d1 − d2 )(a0 − a2 ) − (d0 − d2 )(a1 − a2 )
k
KY3 =
b0 (a 2 d 1 − a 1 d 2 ) + b1 (a 0 d 2 − a 2 d 0 ) + b 2 (a 1 d 0 − a 0 d 1 )
k
In normal operation, use the calibration coefficients (KX,
KY) and the following equations to calculate the calibration
for point P’(x’, y’).
⎧x = KX1x′ + KX 2 y′ + KX 3
⎨
⎩ y = KY1x′ + KY2 y′ + KY3
Application Note
AN-1021
Three experiments follow that used the classical three-point
algorithm, MMSE-based five-point algorithm, and MMSE-based
nine-point algorithm:
EXAMPLES
1
2
3
•
5
6
7
8
9
•
08183-002
4
Figure 2. Selection of Reference Points
As shown in Figure 2, nine points were selected on the touchscreen. Their ideal coordinates are (3931, 3849), (2047, 3849),
(164, 3849), (3931, 2047), (2047, 2047), (164, 2047), (3931, 246),
(2047, 246), and (164, 246). The corresponding sampled
coordinates produced by the touch screen are (3927, 3920),
(2054, 3936), (193, 3943), (3911, 2119), (2054, 2127), (195,
2164), (3915, 331), (2050, 354), and (189, 371). Obviously,
there are very large errors between the ideal coordinates and
the corresponding sampled coordinates.
•
The classical three-point algorithm selects the three references
as Point 1, Point 6, and Point 8 in Figure 2. The calibration
coefficients are:
KX1 = +1.011238, KX2 = −0.003952, and KX3 = −24.638760
KY1 = +0.009894, KY2 = +1.005168, and KY3 = −130.112700
By using the previous coefficients, the results after calibration
are listed in Table 1.
The MMSE-based five-point algorithm selects the five
references as Point 1, Point 3, Point 5, Point 7, and Point 9
in Figure 2. The calibration coefficients are:
KX1 = +1.009899, KX2 = −0.002260, KX3 = −23.715720
KY1 = +0.008494, KY2 = +1.006247, KY3 = −121.821000
By using the previous coefficients, the results after calibration
are listed in Table 2.
The MMSE-based nine-point algorithm, selects the nine
references as Point 1, Point 2, Point 3, Point 4, Point 5,
Point 6, Point 7, Point 8, and Point 9 in Figure 2. The
calibration coefficients are:
KX1 = +1.011161, KX2 = −0.001887, KX3 = −25.777180
KY1 = +0.009718, KY2 = +1.006107, KY3 = −126.258100
By using the previous coefficients, the results after calibration
are listed in Table 3.
Table 1. Results of the Classical Three-Point Algorithm
Point (X, Y)
Ideal Coordinates
Sampled Coordinates
Calibrated Coordinates
Error
Sum of Square Error
1
(3931, 3849)
(3927, 3920)
(3931, 3849)
(0, 0)
(276, 650)
2
(2047, 3849)
(2054, 3936)
(2037, 3846)
(−10, −3)
3
(164, 3849)
(193, 3943)
(155, 3835)
(−9, −14 )
4
(3931, 2047)
(3911, 2119)
(3922, 2039)
(−9, −8 )
5
(2047, 2047)
(2054, 2127)
(2044, 2028)
(−3, −19 )
6
(164, 2047)
(195, 2164)
(164, 2047)
(0, 0)
7
(3931, 246)
(3915, 331)
(3933, 242)
(+2, −4 )
8
(2047, 246)
(2050, 354)
(2047, 246)
(0, 0)
9
(164, 246)
(189, 371)
(165, 244)
(+1, −2)
Table 2. Results of the MMSE-Based Five-Point Algorithm
Point (X, Y)
Ideal Coordinates
Sampled Coordinates
Calibrated Coordinates
Error
Sum of Square Error
1
2
3
4
5
6
7
8
9
(3931, 3849)
(3927, 3920)
(3933, 3856)
(2, 7)
(159, 418)
(2047, 3849)
(2054, 3936)
(2042, 3856)
(−5, +7)
(164, 3849)
(193, 3943)
(162, 3847)
(−2, −2 )
(3931, 2047)
(3911, 2119)
(3921, 2044)
(−10, −3 )
(2047, 2047)
(2054, 2127)
(2046, 2036)
(−1, −11)
(164, 2047)
(195, 2164)
(168, 2057)
(4, 10)
(3931, 246)
(3915, 331)
(3929, 245)
(−2, −1)
(2047, 246)
(2050, 354)
(2046, 252)
(−1, +6)
(164, 246)
(189, 371)
(166, 253)
(+2, +7)
Table 3. Results of the MMSE-Based Nine-Point Algorithm
Point (X, Y)
Ideal Coordinates
Sampled Coordinates
Calibrated Coordinates
Error
Sum of Square Error
1
2
3
4
5
6
7
8
9
(3931, 3849)
(3927, 3920)
(3938, 3856)
(7, 7)
(110, 363)
(2047, 3849)
(2054, 3936)
(2044, 3854)
(−3, +5)
(164, 3849)
(193, 3943)
(162, 3842)
(−2, −7)
(3931, 2047)
(3911, 2119)
(3925, 2044)
(−6, −3)
(2047, 2047)
(2054, 2127)
(2047, 2034)
(0, −13)
(164, 2047)
(195, 2164)
(167, 2053)
(3, 6)
(3931, 246)
(3915, 331)
(3932, 245)
(+1, −1)
(2047, 246)
(2050, 354)
(2046, 250)
(−1, +4)
(164, 246)
(189, 371)
(165, 249)
(+1,+3)
Rev. 0 | Page 7 of 12
AN-1021
Application Note
CONCLUSION
CODE IMPLEMENTATION
As shown in the results of the previous experiments, no matter
which calibration algorithm was used, the calibrated coordinates
are much better than the direct sampled coordinates. In addition,
by comparing these three experiments, it was concluded that
The code implementation of the calibration algorithm in
C language is shown in the Coding section. When there are
three reference points, the code implements the classical threepoint calibration algorithm. When there are more than three
reference points, the code implements the MMSE-based multipoint calibration algorithm. The code was tested with
the ADuC7026 (the ADuC7026 is an MCU product from
Analog Devices, Inc.). The results of the three example
experiments were calculated by this code.
•
•
•
The classical three-point calibration algorithm helps calibrate
the three reference points to the ideal position. In addition,
its performance is very good for the points close to the three
reference points. However, for the points not close to the
three reference points, the performance of the classical threepoint calibration is not good enough. The sum of the square
error for this algorithm was the largest of the three tested
algorithms. Therefore, the classical three-point calibration
algorithm is not a good choice for applications where touch
screen sizes are comparatively large.
For certain points (the points close to reference points),
the MMSE-based multipoint calibration algorithm has
worse performance than the classical three-point calibration
algorithm. However, when looking at the whole touch screen,
the MMSE-based multipoint calibration algorithm has a
smaller sum of square error than the classical three-point
algorithm because it uses the information of more than
three reference points. Therefore, its performance is better
than the classical three-point algorithm from a holistic view.
For the MMSE-based multipoint calibration algorithm, the
more reference points used, the better the performance is.
The results of these experiments are consentaneous with the
mathematics.
Rev. 0 | Page 8 of 12
Application Note
AN-1021
CODING
#define N
algorithm
9
// number of reference points for calibration
signed short int ReferencePoint[N][2];
// ideal position of reference points
signed short int SamplePoint[N][2];
// sampling position of reference points
double KX1, KX2, KX3, KY1, KY2, KY3;
// coefficients for calibration algorithm
void Do_Calibration(signed short int *Px, signed short int *Py) // do calibration for point
(Px, Py) using the calculated coefficients
{
*Px=(signed short int)(KX1*(*Px)+KX2*(*Py)+KX3+0.5);
*Py=(signed short int)(KY1*(*Px)+KY2*(*Py)+KY3+0.5);
}
int Get_Calibration_Coefficient()
algorithm: KX1, KX2, KX3, KY1, KY2, KY3
// calculate the coefficients for calibration
{
int i;
int Points=N;
double a[3],b[3],c[3],d[3],k;
if(Points<3)
{
return 0;
}
else
{
if(Points==3)
{
for(i=0; i<Points; i++)
{
a[i]=(double)(SamplePoint[i][0]);
b[i]=(double)(SamplePoint[i][1]);
c[i]=(double)(ReferencePoint[i][0]);
d[i]=(double)(ReferencePoint[i][1]);
}
}
else if(Points>3)
{
for(i=0; i<3; i++)
{
a[i]=0;
b[i]=0;
c[i]=0;
d[i]=0;
}
for(i=0; i<Points; i++)
Rev. 0 | Page 9 of 12
AN-1021
Application Note
{
a[2]=a[2]+(double)(SamplePoint[i][0]);
b[2]=b[2]+(double)(SamplePoint[i][1]);
c[2]=c[2]+(double)(ReferencePoint[i][0]);
d[2]=d[2]+(double)(ReferencePoint[i][1]);
a[0]=a[0]+(double)(SamplePoint[i][0])*(double)(SamplePoint[i][0]);
a[1]=a[1]+(double)(SamplePoint[i][0])*(double)(SamplePoint[i][1]);
b[0]=a[1];
b[1]=b[1]+(double)(SamplePoint[i][1])*(double)(SamplePoint[i][1]);
c[0]=c[0]+(double)(SamplePoint[i][0])*(double)(ReferencePoint[i][0]);
c[1]=c[1]+(double)(SamplePoint[i][1])*(double)(ReferencePoint[i][0]);
d[0]=d[0]+(double)(SamplePoint[i][0])*(double)(ReferencePoint[i][1]);
d[1]=d[1]+(double)(SamplePoint[i][1])*(double)(ReferencePoint[i][1]);
}
a[0]=a[0]/a[2];
a[1]=a[1]/b[2];
b[0]=b[0]/a[2];
b[1]=b[1]/b[2];
c[0]=c[0]/a[2];
c[1]=c[1]/b[2];
d[0]=d[0]/a[2];
d[1]=d[1]/b[2];
a[2]=a[2]/Points;
b[2]=b[2]/Points;
c[2]=c[2]/Points;
d[2]=d[2]/Points;
}
k=(a[0]-a[2])*(b[1]-b[2])-(a[1]-a[2])*(b[0]-b[2]);
KX1=((c[0]-c[2])*(b[1]-b[2])-(c[1]-c[2])*(b[0]-b[2]))/k;
KX2=((c[1]-c[2])*(a[0]-a[2])-(c[0]-c[2])*(a[1]-a[2]))/k;
KX3=(b[0]*(a[2]*c[1]-a[1]*c[2])+b[1]*(a[0]*c[2]-a[2]*c[0])+b[2]*(a[1]*c[0]a[0]*c[1]))/k;
KY1=((d[0]-d[2])*(b[1]-b[2])-(d[1]-d[2])*(b[0]-b[2]))/k;
KY2=((d[1]-d[2])*(a[0]-a[2])-(d[0]-d[2])*(a[1]-a[2]))/k;
KY3=(b[0]*(a[2]*d[1]-a[1]*d[2])+b[1]*(a[0]*d[2]-a[2]*d[0])+b[2]*(a[1]*d[0]a[0]*d[1]))/k;
return Points;
}
}
Rev. 0 | Page 10 of 12
Application Note
AN-1021
REFERENCES
Vidales, Carlos E. “How to Calibrate Touch Screens, Embedded Systems Design.” Embedded.com, May 31, 2002. Embedded Systems
Design. May 27, 2009.
Rev. 0 | Page 11 of 12
AN-1021
Application Note
NOTES
©2009 Analog Devices, Inc. All rights reserved. Trademarks and
registered trademarks are the property of their respective owners.
AN08183-0-7/09(0)
Rev. 0 | Page 12 of 12