The Application of Function Approximation Algorithm
in Magnetic Parking Detection
Liye Zhao and Yaojie Sun
School of Electronics and Information Engineering, Hebei University of Technology,
5340 Xiping Road, Beichen District, Tianjin, China
zhao_1829@163.com,sunyaojie@hebut.edu.cn
Keywords: Magnetic sensors, parking detection, CORDIC algorithm, digit-by-digit algorithm.
Abstract: In order to improve the accuracy of magnetic parking location detection, the microcontroller needs to use
transcendental function to exclude the parking interference of adjacent parking process. Because the
microcontroller does not contain hardware multipliers, the function approximation algorithm is introduced.
In this paper, the CORDIC algorithm and digit-by-digit algorithm are used to estimate the square root and
arccosine function in the process of magnetic data processing. Experiments show that after adding the
algorithm, the running time of the microcontroller is much less than the sampling interval of the sensor. The
experimental results prove that the algorithm can exclude the interference of adjacent parking process in real
time.
1 INTRODUCTION
In recent years, the problem of urban congestion and
air pollution is becoming more and more serious
with the rapid increase of vehicle volume. The
phenomenon of a low parking utilization rate has
attracted the attention of scholars. As a part of the
intelligent transportation system, the performance of
the parking detection system directly affects the
traffic congestion near the parking lot.
At present, there are a variety of methods to
realize vehicle parking detection. In the field of
image processing, the grayscale projection and first
derivative method were used to find the height of a
vehicle in one image and the status of multiple
parking spaces in one image can be judged (Choorat
et al 2017). In the ultrasonic detection field, there
were two ultrasonic sensors had been installed on
the same side of the entrance or the exit, when the
vehicle to enter or exit the parking lot then two
sensors were blocked at the same time, and the
number of idle parking spaces in the parking lot can
be obtained (Zadeh et al 2016). A detection system
based on RSSI (Received Signal Strength
Indication) had been proposed, in which the data
receiving node and data sending node were installed
on the top and bottom of each parking space
respectively, and the occupancy of parking space
was judged according to the received signal strength
(Li, 2016). In the field of magnetic detection, the
detection system was made up of magnetic sensors,
routing nodes and sink nodes. The magnetic sensor
realized parking detection, and its result was
transmitted from the routing node to the sink node
(Zhu, 2016).
By analyzing the environment of indoor and
outdoor parking lot, it can be found that using image
processing to detect parking space is convenient and
feasible. But the accuracy of detection is easily
disturbed by light conditions, shielding and other
environmental factors, and the cost of equipment is
high. The use of ultrasonic detection is low cost,
high accuracy and easy installation. However, its
detection results are affected by extreme weather
and will fluctuate with temperature changes. The
RSSI detection system requires the data receiving
node and data sending node to be arranged at the
upper and lower ends of the parking space, which is
not conducive to the application of the outdoor
parking lot. The magnetic sensor had the
characteristics of small volume, high sensitivity,
strong adaptability to bad environment and so on
(Qian et al 2009). It is widely used in parking lot
detection system.
There were fixed threshold algorithm, adaptive
threshold algorithm, state machine algorithm in
magnetic parking detection system (Zhang et al
450
Zhao, L. and Sun, Y.
The Application of Function Approximation Algorithm in Magnetic Parking Detection.
In 3rd International Conference on Electromechanical Control Technology and Transportation (ICECTT 2018), pages 450-454
ISBN: 978-989-758-312-4
Copyright © 2018 by SCITEPRESS Science and Technology Publications, Lda. All rights reserved
2013). The core of each detection algorithm is to
analyze and extract the characteristics of the change
of magnetic curve caused by the vehicle. The actual
magnetic field of parking detection was the
superposition of a variety of magnetic disturbance
vectors (Han et al 2009; Wu et al 2014). In this
paper, the parking interference of adjacent parking
process is analyzed, and the threshold detection
algorithm is supplemented.
2 INFORMATION PROCESSING
2.1 Information Acquisition
The information collection system of vehicle
parking space is composed of the superior computer
and the inferior machine. The inferior machine is
responsible for collecting data and transmitting it in
a wireless way to the superior computer.
The hardware block diagram of the collection
system is shown in Figure 1. The white one-way
arrow shows the direction of electric energy
transmission. The grey bidirectional arrow indicates
the direction of data transmission. STM8L151K4T6
is chosen as a microcontroller, because it has five
low power modes and a short start time as well as a
variety of available wake-up sources. The chip is
internally integrated with 16MHz and 38KHz two
kinds of clocks. Under working mode, the
appropriate working clock can be selected for CPU
and peripherals by programming the preset
frequency register, and the power consumption is
reduced while ensuring the execution efficiency. The
point-to-point communication module SKB360 is
chosen as the wireless module. It is a Bluetooth
transmission module for the Nordic scheme based on
nRF51822 and supports Bluetooth 4.0 BLE and
BR/EDR stack. The magnetic sensor uses Freescale's
MAG3110. It has a two working modes of the low
power consumption and three sampling axes, the
data rate and sampling ratio of the control register
can be configured to determine the data output rate.
TPS62110 is chosen as the power supply chip,
which is to realize stabilizing voltage by using a
PWM wave and its switching frequency of 1MHz,
compared to linear regulator chip which has higher
conversion efficiency. Its input voltage range of
3.1V to 17V, and the output voltage range of 1.2V to
16V. Its maximum output current of 1.5A, and the
typical quiescent current value 20uA.
2.2 Information processing
The magnetic sensor has three vertical sampling
axes, and the data on each axis are the components
of the magnetic disturbance vector. Compared with
the case of the adjacent vehicle and passing vehicles,
in which the parking detector are not covered by
vehicles, the angle of the covered parking detector
between the magnetic disturbance vector and the
vertical sampling axis of the sensor is larger(Chen et
al 2015). This feature can be used as the basis to
exclude the parking interference of adjacent parking
spaces. At present, the vehicle position detection
algorithm is based on the threshold detection.
Figure 1: The hardware block diagram of acquisition system.
The Application of Function Approximation Algorithm in Magnetic Parking Detection
451
In order to improve the accuracy of parking
detection, the angle calculation between the
magnetic disturbance vector and the vertical
sampling axis is added in threshold detection.
However, the microcontroller does not have the
hardware multiplier to calculate the floating-point
number and the transcendental function, then the
function approximation algorithm is introduced in
this paper.
Because of the high frequency interference in the
original data of the magnetic sensor, a sliding filter
is needed to eliminate the high frequency
interference first. The principle of sliding filtering is
shown as formula (1). The
s
k
is the original
magnetic data, the
rk
is the filtered data, and the
N is the length of the sliding filtering interval. The
intensity of the magnetic disturbance vector and the
angle between the magnetic disturbance vector and
the vertical sampling axis are shown by the formula
(2) and formula (3). In formula (2),

,,
i
ri xyz
is
the component of the magnetic vector on each axis,
and
r
is the strength of the magnetic vector. In
the formula (3), the calculation of the division and
the inverse cosine function is included in the process
of solving the angle.
The whole data processing is summarized as four
steps: sliding filtering, square root, division and
arccosine. In the next section, the function
approximation algorithm of microcontrollers to
process data can be introduced.



12
,
12
,
ss sk
kN
k
rk
sk N sk N sk
kN
N

 
(1)
222
xyz
r rrr
(2)
arccos
z
r
r




(3)
3 APPROXIMACTION
3.1 CORDIC Algorithm
The CORDIC (COordinate Rotation DIgital
Computer) algorithm, also known as Volder’s
algorithm, is an effective algorithm for calculating
hyperbolic functions and trigonometric functions. As
the only operations it requires are addition,
subtraction, bit-shift and table lookup, the algorithm
has a strong portability and high execution
efficiency. The estimation method of trigonometric
functions is described in this paper. The process to
estimate an inverse cosine function of a known value
is equivalent to estimate an angle between the vector
and the abscissa axis’s positive direction in the unit
circle, and the known value is abscissa of the vector.
The iterative schematic diagram of the CORDIC
algorithm is shown in Figure 2. The
0
v
is the initial
vector, and the coordinate rotation formula is shown
in formula (4). The
i
v
can be get after rotating
i-1
v
into
i
.In order to simplify the computational
complexity,
i
need to satisfy the formula (5). In
this way, the multiplication of the coordinate
rotation formula can be replaced by bit-shift. The
coefficients
i
K
in the coordinate rotation formula
are shown in formula (6),
i
and
i
K
can be recorded
in the table.



1
2
1tan
1
tan 1
1tan
i
ii
i
i
vv



(4)

tan 2
i
i
(5)

22
11
1tan 12
i
i
i
K


(6)
Figure 2: CORDIC algorithm iteration diagram.
ICECTT 2018 - 3rd International Conference on Electromechanical Control Technology and Transportation
452
3.2 Digit-by-digit Calculation
Digit-by-digit calculation is an efficient algorithm
for calculating square root. Compared with other
algorithms, the algorithm is applicable to any system.
Taking the decimal system as an example, the
detailed calculation steps of the algorithm are
summarized as follows:
(1) The square number be converted to decimal
form, and separate the digits into pairs, starting from
the decimal point and going both left and right.
Beginning with the left-most pair of digits
i
d , and
calculate the current value
i
c
based on the remainder
of the previous pair
1i
r
, in which
1
100
ii i
cr d
 ,and the initial remainder
0
0r
.
(2) Finding the largest integer
i
x
that satisfies the
inequality
20
iiii
px c
, and to figure out
20
ii ii
yx px
, the initial
1
0p .The
i
x
as a
digit of the root has been placed above the two digits
of the square
i
d . Then update the value of
i
p
,
1
10
ii i
pp x
.
(3) Updating the remainder
r ,
iii
rcy.
(4) To determine whether
i
r and
1i
d
are 0, if
both of them are 0, the iteration be stopped,
otherwise it returns to the first step.
4 EXPERIMENT
In this paper, the vector components of the magnetic
disturbance produced during the vehicle parking
process are collected by a large number of
experiments. The calculation of the sliding filter,
vector strength and vector angle of the magnetic data
is completed in the superior computer. By
comparing the magnitude of the angle between the
magnetic disturbance vector and the vertical
sampling axis generated during the neighboring
parking process and the parking process of covering
the sensor, we can determine the valid bits of the
threshold to exclude the interference brought by the
neighboring parking, and improve the accuracy of
threshold detection algorithm.
In the experimental process, the sampling rate of
the magnetic sensor MAG3110 is set to 80Hz. The
microcontroller approximate the computation result
of the superior computer by digit-by-digit algorithm
and CORDIC algorithm. The iteration ends when the
valid digits of the microcontroller’s output is equal
to the valid digits of the threshold. The operation
time of the algorithm in the microcontroller is
recorded to ensure that the microcontroller can
handle the data in real time. In the experiment, the
magnetic data acquisition interface of the superior
computer is shown in Figure 3. Figure 3 shows the
magnetic component curve processed by sliding
filter of the vehicle in and out of a parking space.
The collection personnel can set the range of the
filter interval through the interface, and observe the
magnetic component on each axis of the sensor in
real time, and intuitively analyze the magnetic curve
and save the effective magnetic experimental data.
Figure3: The acquisition interface of superior computer.
The Application of Function Approximation Algorithm in Magnetic Parking Detection
453
The experimental process of data acquisition is
shown in Figure 4. The experiment is to collect the
parking process of the covering sensor and the
adjacent vehicles respectively. After a lot of
experiments, it is concluded that the angle between
the magnetic vector and the vertical axis of the
sensor should be retained at least four valid digits to
identify whether it is the interference from adjacent
parking process. Microcontroller after receiving the
magnetic data through sliding average, square root,
division and arccosine several steps to obtain the
final angle, the whole process needs to consider the
accuracy and running time of the calculation. There
are three methods of calculation in the experiment,
and the retained valid digits in different stages is
different, as shown in Table 1. Microcontroller
system clock select 16 MHz, and the Method1s
running time is the fastest and far less than the
sampling interval of 12500us (80Hz). The
experimental results show that the magnetic data can
be processed in real time after adding the angle
calculation based on the existing threshold detection
algorithm.
5 CONCLUTIONS
Since the microcontroller does not have hardware
multipliers, in this paper, the digit-by-digit algorithm
and the CORDIC algorithm are used to complete the
estimation of the square root and the arccosine
function. The retained valid digits of the angle
threshold is determined by experiment. Experiments
show that after adding digit-by-digit algorithm and
CORDIC algorithm, the running time of micro-
controller is much shorter than the sampling interval
of sensors, it ensure that magnetic data are processed
in real time, and the accuracy of parking detection
can be improved.
The Inferior
Machine
The Neighboring
Parking
USB-UART
Bluetooth
Module
The Superior
Computer
Figure4: The experimental process.
Table 1: The valid digits and time of different methods.
Stages Method1 Method2 Method3
Slidin
g
filterin
g
43 2
S
q
uare root 1 2 3
Division 3 3 3
Arccosine 3 3 3
Runnin
g
time 41.125us 44.812us 46.437us
ACKNOWLEDGEMENTS
This work is supported partly by Tianjin science and
technology special project under Grant No.
16JCTPJC50600.
REFERENCES
Choorat, P., Thepsathit, B., Kaosaiyananda, V., 2017.
Applied Integral Intensity Projection to Find The
Numbers of The Parking Spots .In Proc. 9th IEEE Int.
Conf. Knowlege and Smart Technology, p.328-331.
Zadeh, N., Dela, J., 2016. Smart Urban Parking Detection
System. In Proc. 6th IEEE Int. Conf. Control System ,
Computing and Engineering, p.370-373.
Li, X., Wu, J., 2016. A New Method and Verification of
Vehicles Detection Based on RSSI Variation. In Proc.
10th IEEE Int. Conf. Sensing Technology, p.1-6.
Zhu, H., Yu, F., 2016. A Cross-Correlation Technique for
Vehicle Detections in Wireless Magnetic Sensor
Network. IEEE Sensors Journal, 16(11), p.4484-
4494.
Qian, Z., Bai, R., Huang, C., 2009. Advanced Spintronic
Materials and Devices. Instrument Technique and
Sensor, S1(11), p.96-101.
Zhang, Z., Yuan, H., Chen, L., 2013. A Parking Vehicle
Detection Algorithm Using Magnetic Sensor. The 2th
Int. Conf., Applied Mechanics and Materials, p.1353-
1356.
Han, B., Huo, H., Chai, K., 2009. Power Efficient Vehicle
Detection Algorithm Using Wireless Magnetic Sensor
Node. Robotics and Automation, 35(1), p.145-150.
Wu, X., Sa, C., 2014. Design of The Wireless Vehicle
Detection Sensor Based on Magnetic Resistance
Sensor. Beijing Automobile Magazine, 9(2), p.24-26.
Chen, G., She, H., Dong, J., et al, 2015. Parking
Occupancy System Based on Wireless Sensor
Network. Microcontrollers & Embedded
Systems,15(8), p.49-52.
ICECTT 2018 - 3rd International Conference on Electromechanical Control Technology and Transportation
454