1. Introduction and Related Work
Usage of magnetic sensing in intelligent transportation systems (ITS) is rapidly gaining popularity [
1,
2,
3] compared to more traditional video processing [
4,
5]. Various systems for road traffic surveillance largely utilize MEMS (micro-electromechanical systems) magnetometers for the purpose of vehicle detection and classification [
6,
7]. Examples of such applications include vehicle speed calculation [
8,
9], length estimation [
10], classification into defined categories [
11], smart parking [
12] and autonomous driving [
13]. Wireless magnetic sensor networks are a popular choice for information acquisition. This solution has the advantages of low cost, low power consumption and miniaturization. Study [
14] highlights the drawback of magnetic sensing for a parking application, which is the weak magnetic region under the vehicle. It is difficult to separate this magnetic signal from ambient noise since the magnetometers are mounted in the middle of the parking lane. To solve this problem, a UWB radio channel was proposed. The authors of [
15] investigated anomaly detection for a moving magnetic target in controlled laboratory conditions. The velocity–frequency relationship, direction angle and closest point of approach distance were highlighted in this study. The mathematical relationship between the detection platform and magnetic target was established to account for velocity differences [
16].
Machine learning methods for magnetic signal analysis are gaining popularity. In [
11], a method for vehicle detection and recognition using machine learning, input vectors composed from cestrum energy and Mel frequency cepstral coefficients was utilized. Vehicles were classified into five defined categories with high accuracy, although the sample size for training and testing was not very large. The authors of [
17] defined vehicle classification as the process of assigning each vehicle to a pre-defined vehicle class based on some features extracted from its magnetic signature. The task of vehicle re-identification [
18] was applied in determining segment travel times. Using an inductive loop detector, the authors implemented a decision tree using statistical features like lane speed and travel duration estimation. Classification into four different classes was performed in [
19]. The authors extracted 10 different statistical features from the z axis of the triaxial magnetometer—such as mean, variance and local minimums and maximums. Classification was performed using different machine learning algorithms (BP NN, SVM, Random Forest) on a dataset containing more than 4500 vehicle entries. The classification result reached 80%. Real-time vehicle classification into nine classes was performed in [
20] utilizing three-layer feedforward artificial neural networks (ANN). The authors established that using only time-domain features requires low computation and few memory resources, which enables easier implementation and real-time operation. A frequent problem in vehicle classification is an imbalanced dataset—certain types of vehicles like buses and motorcycles occur less often compared to sedans and hatchbacks. A solution called SMOTE was proposed by the authors of [
21]. According to certain rules, the SMOTE algorithm randomly generates new minority sample points, which will be merged into the original. Utilizing this algorithm with a K-nearest neighbor (KNN) classifier, they managed to classify vehicles by magnetic signatures into four classes with 95% accuracy. Balid, in [
22], used various statistical measurements to classify vehicles according to an FHWA scheme. Different classifiers were tested, all reaching almost 98% accuracy.
In [
23], researchers explored the potential of estimating vehicle location using a magnetic sensor array. Although the array consisted of only two sensors, the mathematical principles can be extended to larger arrays. The vehicle, traveling parallel to the sensor array, is modeled as a magnetic dipole, generating an ideal dipole magnetic signature. While the overall accuracy was not specified, the study concluded that it is feasible to detect vehicle location using a magnetic sensor array. Similarly, Kwong [
24] developed a system for the real-time estimation of travel time across the arterial segment of 1.5 km by identifying the same vehicles. The matching procedure is based on a statistical model of signature distance. The model can be used to predict rates of correct, incorrect and missed matches. As stated by [
25], vehicle re-identification (identifying the same exact vehicle in traffic) can give essential information for traffic management about travel time and origin–destination matrices. Real-time traffic data are essential for optimizing traffic flow and reducing travel time and greenhouse gas emissions. The authors collected 261 temporal magnetic signatures from 25 different vehicles in the parking lot. A total of 10 sensors with 25 cm spacing and 200 Hz sampling frequency were used. Their findings included that the Euclidean distance and DTW (dynamic time warping) algorithms are suitable for same vehicle identification; however, performance is linked to the lateral position of the vehicle on the road.
Fourteen wireless magnetic sensors were installed in an array [
26], and vehicle signature features consisting of a collection of peak values were collected. By comparing the upstream and downstream detectors’ registered signatures and calculating different statistical features (mean, standard deviation), arrays were compared using distance metrics. The authors suggested that using their developed algorithm, the mismatch rate is around 8%, and, for congested traffic conditions, it reaches 14%. The authors of [
27] utilized six magnetic sensors with 20 cm spacing for AVMR (automatic vehicle model recognition)—given an unknown vehicle’s signature and set of a database vehicle signatures, the goal is to associate the correct vehicle model. Re-identification using DTW and machine learning models (k-NN, LMD, Gaussian classifier) has shown promising results; however, there are no experiments indicating how the algorithms would perform with new, unseen data.
The advantages of wireless sensor networks utilizing magnetic sensing are summarized in [
28]—they do not require an external power supply, they have a compact size, they minimally damage the road surface and they have resistance to interference from the urban environment. The authors emphasize as a disadvantage that magnetic sensors do not provide information about the direction of the vehicles—available systems cannot detect which gate the car entered the area through or left through. With our work, we try to challenge this statement and demonstrate that it is possible to determine specific vehicle traveling patterns in a specified area with great accuracy.
The available research is concentrated on single-magnetometer feature extraction for vehicle classification to strictly defined categories. Not much work is available on the vehicle re-identification problem—finding the same vehicle passing over sensors by comparing its magnetic signature with previously recorded signatures. Articles revolving around vehicle re-identification methods involved testing in restricted conditions or with a small data subset. In this work, a feature extraction method for a magnetometer array is proposed, and different machine learning methods are compared for same vehicle re-identification in real traffic conditions. Focus is shifted to define better input features and compare different classification algorithms.
2. Materials and Methods
Vehicles are registered using our system, presented in a previous work [
29], updated to 15 sensors with 10 cm spacing between sensors. The system constantly measures Earth’s magnetic field with tri-axis magnetic sensors, each sampled at 1 kHz frequency. Measured values are constantly detrended and register only change in the magnetic field. The magnetometer’s measuring range is set to ±400 μT, and practical experiments showed that the measured ambient noise is 1.5 μT when no vehicles or other metallic objects are near the sensors. The system starts to register magnetic signatures, then the center sensor of the array’s calculated module exceeds 5 μT and waits for a decrease in amplitude or timeout condition. Collected signatures for all sensors (matrix consisting of 15
x/y/z arrays) are transmitted to a central server. Additionally, images from a temporarily installed camera with license plate recognition are collected and saved together with a .csv file.
In the preprocessing stage, raw collected x/y/z values undergo low-pass filtering with a 100 Hz cutoff frequency in order to smooth the signal. Modules for every sensor are calculated according to the following formula:
where
—calculated module,
—raw registered values,
n—sensor number.
Signature length depends on vehicle speed and vehicle length. Many feature extraction methods and machine learning algorithms expect input data to be of uniform length. Signals with a different number of points might lead to inaccuracies and inconsistencies in the analysis. In the deployed signature collection system, vehicles travel with speeds ranging from 30 km/h to 60 km/h. Most of the time, they are light passenger cars with an average length of 4.5 m. The collected signatures sample count ranges from 600 to 1300 points. Based on these observations, it was decided to resample all signals to a fixed number of 500 points. This process involves interpolating or resampling the signals so they all have the same length regardless of the original number of data points. The vehicle signature sampling process is initiated by a single magnetometer located in the center of the array; other sensors values might be shifted with reference to this sensor depending on the angle at which the vehicle is passing through the sensors. To address these issues, all signature values are cropped to a specified threshold—5 μT. The cropping and resampling process is illustrated in
Figure 1.
For each calculated module index, we identify points where the amplitude exceeds a pre-defined threshold. This search is performed from the beginning and the end of the signal. A new array is then formed based on these identified indices. The middle of the signal is not checked as the amplitude might drop below the threshold, but it still represents an important part of the signal.
The pipeline for the experiments is outlined in
Figure 2. A record is defined as one unique vehicle passing once through the signature collection system and contains 15
x/y/z signal arrays of registered magnetic distortions. The collected database contains numerous different vehicles with multiple records. Information about vehicle make, model and driving trajectory is taken from the registered image. For experimentation, we select subsets from the database with the required number of vehicles
, each containing
passing entries from passing through the system. Constraints are added so that no vehicles of the same model should exist, and driving direction must be the same. One subset is selected for training samples and another subset for testing. Record comparison, pair generation, feature extraction, model training and evaluation are performed in parallel, applying the same actions.
Record pairs labeled “same” are defined as pairs of records that refer to the signatures from the same unique vehicle, while “different” records refer to pairs of records that refer to signatures from different vehicles. In our experiment, we used these definitions to evaluate the performance of our algorithm in distinguishing between matching (same) and non-matching (different) records. An example of the records is shown in
Figure 3.
The comparison pair generation algorithm (Algorithm 1) involves two steps—generating pairs for the same vehicles and, after that, pairs for different vehicles. Empty lists are initialized to store references to records. Each vehicle is iterated, and all record pairs are added to the list. Same records are not compared to themselves; in this way, the maximum number of “same” labels are created. In order to have a balanced dataset, an equal number of different record pairs should exist. For different record comparison pairs, two vehicles are randomly selected and checked to see whether they are different, and then a random record is selected for each vehicle. This process is repeated until different vehicle comparison pairs have an equal number to the same vehicle comparison pairs. The condition exists that randomly selected records cannot repeat.
Algorithm 1. Generate Comparison Pairs |
1: Input: Database of n vehicles, each with m records 2: Output: Comparison pairs for each vehicle and between different vehicles 3: Initialize empty list sameVehiclePairs 4: Initialize empty list differentVehiclePairs >Generate same-vehicle comparison pairs 5: for each vehicle v ∈ {1, 2, …, n} do 6: for each record ri ∈ {1, 2, …, m − 1} do 7: for each subsequent record rj ∈ {ri + 1, ri + 2, …, m} do 8: Add (v, ri, rj) to sameVehiclePairs 9: end for 10: end for 11: end for >Generate different-vehicle comparison pairs 12: countSamePairs ← length of sameVehiclePairs 13: while length of differentVehiclePairs ¡ countSamePairs do 14: Randomly select two different vehicles v1 and v2 from {1, 2, …, n} 15: if v1 ≠ v2 then 16: Randomly select one record ri from v1 and one record rj from v2 17: Add (v1, ri, v2, rj) to differentVehiclePairs 18: end if 19: end while |
After extensive analysis of the magnetometers axis values and modules comparison, the decision was made to use the calculated signature modules processed as explained earlier. An example of the registered magnetic signature modules for the same vehicle driving through the system is shown in
Figure 4. Based on the collected signal analysis, it is evident that at least one side of the vehicle’s wheels is always presented in the single passing vehicle record, as shown in figure by the red dotted line. Sensors which are affected by the wheels register a distorted signature, usually with a much higher amplitude or unpredictable shape. Data of such sensors should be omitted from direct signal comparison. An example of different vehicles’ signatures is presented in
Figure 5. It is evident that the signatures’ shape and amplitudes are significantly different between these two records.
Vehicle re-identification is performed by searching for similarities between the registered magnetic signatures modules. The challenge lies in discovering how to effectively evaluate these similarities. Different feature extraction ideas were tested. Every vehicle has a unique signature, although certain common attributes which are repeating between different vehicles can be observed. The shape of the module initially is always rising and reaches the maximum signal value or intermediate maximum. These ascents and descents can look like a parabola or an inverted parabola. Different vehicles have different numbers of intermediate maximum values in different locations. These amplitude values and location indices could be used as feature values. Signature shape approximation and single sensor values’ relations to neighboring sensors’ relations were investigated. These strategies were evaluated using stem plot diagrams but yielded unsatisfactory results that are not presented in this study. For vehicle re-identification, the following feature vectors were composed which showed less overlapping between same and different vehicle records:
Module amplitude maximum location differences;
Five maximum corr-coefficients from correlation matrix;
Ten corr-coefficients from best diagonal;
Five corr-coefficients calculated using vehicle center sensor;
Ten corr-coefficients from best diagonal and ten Euclidean distance values.
All feature vectors were calculated with normalized signature modules. Normalization was performed record-wise by taking all signatures of one record, finding the maximum amplitude and dividing all signatures by this value. This is the most reasonable approach because, if normalization were performed for every sensor separately, important information about amplitude differences between neighboring sensors would be lost. Without normalization, absolute amplitude difference information is presented which can better distinguish the same vehicles; however, in this case, the dynamic range can be high and unpredictable. To tackle this problem, it is feasible to perform value constraint in the feature extraction step so the machine learning algorithm obtains values defined in a specific range.
Feature vector 1 consists of 15 differences between module maximum indices. The idea is that same vehicle records will have smaller distance values compared to different vehicles. The vector is calculated using the following formula:
where
is the calculated distance value between indices for sensor
;
corresponds to the signature module for record 1 and
for record 2; function
returns the maximum value of the array; function
returns the array index.
Other feature vectors are calculated using correlation and Euclidean distance matrices. The matrices result in a 15 × 15 array while calculating values between all sensor pairs according to the following formula:
where
is the covariance between two time series—it measures the degree to which two variables change together—and
are standard deviations of the time series for every sensor
. Analogically, the Euclidean distance matrix is calculated using the following formula:
where
is the Euclidean distance value, and
are signature modules for every sensor. An example of calculated matrices for same and different vehicles is shown in
Figure 6.
The assumption is made that same vehicle records will have higher correlation coefficients and smaller Euclidean distance values compared to different vehicles’ records. Feature vector 2 is based on this assumption and uses the five highest correlation matrix values as a feature. Additionally, as can be seen from
Figure 6, for same vehicles, it is possible to distinguish a single diagonal for the largest correlation coefficients and smallest Euclidean distances just by looking at the first 10 maximum (minimum for Euclidean distance) values. In an ideal driving trajectory, when the same vehicle ideally passes sensors, this diagonal should appear between the same sensor pairs—(0, 0), (1, 1), (2, 2) and so on. However, depending on the vehicle trajectory, this diagonal could be shifted. For feature vector 3, ten correlation coefficients taken from the diagonal are used, so the diagonal can be offset by −5 to +5 indices from the center position. The algorithm for best diagonal selection (Algorithm 2) is as follows:
Algorithm 2. Find Best Diagonal in Matrix |
1: procedure FindBestDiagonal(matrix) 2: avg arr ← [] 3: for shift in [−5, 5] do 4: diagonal ← GetDiagonal(matrix, shift) 5: avg ← Mean(diagonal) 6: avg arr.append(avg) 7: end for 8: ind ← ARGMAX(avg_arr) 9: best_shift ← ind – 5 10: best diagonal ← GetDiagonal(matrix, best shift) 11: return best diagonal 12: end procedure 13: 14: procedure GetDiagonal(matrix, shift) 15: diagonal ← [] 16: for i in [0,15 − |shift|] do 17: if shift > 0 then 18: diagonal.append(matrix[i, i + shift]) 19: else 20: diagonal.append(matrix[i + |shift|, i]) 21: end if 22: end for 23: return diagonal 24: end procedure |
The algorithm identifies the most significant diagonal in a given matrix by evaluating the average values of diagonals shifted within a range from −5 to +5. For each possible shift, the resulting diagonal average is calculated. For correlation values, the diagonal with the highest average is selected, and, for Euclidean distance values, the diagonal with the lowest average is selected. The resulting diagonal is an array with 10 values extracted from the matrix. Feature vector 5 is similar; only values are taken from both matrices (correlation and Euclidean).
Feature vector 4 focuses around center sensor and two neighboring sensors from both sides. As explained in our previous work [
25], it is complicated to decide which sensor is in the middle of the vehicle. The purpose of focusing on the center sensor is to mitigate the influence of the vehicle wheels on the magnetic signature, as described earlier. If the center sensor is correctly labeled, there is no need to calculate the matrix for all sensor pairs, but only for corresponding sensors. This simplifies calculations and directly returns five element feature vectors. Records used for analysis were manually inspected, and the center sensor position was labeled. An example of two different vehicles’ signatures revolving around the center sensor and without wheel influence is shown in
Figure 7. Vehicle 1 is an Opel hatchback, and vehicle 2 is a VW panel van; however, the processed and resampled signature modules visually are similar because of the first rising edge (samples 0–130). A similar signature shape raises the correlation coefficients, which are around 0.94. Usually this high a correlation value suggests that the compared records originate from the same vehicles. Although the signature shape follows a similar pattern, the amplitude differs, and the Euclidean distance matrix can help separate it into different vehicles because maximum values are not concentrated on the diagonal but are chaotic. Based on this observation, feature vector 5 was composed containing ten maximum correlation values and ten minimum Euclidean distance values extracted from the best diagonal.
During the experiments, different methods for feature extraction were analyzed, and it was noticeable that the Pearson correlation coefficient and Euclidean distance emerged as the optimal parameters based on their computational efficiency, which allowed for the accurate comparison of records while minimizing processing time. Feature sets are composed of calculated feature vectors for generated comparison pairs.
In the results section, there is a comparison of accuracy, and calculation time is evaluated for the presented feature sets. Accuracy is evaluated by calculating the confusion matrix and accuracy metrics.
3. Results
The used dataset consists of 300 different vehicles passing the sensor in the same direction three times in real traffic conditions. Comparison pairs were generated, as explained earlier, resulting in 900 entries for same vehicle record pairs and 900 entries for different vehicles. Of all the pairs, 70% were used for training and 30% for testing. A feature boxplot of correlation coefficient features using the diagonal with the preselected center sensor (feature vector 4) is presented in
Figure 8. For different vehicle records, correlation values had a wide range but were concentrated below 0.95. For the same vehicle records, the median was above 0.97; however, outliers existed. After inspecting the comparison pairs for the same vehicles with low correlation values, it was noted that incorrect center sensor selection generates more outliers in same vehicle comparison pair features. This suggests that, in order to reduce outliers, it is necessary to perform relabeling for the selected center sensor, oruse a magnetic sensor array with smaller spacing or a different similarity evaluation method which is not affected by wheel-distorted signatures.
Seven different machine learning models for the classification problem were tested using the earlier-defined input feature sets. Linear regression was the simplest model. After training, model weights were calculated, which were used on input data, and summed together, and the activation function was applied. After training the model with simple feature sets (one value for one sensor pair) for correlation and amplitude differences and sorting calculated weights by importance, no significant sensor was noted—every time, a different sensor had the highest weight.
The nearest neighbor algorithm complexity is determined by value k. A higher value can give more accurate classification; however, the model might become overfitted and poorly generalize new unseen data. Value k = 3 was empirically selected after exploring small training/testing subsets. The KNN algorithm computes distances between input features and trained samples and, based on majority vote, finds the closest neighbor sample. Intuitively, features for the same vehicle are closer together than for different vehicles.
The support vector machine model creates a hyperplane separating input features into two categories for same and different vehicles. Although the model is more aimed at high-dimensional feature space where the feature count exceeds sample count, it worked correctly in the vehicle re-identification task. Different kernel functions can be used to capture complex feature relationships. A linear kernel was selected.
The Naïve Bayes classifier works with probabilities based on Bayes’ Theorem. The Gaussian Naïve Bayes classifier was used. The model was fitted by finding the mean and standard deviation of the two vehicle classes’ input features.
A decision tree aims to create a tree-like model for decisions based on input features. Values are best split into homogeneous subsets with respect to the target variable. These models are transparent and intuitive, allowing us to understand and explore relationships within the data. By constructing multiple instances of decision trees during training time, a Random Forest classifier is achieved.
The Gradient Boosting Machine (GBM) is a powerful ensemble machine learning technique suitable for classification tasks. The boosting method converts weak learners into strong learners.
Models were compared using accuracy, precision and recall metrics, which are summarized in
Table 1. It is notable that different methods yielded varying levels of accuracy across different feature sets. For instance, the Random Forest and Gradient Boosting Machine consistently demonstrated higher accuracy across most features compared to other methods. In this re-identification task, it was important to capture all positive indices (recall)—vehicle records which correspond to the same vehicle. While some methods exhibited high precision but lower recall (e.g., Naïve Bayes), others achieved a balance between precision and recall (e.g., Gradient Boosting Machine). The performance of each method varied across different features, indicating the importance of feature selection.
Different machine learning models were compared using a Receiver Operating Characteristic (ROC) curve. It illustrates the performance of a binary classification model across different discrimination thresholds. The true-positive rate is plotted against false-positive rates at various thresholds. ROC curves for different analyzed feature sets are shown in
Figure 9. Feature sets that only include correlation coefficients or amplitude evaluations tend to perform worse compared to feature sets that combine both types of features. This highlights the benefit of mixing signature amplitude and shape evaluation. These findings underscore the significance of feature engineering in signature re-identification tasks, emphasizing the critical role played by feature selection and combination strategies.
4. Discussion
In this paper, a novel methodology for feature extraction and signature comparison using a magnetometer array is presented. Raw registered signals were preprocessed and different feature sets extracted.
Using only correlation features and ignoring amplitudes gives bad re-identification accuracy because different vehicle signatures can have a similar shape. Alternatively, when using only amplitude difference, same vehicle records might appear as different because registered amplitude values fluctuate based on driving pattern.
Combining correlation coefficients with amplitudes for specific sensor pairs gives the best re-identification accuracy, which reaches 98% with the Random Forest algorithm.
Choosing a machine learning algorithm is not critical. With a good feature set, all tested algorithms perform well, with accuracy reaching 97%, while, with a bad feature set, the accuracy gap is more visible—achieving accuracy values of 76–93%. The best accuracy is reached with the Random Forest algorithm and KNN. In all cases, the traditional decision tree’s performance is the worst.
The proposed method does not require the intensive computation associated with deep learning models, making it more suitable for real-time applications and deployment in resource-constrained environments. Unlike deep-learning-based methods, our approach ensures anonymity by not relying on image or video data, which often contain personally identifiable information.