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

Authors: Baosen Xiao; Jingbo Xia; Xiaolu Li; Qinquan Gao
Journal: Mathematical Problems in Engineering
 (2021)

---

## Abstract

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.


---

## Body

## 1. 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. 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 [6]. 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 [7].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 [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. 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.Figure 1
Magnetoresistive effect.
(a)(b)Figure 2
Functional relationship between nickel alloy iron magnetic resistance and angle.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 [10]:(1)ρθ=ρ⊥⋅sin2θ+ρ⋅cos2θ=ρ⊥+ρ−ρ⊥⋅cos2θ.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 [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.


## 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 Table1 in the appendix.Table 1
Technical parameters of HMC1022.
CharacteristicsConditionsMin.TypeMax.UnitBridge supplyVbridge referenced to GND525VoltsBridge resistanceBridge current = 5 mA80011001300ΩOperating temperature (1)HMC1021S, 1021Z, and 1022−55150°CHMC1021D∗−55300∗Storage temperature (1)Unbiased−55175°CField range (1)Full-scale (FS), total applied field−6+6GaussLinearity error (1)Best fit straight line ±1 gauss0.05(%) FS±3 gauss0.4±6 gauss1.6Hysteresis error (1)3 sweeps across ±3 gauss0.08(%) FSRepeatability error (1)3 sweeps across ±3 gauss0.08(%) FSBridge offsetOffset = (OUT+)–(OUT−), field = 0 gauss after set pulse, Vbridge = 5 V−10±2.511.25mVSensitivityS/R current = 0.5 A0.81.01.25Mv/V/gaussNoise density (1)Noise at 1 Hz, Vbridge = 5V48nV/HzResolution (1)Bandwidth = 10 Hz and Vbridge = 5V85ugaussBandwidth (1)Magnetic signal (lower limit = DC)5MHzOFFSET strapMeasured from OFFSET + to OFFSET-385060ΩOFFSET strap Ω tempco (1)TA = −40 to 125°C0.39(%)°COFFSET field (1)Field applied in sensitive direction4.04.66.0mA/gaussSet/reset strapMeasured from S/R+ to S/R−5.57.79ΩSet/reset current2us current pulse, 1% duty cycle0.50.54.0AmpSet/reset Ω tempco (1)TA = −40 to 125°C0.37(%)°CDisturbing field (1)Sensitivity starts to degrade. Use S/R pulse to restore sensitivity20GaussSensitivity tempco (1)TA = -40 to 125°C Vbridge = 5 V−0.32−0.3−0.28(%)°CIbridge = 5 mA−0.06Bridge offset tempco (1)TA = -40 to 125°C no set/Reset+0.05(%)°CVbridge = 5 V with set/reset+0.001Resistance tempco (1)Vbridge = 5 V, TA = –40 to 125°C0.25(%)°CCross-axis effect (1)Cross field = 1 gauss (see AN-205) Happlied = ±1 gauss+0.3(%) FSMax. exposed field (1)No perming effect on zero reading10000GaussSet/reset (1)S/R current ≥ 0.5 amps30uVThe 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 Figure3.Figure 3
Flowchart of the system hardware structure.


### 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 is(2)VOUT=Vref+G⋅V+IN−V−IN,while G denotes the gain magnification, and its relationship with the resistance RG is(3)G=49.4kΩ/RG−1.It can be seen thatG 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:(4)Mn=Xnm−Xn−1m2+Ynm−Yn−1m2,(5)Mnm=Mn+⋯+M14,n<4,Mn+Mn−1+Mn−2+Mn−34,n≥4,whereXnm and Ynm represent the values of the nth sampling point after filtering on the X-axis and Y-axis, respectively, and Mn and Mnm are the overall disturbance degree at the nth sampling point and the mth sampling point after filtering, respectively.


## 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 is(2)VOUT=Vref+G⋅V+IN−V−IN,while G denotes the gain magnification, and its relationship with the resistance RG is(3)G=49.4kΩ/RG−1.It can be seen thatG 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:(4)Mn=Xnm−Xn−1m2+Ynm−Yn−1m2,(5)Mnm=Mn+⋯+M14,n<4,Mn+Mn−1+Mn−2+Mn−34,n≥4,whereXnm and Ynm represent the values of the nth sampling point after filtering on the X-axis and Y-axis, respectively, and Mn and Mnm 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 [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. 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 theZ-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.


### 4.2. 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. The ATA algorithm flow chart is shown in Figure4.Figure 4
ATA algorithm flow chart.This algorithm uses the FIR filter to detect the magnetic field signal, which makes the algorithm complicated to some extent.


## 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 theZ-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.


## 4.2. 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. The ATA algorithm flow chart is shown in Figure4.Figure 4
ATA algorithm flow chart.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, asN, 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.Figure 5
State machine detection algorithm.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 pointsN can be derived as(6)N=3.6×LVf.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.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 thresholdN = 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 thresholdT 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 nodesA 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.Figure 6
Location diagram of the detection node.Figure 7
Waveform measured at nodeA.Figure 8
Waveform measured at nodeB.By comparing and analyzing the test waveforms of the detection nodeA 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 nodeA.); 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.Table 2
Vehicle test results.
AlgorithmActual number of vehicles passing/carDetected number of vehicles passing/carDetection accuracy (%)Multi-intermediate state machine20019798.5Fixed threshold20018190.5Adaptive threshold20018291Table 3
Detailed data of vehicle test results.
Is there a vehicle? (Y/N)No.Detection valueMulti-intermediate state machineFixed thresholdAdaptive threshold12.6185YYY22.6031YYY32.5948YYY42.5660YYY52.5184YYY62.4730YYY72.4529YYY82.5255YYY92.6168YYY102.5814YYY112.4964YYY122.5064YYY132.5453YYY142.5313YYY152.3760YNN162.4658YYY172.5250YYY182.4179YNN192.5286YYY202.4981YYY212.4109YNN222.5285YYY232.4344YNN242.5683YYY252.4586YYY262.5142YYY272.5312YYY282.5413YYY292.4512YYY302.5781YYY312.6035YYY322.4632YYY332.5489YYY342.6145YYY352.4689YYY362.4751YYY372.4693YYY382.5462YYY392.5489YYY402.5358YYY412.5697YYY422.4869YYY432.3658YNN442.3789YNN452.4785YYY462.5478YYY472.6102YYY482.6189YYY492.5691YYY502.5486YYY512.4653YYY522.5662YYY532.5449YYY542.6358YYY552.5397YYY562.5269YYY572.3649NNN582.4769YYY592.6589YYY602.4854YYY612.5698YYY622.5485YYY632.5684YYY642.4536YYY652.6245YYY662.5632YYY672.5215YYY682.5632YYY692.5325YYY702.5745YYY712.5362YYY722.5486YYY732.5568YYY742.5742YYY752.5690YYY762.5701YYY772.5120YYY782.5313YYY792.5426YYY802.5580YYY812.5243YYY822.5368YYY832.5472YYY842.5542YYY852.5617YYY862.6310YYY872.4782YYY882.4957YYY892.4325YNN902.4365YYY912.5210YYY922.5472YYY932.5101YYY942.5240YYY952.5431YYY962.5571YYY972.5240YYY982.4532YYY992.4781YYY1002.4235YNN1012.4582YYY1022.5325YYY1032.5472YYY1042.4625YYY1052.5214YYY1062.4125YNN1072.6325YYY1082.6214YYY1092.6302YYY1102.5412YYY1112.5003YYY1122.5268YYY1132.5412YYY1142.5471YYY1152.5862YYY1162.5521YYY1172.4305YNN1182.5014YYY1192.5478YYY1202.5325YYY1212.5411YYY1222.4690YYY1232.4364YYY1242.4521YYY1252.4781YYY1262.5302YYY1272.5201YYY1282.5131YYY1292.4520YYY1302.3945YNN1312.4368YYY1322.4528YYY1332.6582YYY1342.5832YYY1352.6048YYY1362.6102YYY1372.6352YYY1382.4563YYY1392.5048YYY1402.3652NNN1412.6245YYY1422.6325YYY1432.4587YYY1442.4782YYY1452.4632YYY1462.5017YYY1472.4785YYY1482.5201YYY1492.4690YYY1502.4703YYY1512.4258YNN1522.4569YYY1532.4586YYY1542.4260YNN1552.5203YYY1562.5249YYY1572.5862YYY1582.5841YYY1592.5428YYY1602.5269YYY1612.5423YYY1622.5148YYY1632.5905YYY1642.5826YYY1652.5472YYY1662.5630YYY1672.5325YYY1682.3520NNN1692.5124YYY1702.5642YYY1712.5820YYY1722.5802YYY1732.6102YYY1742.5501YYY1752.5321YYY1762.5321YYY1772.5703YYY1782.5903YYY1792.5836YYY1802.6025YYY1812.5123YYY1822.5802YYY1832.5621YYY1842.5421YYY1852.5478YYY1862.6130YYY1872.6012YYY1882.5891YYY1892.6472YYY1902.5747YYY1912.5201YYY1922.4512YYY1932.5120YYY1942.5362YYY1952.4352YNY1962.5210YYY1972.4258YNN1982.4365YYY1992.4524YYY2002.4125YNNFrom the test results in Table2, 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 [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%.


## 7. Conclusion

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.



---

*Source: 5540837-2021-04-21.xml*