An Improved Vehicle Detection Algorithm Based on Multi-Intermediate State Machine

,


Introduction
With the rapid development of China's national economy and the modernization of social life, China's urbanization and motorization process has been further promoted. However, it also brought a series of problems, of which the traffic problem is one of the most important. In addition to the rapid growth in the number of motor vehicles, the lack of advanced transportation infrastructure is the main source of long-term traffic congestion. Under this situation, the Intelligent Transportation System (ITS) is emerging to meet with the requirements of the times.
At present, the traffic order of the crossroad is maintained by periodically changing traffic lights. One of the main drawbacks of this timing control method is that when the signal light is red and there is no car waiting in the crossing lane, the green light signal will still be released. is not only wastes the driver's time in other lanes but also causes environmental pollution due to the waiting of the vehicles. A worse situation is that a small number of drivers may cause the traffic accident by running the red light in a hurry. us, in the control of traffic signs at the crossroads, it is important to improve control efficiency through advanced traffic sign schemes based on the traffic characteristics and queuing rules of the crossroad. At present, large cities in some developed countries have begun to adopt intelligent traffic control systems. e technical basis is to detect the vehicle in real time. ere are various types of vehicle detection technologies, and they either have insufficient detection accuracy or require relatively complicated installations [1][2][3]. Such as the loop coil technology, it requires the toroidal coil to be buried in the ground which will cause certain damage to the road surface. Moreover, the road surface will be damaged again during maintenance, which inevitably increases the cost [4,5]. For the microwave technology, the detection accuracy is often insufficient when traffic is congested or a big car blocks a small car [6]. e video detection technology is the most widely used way in China. Its detection accuracy is able to meet the demand under normal weather conditions. However, the detection accuracy of the technology will be greatly reduced under dust or fog conditions [7]. e system contains several functional modules, including signal amplification, wireless communication, A/D converter, and sensor set/reset functions. To detect all the intersection vehicles, a number of magnetoresistive sensors are connected to the computer system through the wireless communication module, and then, the detected vehicle information will be transferred back to the master host computer. Finally, an improved multi-intermediate state machine algorithm for vehicle detection was proposed.

Detection Principle
e geomagnetic vehicle detector is a vehicle detection technology based on a magnetoresistive sensor, with the characteristics of small size, convenient installation, no response to nonferromagnetic objects, and high reliability [6]. Generally, the geomagnetic field around the car changes during driving due to a steel plate with a ferromagnetic component at the bottom of the automobile engine. erefore, the magnetoresistive sensor can be used to detect the changes of the Earth's magnetic field, so as to determine the existence of a vehicle. In addition, when the nonferromagnetic part of the car passes through the magnetoresistive sensor, the magnetic field changes are very small and can even be ignored (called "dead zone") owing to the magnetoresistive sensor that does not respond to the nonferromagnetic object. Furthermore, the magnetoresistive sensor mainly utilizes the magnetoresistance effect of a nickel-iron magnetic alloy (Figure 1), while its basic component is a Wheatstone Bridge, which is made by a nickel-iron magnetic alloy material. At the same time, the value of the resistor has a certain relationship with the angle between the bias current and the magnetic field vector. As shown in Figure 2, within a certain range, the resistance is linear with the magnetic field vector [8,9]. Besides, the Wheatstone bridge converts the changes of the magnetic field to output in the form of differential voltages. e resistivity ρ of the nickel-iron magnetic alloy material depends on the angle θ between the magnetic field strength M and the current I. e functional relationship is as follows [10]: In this equation, ρ ⊥ and ρ ‖ indicate the resistivity when the direction of magnetic field strength is perpendicular and parallel to the direction of the current, respectively. e Earth's magnetic field is weak, with an average intensity of about 0.06 mT at the strongest poles, so the Earth's magnetic field can be regarded as uniform within a limited space. e ferromagnetic material contained in the vehicle itself affects the geomagnetic signal and bends the magnetic field lines in the area where the vehicle is located. When this uniform magnetic field is disturbed by ferromagnetic materials (such as iron, steel, nickel, and cobalt), its uniformity is destroyed [11]. So the vehicle information can be obtained through signal analysis since the sensor is sensitive to the change of the signal as the vehicle passes the sensor.

Hardware Design
Honeywell has the world's leading technology in the manufacturing of magnetic induction and measuring elements. HMC1022 is one of HMC series double-axis magnetoresistive sensor produced by Honeywell. It not only has a wide range of magnetic field strength and a low set/reset current performance but also has the characteristics of high detection accuracy, stable working performance, small size, antielectromagnetic noise, and no response to nonferrous magnetic objects, which is mainly used to detect the weak magnetic field. e main technical parameters are shown in Table 1 in the appendix.
e detection system is a single-node distributed vehicle information collection and control system with HMC1022 as the information acquisition sensor, which mainly includes signal amplification module, A/D conversion module, sensor setting/reset module, and ZigBee wireless communication module. e sensor node is composed of a dual-axis magnetoresistive sensor HMC1022, a ZigBee wireless communication module, and a power source. Compared with the HMC1001/1002 and three-axis magnetoresistive sensor, the HMC1022 has lower power consumption. It also reduces peripheral circuits. e maximum energy of the node is mainly consumed at two time points of wireless transmission and reception of data. A plurality of magnetoresistive sensor nodes is connected to the computer system through the serial port wireless communication module, and the detected vehicle information is fed back to the upper computer. ereby, the detection of the intersection vehicle is realized. e design framework of the vehicle detection system hardware is shown in Figure 3.

Signal Amplification Module.
In order to effectively use the sampling accuracy of the A/D converter and improve the detection accuracy, the weak voltage signal output by the magnetoresistive sensor needs to be amplified before A/D sampling. e instrument amplifier AD620 is selected in this project, while the signal input + IN and -IN correspond to the differential input OUT+(A) and OUT-(A) of the sensor, respectively.
ere is a linear relationship between the voltage value at the output of AD620 and the voltage difference between the two input terminals. e functional relationship is while G denotes the gain magnification, and its relationship with the resistance R G is It can be seen that G is only affected by R G .

A/D Conversion Module.
e magnetoresistive sensor HMC1022 transmits the detected magnetic field analog signal to the A/D conversion module through the I/O interface. It converts the analog signal into a digital signal and transmits the converted digital signal to each base station  (1) Cross field � 1 gauss (see AN-205) Happlied � ±1 gauss +0.3 (%) FS Max. exposed field (1) No perming effect on zero reading 10000 Gauss Set/reset (1) S/R current ≥ 0.5 amps 30 uV  Mathematical Problems in Engineering 3 through the RF circuit. e change of the magnetic field is converted into the change of voltage. But the change of voltage is very weak and short, which requires the accuracy of A/D conversion to be high enough and the sampling frequency as high as possible. e system adopts 14 bit A/D conversion in CC2530. Its acquisition frequency reaches hundreds of times per second, which can meet the system requirements.

Set/Reset Circuit.
General power supply is difficult to generate high current pulse, which is usually generated by capacitor charging and discharging. In this project, the CMOS switch IRF7105 is selected, and on and off are controlled by the clock signal to generate set/reset pulse. Based on the requirements, a pulse current-generating circuit with the pulse width of 2 us and the pulse period of 50 ms can be designed, and the frequency can be further reduced to save power consumption. e setting pulse is formed by a 1 uF tantalum capacitor, and a 200 Ω step-down resistor is connected in series with the power supply to reduce the noise. e output terminal of IRF7105 is connected to the S/R + terminal of HMC1022 through a 0.1 uF capacitor.

ZigBee Wireless Communication Module.
ZigBee's typical wireless communication distance is 50-300 m, and its protocol stack includes 5 layers: application layer, network layer, data link layer, media access layer, and physical layer. Among them, the application layer is developed by users based on their own needs, the network layer and data link layer are developed by ZigBee alliance, and the media access layer and physical layer follow the IEEE802.15.4 standard. Furthermore, the ZigBee wireless sensor consists of an 8 bit MCU and CC2530 RF chip.

Anti-Interference Design of the Hardware Circuit.
In the magnetoresistive sensor vehicle flow detection system, the sensor nodes are placed in the open traffic environment, where there exists a variety of electromagnetic signal interference, such as electromagnetic signals generated by high-voltage transmission lines/high-voltage equipment, radio stations, mobile communications, and electronic instruments. Moreover, the vehicle flow detection system has both the analog circuit and digital circuit; hence, the electromagnetic compatibility problems should be well-dealt with, especially the electromagnetic interference caused by the RF circuit. erefore, the following measures can be taken to reduce electromagnetic interference during PCB wiring: (1) In the clock circuit, the wire connecting crystal input/output and the ground wire of the crystal capacitor should be wide and short to reduce noise interference. (2) In terms of power supply and ground, first of all, the power line should be close to the ground wire as much as possible to reduce the area of the power supply loop. Secondly, the analog circuit power supply and digital circuit power supply should be separated to avoid interference. irdly, a decoupling capacitor is connected between the power pin and the ground pin of the chip. Furthermore, the ground wire should be designed as a closed loop to avoid large potential difference and improve the noise tolerance when the circuit board has multiple chips.
(3) In order to improve the stability of the circuit, the right angle and acute angle should not appear in PCB wiring, and the principle of 135°is ought to followed in the broken line. Besides, the width of the signal line, the power line and ground wire need to increase in turn, with the width of 1 mm, 1.5 mm, and 2 mm, respectively.
3.6. Sampled Waveform Preprocessing. First, the sliding average filtering and peak filtering methods are used to weaken the high-frequency interference signals of each axis, and then, the magnetic field component information of the two axes is combined to obtain the entire disturbance effect generated when the vehicle passes over the sensor. e geometric mean of the differential of the magnetic field components of each axis is used to characterize the overall disturbance degree of the magnetic field, which cannot only eliminate the slow drift of the time series but also eliminate the interference of vehicles in adjacent lanes. Finally, the overall disturbance is sampled and averaged to obtain stability time series: where X m n and Y m n represent the values of the nth sampling point after filtering on the X-axis and Y-axis, respectively, and M n and M m n are the overall disturbance degree at the nth sampling point and the mth sampling point after filtering, respectively.

Common Detection Algorithms
is project designs a vehicle detection system based on the dual-axis magnetoresistive sensor HMC1022 to detect the vehicle information on the road in real time. erefore, the selection of the vehicle detection algorithm, the accurate analysis of various signal characteristics influencing factors, and the acquisition of traffic flow information will be the focus of this project. e general considerations include (1) extracting relatively accurate vehicle signals from the vehicle detection signal, (2) minimizing other electromagnetic signal interference, (3) conducting a series of processing on the extracted signals, (4) requiring no change about the original vehicle signal characteristics after processing, and (5) using a simpler algorithm to improve the accuracy of vehicle detection. e fixed threshold algorithm and adaptive threshold algorithm (ATA) are the main algorithms for vehicle detection technologies by using magnetoresistive sensors [7]. At present, these two algorithms are widely used with accurate detection results and strong representativeness. Comparing with the multi-intermediate state machine algorithm, the advantages of the multi-intermediate state machine algorithm can be better presented. e abovementioned algorithms will be introduced, respectively, hereinafter.

Fixed reshold Algorithm.
Since the geomagnetic signal collected by the magnetoresistive sensor is not continuous but discrete data, the algorithm compares the magnetic field signal acquired from the Z-axis (the direction perpendicular to the road surface) with the given fixed threshold. e vehicle is considered to be present, while the values of 10 magnetic field signals are greater than the fixed threshold, or the vehicle is considered to be leaving, while the magnetic field signal value of the X-axis (the direction parallel to the road surface) and Z-axis is below the threshold for more than 0.25 s. is algorithm is easy to understand and fast; moreover, it can reflect the current traffic flow information in real time. However, the magnetic field signal value collected may sometimes appear as breakpoints or outliers since the magnetoresistive sensor is susceptible to magnetic interference in the open air, which may cause misjudgment of vehicles.

ATA.
In this method, the energy of the original magnetic field signal is calculated firstly; then, the signal is processed by the FIR filter to obtain the average energy, which is compared with the adaptive threshold value. Finally, the comparative results are input into the state machine for decision analysis. e ATA algorithm flow chart is shown in Figure 4.
is algorithm uses the FIR filter to detect the magnetic field signal, which makes the algorithm complicated to some extent.

System Algorithm Implementation
Considering that the vehicle flow detection system requires the sensor node to transmit the road conditions to the host computer in real time and accurately through the ZigBee wireless communication module, the detection algorithm should be as simple as possible to reduce the calculation time.
A multi-intermediate state machine algorithm with high accuracy and simple feasibility is first proposed by Ding et al. which typically has five states: nocar, car, count0, count00, and count1. e input is denoted as u(k), the intermediate states are count0 and count00, and the output states are car and nocar. First, the magnetoresistive sensor detects and collects the geomagnetic field signal, and the signal is averaged to obtain f(k); then, f(k) is binarized to obtain u(k), which is used as the state machine input. e threshold T(k) is set reasonably as needed, and u(k) � 1 when f(k) ≥ T(k), and u(k) � 0 when f(k) < T(k). e state machine has a car counter (represented by count1), an interference counter (represented by count0), and a vehicle departure counter (represented by count00). e threshold values of these three counters are set, respectively, as N, M, and M. When the count is greater than M, the vehicle is considered to be leaving, and when it is less than M, it is considered to be interference. Changes in the sensor temperature or the external environment may cause the output signal to drift, so the values of all counters are set to 0. e improved state machine algorithm is shown in Figure 5. e multi-intermediate state machine algorithm has an intermediate state, which can be used to determine whether the vehicle is leaving the sensor node, rather than just determining when the vehicle enters the detection zone. us, it improves the detection accuracy.

Tests and Results
Since the vehicle counter threshold is closely related to the number of sampling points in the state machine algorithm, the more the points, the more reliable the threshold design. e number of sampling points N can be derived as In this equation, L indicates the length of the car (m), and v and f are the vehicle speed (km/h) and sampling frequency (Hz), respectively. e length of a small car is about 4.8 m. If it takes about 0.17 s to pass the node at a speed of 100 km/h, it can be sampled about 10 points under 60 Hz sampling frequency. But the vehicle can't reach this speed in urban. us, the vehicle counter threshold N � 10. e sampling frequency needs to be increased, while it is necessary to sample a higher speed vehicle. Based on the test data, the vehicle threshold T is equal to 40, the interference counter and the vehicle leaving counter M is 20, and the forced reset threshold is 200. e experimental test results show that when the vehicle passes the sensor nodes, the vehicle can be detected as long as most of the vehicle body is in the lane; however, it cannot be detected in the adjacent lane. A total of 156 vehicles actually passed in the 20 minutes, and 153 vehicles were tested by the sensor node; therefore, the detection accuracy rate was 98.08%, and the false detection rate was 1.92%. In Mathematical Problems in Engineering addition, the detection accuracy could be improved by adjusting the threshold value. In this method, the problem of sensor output signal drift is solved by re-setting and resampling the environmental magnetic field so that the output magnetic field is the net magnetic field generated by the vehicle, which improves the test accuracy.
According to the state machine algorithm, the vehicle detection accuracy is mainly determined by the vehicle threshold T and the vehicle counter N. e higher the threshold T, the stronger the anti-interference. However, it easier to miss passing vehicles, and the same applies to vehicle counters. us, the most reasonable threshold should be selected after analyzing a large amount of test data.
Before verifying the reliability of the relevant algorithms, some testing work was conducted in the early stage. e experimental results were obtained through field tests in the road field. According to the different placement positions of the detection points and the different placement directions of the sensor's sensitive axis, the test was carried out, respectively, to collect the corresponding magnetic field signal change information and carry out classification comparison and analysis further.
Detection nodes A and B were placed in the center and edge of the lane, respectively, while the driving direction of the vehicle was from west to east, as shown in Figure 6. e X-axis was marked as the positive direction, and by changing the X-axis (the sensitive axis) direction of the magnetoresistive sensor to make it face to the east, west, south, and north, respectively, the magnetic field changes of the detected node were tested when a car passes by. e experimental results of the detection nodes A and B are shown in Figure 7 and Figure 8, respectively. By comparing and analyzing the test waveforms of the detection node A and B, it can be found that (1) when the vehicle passes the detection node, the detection value has a significant change; (2) As the vehicle passes by the detection node, the detection value changes, but the change is not obvious. Based on this different variation feature, the detection node can be placed in the center of each lane of the road, which cannot only accurately distinguish whether there is a vehicle passing through the lane but also effectively prevent the interference caused by vehicles passing the side lane and avoid false detection. It can be seen from Figure 7 that, in case of the vehicle passes, the detection value of the X-axis is the largest when the sensitive axis is placed in the north direction. As a result, the positive axis of the sensitive axis should be oriented to the north, while placing the magnetoresistive sensor, and the subsequent test should be performed under this condition.          On the basis of completing the hardware and software design of the vehicle detection system, the hardware module of the vehicle detection system was placed on the road for field test and analysis, so as to verify the reliability of the multi-intermediate state machine algorithm and compare the fixed threshold algorithm and ATA. In order to eliminate the interference of other factors and determine the superiorities of different algorithms, the system with the selfdesigned hardware module adopted for the test and location of road detection were all the same. In addition, the module was installed in the same position and direction (the detection node was located in the center of the road, that is, the detection node A.); besides, the test weather was also basically the same. In order to obtain different vehicle judgment test results, the detection algorithms used the fixed threshold algorithm, ATA, and multi-intermediate state machine algorithm, respectively, and the results are shown in Table 2. It should be noted that, based on the test results of repeated trials in advance, the reasonable threshold parameters are finally determined for each algorithm. Detailed data of vehicle test results are shown in Table 3.
From the test results in Table 2, it can be seen that the multi-intermediate state machine algorithm has a higher accuracy than the fixed threshold algorithm and ATA. e detection accuracy of the multi-intermediate state machine algorithm reaches 98.5%. It can also be seen that each algorithm has a certain probability of misjudgments. e reason for these misjudgments may be the interference of wireless signals sent by external radio equipment [12].
Up to now, the detection accuracy of some research vehicle detection systems is mostly concentrated in 75%-90%. For example, the vehicle detection system designed uses a HMC1022 as the detection sensor and uses the vehicle classification algorithm in Reference [13], which has a detection accuracy of about 85.7%.

Conclusion
is project has analyzed several common vehicle presence detection algorithms, such as the fixed threshold algorithm and ATA. And, the multi-intermediate state machine algorithm is used as the vehicle detection method in the hardware system. By adding an intermediate state variable, the algorithm can judge when the vehicle leaves the sensor detection node, rather than when the vehicle enters the detection area, thus the detection accuracy is improved. e experimental results show that, because of the simple and reasonable traffic flow algorithm adopted by the system and the correct circuit design, the system has high detection accuracy, fast running speed, and good detection effect and can be widely used in the traffic field of large-and medium-sized cities.

Conflicts of Interest
e authors declare that they have no conflicts of interest.