An Improved Vehicle Detection Algorithm Based on Multi-Intermediate State Machine
The vehicle detection algorithm is an important part of the intelligent transportation system. The accuracy of the algorithm will determine whether accurate vehicle information can be obtained. The 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. In this paper, two common vehicle detection algorithms, fixed threshold algorithm and adaptive threshold algorithm, were analyzed in the vehicle detection system with magnetoresistive sensors, simultaneously. Finally, an improved multi-intermediate state machine algorithm for vehicle detection was proposed. Using the intermediate state, this algorithm cannot only detect when the vehicle enters the detection area but also decide whether the vehicle leaves the sensor node or not. In this way, it improves the detection accuracy.
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. This 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. Thus, 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. The technical basis is to detect the vehicle in real time. There are various types of vehicle detection technologies, and they either have insufficient detection accuracy or require relatively complicated installations [1–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 . The 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 .
The 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.
2. Detection Principle
The 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 . 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. Therefore, 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.
The resistivity ρ of the nickel-iron magnetic alloy material depends on the angle θ between the magnetic field strength M and the current I. The functional relationship is as follows :
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.
The 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. The 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 . 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.
3. 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. The main technical parameters are shown in Table 1 in the appendix.
The 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. The 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. The 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. Thereby, the detection of the intersection vehicle is realized. The design framework of the vehicle detection system hardware is shown in Figure 3.
3.1. 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. The 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.
There is a linear relationship between the voltage value at the output of AD620 and the voltage difference between the two input terminals. The functional relationship iswhile denotes the gain magnification, and its relationship with the resistance RG is
It can be seen that is only affected by RG.
3.2. A/D Conversion Module
The 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 through the RF circuit. The 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. The system adopts 14 bit A/D conversion in CC2530. Its acquisition frequency reaches hundreds of times per second, which can meet the system requirements.
3.3. 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. The 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. The output terminal of IRF7105 is connected to the S/R + terminal of HMC1022 through a 0.1 uF capacitor.
3.4. 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.
3.5. 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. Therefore, 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. Thirdly, 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. The 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 and represent the values of the nth sampling point after filtering on the X-axis and Y-axis, respectively, and and are the overall disturbance degree at the nth sampling point and the mth sampling point after filtering, respectively.
4. Common Detection Algorithms
This 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. Therefore, 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. The 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.
The fixed threshold algorithm and adaptive threshold algorithm (ATA) are the main algorithms for vehicle detection technologies by using magnetoresistive sensors . 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. The abovementioned algorithms will be introduced, respectively, hereinafter.
4.1. Fixed Threshold 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. The 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. This 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.
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. The ATA algorithm flow chart is shown in Figure 4.
This algorithm uses the FIR filter to detect the magnetic field signal, which makes the algorithm complicated to some extent.
5. 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. The 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. The 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). The state machine has a car counter (represented by count1), an interference counter (represented by count0), and a vehicle departure counter (represented by count00). The 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. The improved state machine algorithm is shown in Figure 5.
The 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. Thus, it improves the detection accuracy.
6. 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. The number of sampling points N can be derived as
In this equation, L indicates the length of the car (m), and and f are the vehicle speed (km/h) and sampling frequency (Hz), respectively.
The 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. Thus, the vehicle counter threshold N = 10. The 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. The 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 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 re-sampling 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. The higher the threshold T, the stronger the anti-interference. However, it easier to miss passing vehicles, and the same applies to vehicle counters. Thus, 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. The 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. The 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. The 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 self-designed 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. The 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. The reason for these misjudgments may be the interference of wireless signals sent by external radio equipment .
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 , which has a detection accuracy of about 85.7%.
This 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. The 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
The authors declare that they have no conflicts of interest.
This research was funded by National Natural Science Foundation of China Youth Project (no. 61802065).
X. Y. Liu, H. Wei, and C. H. Liu, “Marker-free coil-misalignment detection approach using TMR sensor array for dynamic wireless charging of electric vehicles,” IEEE Transactions On Magnetics, vol. 54, no. 11, Article ID 2844863, 2018.View at: Publisher Site | Google Scholar
U. P. Borole, S. Sasikala, I. R. Kulkarni, P. Saravanan, H. C. Barshilia, and P. Chowdhury, “Highly sensitive giant magnetoresistance (GMR) based ultra low differential pressure sensor,” Sensors and Actuators A-Physical, vol. 280, pp. 125–131, 2018.View at: Publisher Site | Google Scholar
V. S. Luong, A. T. Nguyen, Q. K. Hoang et al., “Magnetoresistive performances in exchange-biased spin valves and their roles in low-field magnetic sensing applications,” Journal of Science: Advanced Materials and Devices, vol. 3, no. 4, pp. 399–405, 2018.View at: Publisher Site | Google Scholar
C. X. Chang, Y. G. Wang, and Y. L. Zhan, “Vehicle classification under different feature sets with a single anisotropic magnetoresistive sensor,” IEICE Transactions On Electronics Communications and Computer Sciences, vol. E100A, no. 2, pp. 440–447, 2017.View at: Publisher Site | Google Scholar
Y. S. Byun, R. G. Jeong, and S. W. Kang, “Vehicle position estimation based on magnetic markers: enhanced accuracy by compensation of time delays,” Sensors (Basel, Switzerland), vol. 15, no. 11, pp. 28807–28825, 2015.View at: Publisher Site | Google Scholar
C. Xu, Y. G. Wang, B. X. He, and F. G. Li, “Vehicle classification using an imbalanced dataset based on a single magnetic sensor,” Sensors, vol. 18, no. 6, p. 1690, 2018.View at: Publisher Site | Google Scholar
C. F. Ye, R. Anders, and U. Lalita, “Using magnetoresistive sensors in nondestructive testing,” Materials Evaluation, vol. 76, no. 2, pp. 144–154, 2018.View at: Google Scholar
J. H. Hu, M. C. Pan, J. F. Hu et al., “Resolution improvement of low frequency AC magnetic field detection for modulated MR sensors,” Review of Scientific Instruments, vol. 88, no. 9, Article ID 095006, 2017.View at: Publisher Site | Google Scholar
X. P. Zeng, S. Song, J. S. Wang, H. Dai, and S. Su, “An analytic algorithm based position and orientation detection using a tri-axial magnetoresistive sensor,” in Proceedings of the 16th IEEE Sensors Conference, pp. 1158–1160, Glasgow, UK, November 2017.View at: Google Scholar
F. Nording, S. Weber, F. Ludwig, and M. Schilling, “Measurement system for temperature dependent noise characterization of magnetoresistive sensors,” Review of Scientific Instruments, vol. 88, no. 3, Article ID 035006, 2017.View at: Publisher Site | Google Scholar
X. Liu, C. Liu, W. Han, and P. W. T. Pong, “Design and implementation of a multi-purpose TMR sensor matrix for wireless electric vehicle charging,” IEEE Sensors Journal, vol. 19, no. 5, pp. 1683–1692, 2019.View at: Publisher Site | Google Scholar
W. Han, K. T. Chau, C. Q. Jiang, and W. Liu, “Accurate position detection in wireless power transfer using magnetoresistive sensors for implant applications,” IEEE Transactions on Magnetics, vol. 54, no. 11, Article ID 2843796, 2018.View at: Publisher Site | Google Scholar
X. Lei, Y. Y. Hou, and Q. S. Wu, “Algorithm design of vehicle type classification for geomagnetic vehicle detector,” Journal of Chang'an University (Natural Science Edition), vol. 33, no. 5, pp. 118–123, 2013.View at: Google Scholar