A smart sensor-based online detection method and system for metal impurities in food
By using multi-band electromagnetic signal synchronous transmission and reception and an improved FastICA blind source separation algorithm, combined with lightweight deep learning and DS evidence theory, the problems of cross-interference and misjudgment in traditional detection methods are solved, achieving high-precision and stable online detection of metal impurities in food, and adapting to complex industrial environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIANGXI WEIRBAO FOOD BIOTECH
- Filing Date
- 2026-04-09
- Publication Date
- 2026-06-30
AI Technical Summary
Traditional online detection methods for metal impurities in food are susceptible to cross-interference from food matrix, packaging materials and environmental noise, resulting in low recognition sensitivity and high false positive rate. Furthermore, existing machine learning-based detection schemes have weak generalization ability, cannot adapt to complex industrial production environments, lack adaptive calibration mechanisms, and are difficult to meet the requirements of high precision and high stability.
By employing synchronous transmission and reception of multi-discrete frequency band electromagnetic signals, combined with an improved FastICA blind source separation algorithm and wavelet packet transform, a multi-frequency feature-blind source separation dual-layer model is constructed. Through the fusion of traditional machine learning and lightweight deep learning hybrid models, DS evidence theory is introduced, and decision rules are dynamically adjusted in conjunction with real-time parameters of the production line. Online incremental learning is achieved through federated learning, and a lightweight inference engine is constructed to ensure the efficient operation of edge devices.
It significantly improves the sensitivity and anti-interference ability of identifying minute metal impurities, reduces the false detection rate, adapts to different food categories and complex production environments, achieves high-precision detection, and operates stably under network outage conditions, meeting the long-term reliable detection needs of food industry production lines.
Smart Images

Figure CN122307738A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of online detection technology for metal impurities in food, and particularly relates to an intelligent sensor-based online detection method and system for metal impurities in food. Background Technology
[0002] Traditional online detection of metal impurities in food often employs single-band electromagnetic induction or X-ray detection. Single-band detection is susceptible to cross-interference from food matrix, packaging materials, and environmental noise, resulting in low sensitivity for identifying minute metal impurities. X-ray detection, on the other hand, poses radiation safety hazards and is unsuitable for diverse detection scenarios such as flexible packaging and liquid foods. These traditional systems all use fixed threshold decision logic and fail to dynamically adjust the judgment rules based on real-time production line conditions such as production speed, temperature, and humidity. Consequently, the false positive and false negative rates remain high in complex industrial production environments, making it difficult to meet the high-precision and high-stability online detection requirements of the entire food production process.
[0003] Existing solutions for detecting metal impurities in food based on machine learning and deep learning generally suffer from weak model generalization ability and poor adaptability to edge device deployment. They fail to effectively decouple metal signals from interference signals through blind source separation technology, and feature extraction and dimensionality reduction methods are simplistic. Furthermore, they often employ centralized model training modes, which cannot achieve online incremental learning while ensuring local data privacy. They lack adaptive calibration mechanisms when facing signal feature drift, and hybrid model decision-making does not integrate evidence theory and intelligent optimization strategies. Moreover, they do not use heterogeneous computing architectures to collaboratively execute detection tasks, and cannot operate continuously under network outage conditions, making them unsuitable for long-term, continuous, and highly reliable detection application scenarios in industrial production lines. Summary of the Invention
[0004] In view of the aforementioned problems, and in conjunction with the first aspect of the present invention, embodiments of the present invention provide an intelligent sensing-based online detection method for metal impurities in food, the method comprising: Simultaneously transmit and receive multiple discrete frequency band electromagnetic signals, and generate a multi-dimensional original signal matrix by taking advantage of their different responses to metals, food, packaging and environment; Based on the fusion of the improved FastICA blind source separation algorithm and wavelet packet transform, a two-layer model of multi-frequency feature-blind source separation is constructed. The effectiveness of signal separation is verified by relying on a multi-scenario standard signal feature library and cosine similarity matching. After feature extraction and combined dimensionality reduction, the output is fused through a hybrid model of traditional machine learning and lightweight deep learning. The DS evidence theory is introduced and combined with real-time parameters of the production line to dynamically adjust the decision rules. An online incremental learning framework is built based on federated learning. Feature drift detection and automatic parameter adjustment are achieved through KL divergence and PSI index. A dynamic adjustment strategy library is constructed by combining Q-Learning agent. We construct a data-enhanced labeled sample dataset, optimize the model through knowledge distillation and domain adversarial neural networks, and develop a lightweight inference engine for edge devices. The detection function is executed based on the heterogeneous architecture of MCU and FPGA / TPU, and the local cache ensures operation when the network is not connected. The model is optimized through edge and cloud collaboration, and the data processing-related links are optimized in sync.
[0005] Furthermore, embodiments of the present invention also provide an intelligent sensor-based online detection system for metal impurities in food, characterized in that it includes: A processor; a machine-readable storage medium for storing machine-executable instructions of the processor; wherein the processor is configured to perform the above-described intelligent sensing-based online detection method for metal impurities in food by executing the machine-executable instructions.
[0006] In another aspect, embodiments of the present invention also provide a computer program product, the computer program product including machine-executable instructions, the machine-executable instructions being stored in a computer-readable storage medium, the processor of a computer device reading the machine-executable instructions from the computer-readable storage medium, the processor executing the machine-executable instructions, causing the computer device to execute the above-described intelligent sensor-based online detection method for metal impurities in food.
[0007] Based on the above, by synchronously transmitting and receiving multi-discrete frequency band electromagnetic signals and improving the FastICA blind source separation dual-layer model, the metal impurity signal can be accurately decoupled from the food matrix, packaging, and environmental interference signals, significantly improving the identification sensitivity and anti-interference ability of tiny metal impurities. Combining traditional machine learning and lightweight deep learning hybrid models, DS evidence theory decision fusion, and dynamically adjusting the judgment rules according to the real-time working conditions of the production line, the detection false judgment rate and false negative rate can be effectively reduced, and it can adapt to the high-precision detection needs of different food categories, packaging types, and complex production environments.
[0008] This invention employs a federated learning online incremental learning and feature drift adaptive calibration mechanism to achieve continuous iterative optimization of the model while ensuring the local privacy of production data, thereby significantly improving the system's generalization and environmental adaptability. Through knowledge distillation, domain adversarial neural network optimization, and a lightweight inference engine, combined with heterogeneous computing power collaboration between MCU and FPGA / TPU and a hierarchical local caching design, it enables low-power, high-real-time deployment of edge devices, allowing for stable and continuous operation even under network outage conditions, fully meeting the requirements of long-term, efficient, and reliable online detection applications in food industry production lines. Attached Figure Description
[0009] Figure 1 This is a schematic diagram of the execution flow of the intelligent sensor-based online detection method for metal impurities in food provided in an embodiment of the present invention.
[0010] Figure 2 This is a schematic diagram of exemplary hardware and software components of the intelligent sensor-based online detection system for metal impurities in food provided in an embodiment of the present invention. Detailed Implementation
[0011] The present invention will now be described in detail with reference to the accompanying drawings. Figure 1 This is a flowchart illustrating an embodiment of the intelligent sensor-based online detection method for metal impurities in food provided by the present invention. The following is a detailed description of the intelligent sensor-based online detection method for metal impurities in food.
[0012] Step S110: Simultaneously transmit and receive multiple discrete frequency band electromagnetic signals, and generate a multi-dimensional original signal matrix by utilizing their differences in response to metals, food, packaging and environment; The synchronously transmitted and received multi-discrete frequency band electromagnetic signals cover the low-frequency band (1kHz-1MHz), the mid-frequency band (1MHz-10MHz), and the high-frequency band (10MHz-100MHz). Utilizing the eddy current loss of electromagnetic signals in metallic materials, the dielectric loss of food substrates, the reflection attenuation of packaging materials, and the random disturbances of environmental noise, a multi-dimensional original signal matrix is generated. During signal transmission and reception, a multi-channel synchronous control mechanism ensures the timing consistency of signal transmission and reception across all frequency bands. The original signal matrix is set to M×N×K, where M is the number of time sampling points (ranging from 1024 to 4096), N is the number of frequency bands (configured as 8-16 channels according to detection requirements), and K is the number of feature types (initially including four types: time-domain amplitude, time-domain phase, frequency-domain amplitude, and frequency-domain phase). This matrix directly correlates with the response characteristics of targets and interference in different frequency bands.
[0013] Step S111: Select a multi-channel signal generator based on direct digital synthesis technology. This signal generator supports synchronous output of multiple independent frequency bands. Each frequency band can be configured independently within a set frequency range. Divide the low-frequency band, mid-frequency band, and high-frequency band according to the detection requirements and allocate the corresponding number of channels. Perform amplitude and phase calibration on each signal. The AD9910 Direct Digital Synthesis (DDS) signal generator was selected, supporting 16 independent frequency band synchronous outputs, with a frequency resolution of 1Hz per band, meeting the flexible configuration requirements of the detection frequency bands. Divided by detection scenario: 4 channels for the low-frequency band (1kHz-1MHz), 6 channels for the mid-frequency band (1MHz-10MHz), and 6 channels for the high-frequency band (10MHz-100MHz); the amplitude of each signal is adjustable from 0.5V to 5V, with a phase adjustment accuracy of ±0.1°. Amplitude calibration uses an Agilent 3458A digital multimeter to measure the peak value of the output signal, compares it with the set value, and corrects the deviation through the DDS internal register; phase calibration uses a Tektronix MDO3024 oscilloscope to acquire the phase difference between the reference signal and the output signal, and compensates for the phase shift through software algorithms, ensuring that the amplitude error of each signal is ≤±2% and the phase error is ≤±1°, guaranteeing the consistency and accuracy of multi-band signal transmission.
[0014] Step S112: Design the transmitting coil according to the electromagnetic characteristics of each frequency band. Different frequency bands have corresponding adaptive transmitting coils. Each frequency band is equipped with an independent transmitting coil. An impedance matching network is formed by an LC resonant circuit composed of inductors and capacitors to match the coil impedance with the output impedance of the signal generator. The transmitting coil is wound with φ0.5mm copper enameled wire. The low-frequency coil has 80-120 turns and a diameter of 50mm, the mid-frequency coil has 40-60 turns and a diameter of 30mm, and the high-frequency coil has 20-30 turns and a diameter of 20mm. Different frequency band coils are matched using different core materials (ferrite core for low frequency, hollow core for mid- and high-frequency). The LC resonant circuit consists of a fixed inductor and a variable capacitor. The inductance value is matched to the inductance of the corresponding frequency band coil. The variable capacitor's adjustment range is 10pF-1000pF. The coil impedance (typically 50Ω-200Ω) is measured using an impedance analyzer. The capacitor value is adjusted to make the LC circuit resonant frequency match the center frequency of the corresponding frequency band, achieving impedance matching between the coil and the 50Ω output impedance of the signal generator. This ensures a standing wave ratio (VSWR) ≤1.2, minimizing signal reflection loss and improving electromagnetic energy transmission efficiency.
[0015] Step S113: Use a high-precision time synchronization module or network clock protocol to provide a unified clock reference for the signal generator, data acquisition card and sensor array. Design a hardware trigger synchronization circuit, and output a synchronization trigger signal from the main control MCU to synchronously start the multi-band signal transmission of the signal generator and the signal reception of the data acquisition card. The system employs a GPS / BeiDou dual-mode timing module (model UBLOX M8T) with a timing accuracy of ≤10ns. It also supports NTP / PTP network clock protocol backup, providing a unified clock reference for the signal generator, data acquisition card, and sensor array. The hardware trigger synchronization circuit consists of an STM32H743 main control MCU, a 6N137 optocoupler isolation chip, and a trigger signal amplification circuit. The synchronization trigger signal output by the MCU is isolated and amplified before being sent to the external trigger terminal of the signal generator and the start-up acquisition terminal of the data acquisition card, respectively, with a trigger delay of ≤50ns. The synchronous start-up mechanism ensures that the data acquisition card begins receiving induction signals simultaneously with the signal generator transmitting multi-frequency signals, avoiding signal distortion caused by timing misalignment. The clock synchronization signal transmission uses shielded cable to reduce the impact of electromagnetic interference on synchronization accuracy and ensure timing consistency for multi-device collaborative operation.
[0016] Step S114: Configure the receiving coil array corresponding to the transmitting coil. Each receiving coil is coaxially arranged with the transmitting coil to form a transmitting and receiving pair structure. Design a signal conditioning circuit for the signal characteristics of different frequency bands. The circuit includes a low-noise preamplifier, a bandpass filter and a differential amplifier circuit to convert the received weak electromagnetic induction signal into a standard analog signal. The receiving coil array corresponds one-to-one with the transmitting coil. Each receiving coil and transmitting coil are coaxially arranged with a fixed axial spacing of 5mm. The coil parameters are consistent with the corresponding frequency band transmitting coil to optimize coupling. The signal conditioning circuit uses an AD8421 low-noise preamplifier with an input offset voltage ≤10μV and an adjustable voltage gain range of 1-1000 times, amplifying the received μV-level weak signal to the mV level. The bandpass filter adopts an active RC filter structure with a center frequency consistent with the corresponding frequency band and a 3dB bandwidth 1.2 times the frequency band width, effectively filtering out noise outside the frequency band. The differential amplifier circuit uses an INA128 chip with a common-mode rejection ratio ≥100dB, further suppressing common-mode interference. Through three-stage circuit conditioning, the received electromagnetic induction signal is converted into a 0-5V standard analog signal, improving the signal-to-noise ratio to over 40dB, meeting the input requirements for subsequent ADC acquisition.
[0017] Step S115: Select a multi-channel high-speed ADC acquisition card. The number of channels on the acquisition card is the same as the number of transmission frequency bands to achieve independent acquisition of each frequency band signal. The timing control of ADC acquisition is implemented through FPGA. The DMA direct memory access method is adopted to convert the acquired analog signal into a digital signal and store it directly in the buffer. During the acquisition process, a timestamp is added to each data channel through a clock synchronization signal. The ADS8688 multi-channel high-speed ADC acquisition card is selected, featuring 16 synchronous acquisition channels, a sampling rate of up to 1MSps, and a 16-bit resolution, perfectly matching the number of transmission bands and enabling independent acquisition of each band's signal. The FPGA used is a Xilinx Artix-7 series (model XC7A35T), with timing control logic written in Verilog to generate the clock signal (the sampling clock frequency is proportional to the center frequency of the corresponding band, ranging from 1MHz to 10MHz) and control signals required for ADC acquisition. Data transmission employs DMA (Direct Memory Access). The digital signal converted by the ADC is buffered by the FPGA and then directly written to an 8GB DDR4 cache via a PCIe 2.0 interface, achieving a transfer rate ≥1GB / s and avoiding latency caused by CPU intervention. During acquisition, each data point is identified using the format "UTC time + millisecond-level timestamp," with a timestamp error ≤1ms, ensuring the time correlation and traceability of multi-band data.
[0018] Step S116: Frequency band response characteristic calibration and compensation. In a standard environment without metal or interference, the signals of each frequency band are calibrated. Blank sample response signals of different food matrices and packaging materials are collected. The amplitude and phase calibration coefficient matrix of each frequency band is established. The ambient temperature is collected in real time through a temperature sensor. The collected signals are dynamically compensated using a pre-stored temperature compensation model. The standard calibration environment was controlled at a temperature of 25℃±2℃ and a relative humidity of 50%±5%, free from metallic interference and with electromagnetic shielding effectiveness ≥80dB (1kHz-100MHz). Blank samples were collected covering 10 common food substrates such as pork, biscuits, and milk powder, and 5 packaging materials including plastic, paper, and aluminum foil. Each sample was collected 20 times. Statistical analysis was used to calculate the amplitude calibration coefficient (range 0.95-1.05) and phase calibration coefficient (range -5°-5°) for each frequency band, constructing a 2×N dimensional calibration coefficient matrix (N being the number of frequency bands). The DS18B20 temperature sensor was selected, with a measurement range of -40℃-85℃ and an accuracy of ±0.5℃. Ambient temperature was collected in real time and transmitted to the MCU. The temperature compensation model used a cubic polynomial fitting (fitting formula T). comp =aT³+bT²+cT+d, where a, b, c, and d are pre-stored fitting coefficients), dynamically adjust the signal amplitude and phase according to the real-time temperature, compensate for the error ≤±3%, and eliminate the influence of temperature changes on signal acquisition.
[0019] Step S117: Using timestamps as indexes, arrange the digital signals acquired from each frequency band in a time sequence to form a single-band time-domain signal vector. Perform a fast Fourier transform on each time-domain signal to extract frequency-domain amplitude and phase features, forming a single-band frequency-domain signal vector. Integrate the time-domain vectors and frequency-domain vectors of all frequency bands into a three-dimensional structure of time dimension, frequency band dimension, and feature dimension to construct a multi-dimensional original signal matrix. The feature dimension of this matrix includes four basic features: time-domain amplitude, time-domain phase, frequency-domain amplitude, and frequency-domain phase.
[0020] Using timestamps as unique indexes, the digital signals of each frequency band are arranged in chronological order of acquisition time, forming a single-band time-domain signal vector of length M (1024-4096). A 1024-point Fast Fourier Transform (FFT) is performed on each time-domain signal to extract amplitude (peak value) and phase (phase at the main frequency point) features within the 0-50MHz frequency range, forming the corresponding frequency-domain signal vector. The multi-dimensional original signal matrix is integrated in a three-dimensional structure: the first dimension is the time dimension (M sampling points), the second dimension is the frequency band dimension (N frequency bands), and the third dimension is the feature dimension (containing four basic features: time-domain amplitude, time-domain phase, frequency-domain amplitude, and frequency-domain phase). The matrix dimension is represented as M×N×4. The unit for time-domain amplitude is V, the unit for time-domain phase is °, the unit for frequency-domain amplitude is dBm, and the unit for frequency-domain phase is °. All feature values are uniformly retained to two decimal places to ensure the standardization and operability of the matrix data.
[0021] Step S120: Based on the fusion application of the improved FastICA blind source separation algorithm and wavelet packet transform, a multi-frequency feature-blind source separation two-layer model is constructed. The effectiveness of signal separation is verified by relying on the multi-scenario standard signal feature library and cosine similarity matching. The multi-frequency feature-blind source separation dual-layer model is built on the PyTorch framework, integrating an improved FastICA blind source separation algorithm and wavelet packet transform technology. The model runs on an Ubuntu 20.04 operating system, with hardware relying on a CPU (Intel i7-12700K) and GPU (NVIDIA RTX 3090) for collaborative computing. A multi-scenario standard signal feature library is stored on a 1TB SSD, covering signal samples from 20 food matrices, 10 packaging types, 8 environmental noises, and 15 specifications of metal impurities (diameter 0.1mm-5mm, materials including iron, copper, and aluminum), totaling ≥100,000 samples. Signal separation effectiveness is verified by calculating the cosine similarity between the separated signal and the standard feature library. The similarity calculation uses the vector dot product formula: cosθ=(A・B) / (|A||B|), where A is the separated signal feature vector and B is the standard feature template vector. This model and verification mechanism are used to verify the effectiveness of the signal separation.
[0022] Step S121: Adaptive median filtering is used to suppress impulse noise in the multi-dimensional original signal matrix, and missing sampling points in the signal acquisition process are completed by linear interpolation. The signals of each frequency band are time-aligned based on the timestamp information. The adaptive median filter dynamically adjusts its window size based on signal noise intensity. The initial window is 3×3, and when impulse noise (amplitude exceeding three times the standard deviation of the mean) is detected, the window automatically expands to 5×7. During filtering, signal peak characteristics are preserved to avoid loss of effective information. Missing signal sampling points are filled in using bilinear interpolation, with an interpolation error ≤ ±2%. For differences in acquisition delay across frequency bands, time alignment is performed using linear interpolation based on timestamp information, resulting in a time deviation of ≤ 1 μs for each frequency band after alignment. During preprocessing, an outlier detection algorithm (based on the 3σ criterion) identifies and removes signal points with abnormal acquisition (≤ 0.5%). Simultaneously, trend term removal is performed (using least squares to fit the trend term and subtract it) to ensure signal stability after preprocessing, providing a high-quality data foundation for subsequent feature extraction.
[0023] Step S122: For the time-domain signal of each frequency band, set a wavelet basis function that fits its frequency range, dynamically adjust and determine the optimal decomposition level according to the frequency band width and signal complexity to ensure that the target signal frequency band is covered after decomposition, perform wavelet packet decomposition on each frequency band signal, obtain the high-frequency and low-frequency coefficients of each decomposition node, calculate the energy, entropy value, peak factor and kurtosis feature of each node, form a time-domain-frequency domain joint feature vector of a single frequency band, and concatenate the feature vectors of all frequency bands according to the frequency band dimension to construct a global multi-frequency feature matrix; The low-frequency band (1kHz-1MHz) uses the db4 wavelet, the mid-frequency band (1MHz-10MHz) uses the sym5 wavelet, and the high-frequency band (10MHz-100MHz) uses the coif3 wavelet. The number of decomposition layers is adaptively determined by the signal-to-noise ratio (SNR): the SNR of each frequency band is calculated, and 3 layers are decomposed when SNR ≥ 30dB, 4 layers when SNR ≤ 20dB < 30dB, and 5 layers when SNR < 20dB, ensuring that each node covers the target signal frequency band after decomposition. After wavelet packet decomposition, the energy (sum of squared coefficients), information entropy, peak factor (peak value / RMS value), and kurtosis (fourth-order central moment / squared variance) of each node are calculated to form a 16-dimensional single-band time-domain-frequency domain joint feature vector. The feature vectors of all frequency bands are concatenated in frequency band order to construct a global multi-frequency feature matrix of dimension M×(N×16) (M is the number of samples, N is the number of frequency bands), which comprehensively characterizes the time-domain and frequency-domain characteristics of the multi-band signal.
[0024] Step S123: An adaptive regularization term is introduced on the basis of the traditional FastICA algorithm. This regularization term dynamically adjusts the penalty coefficient based on the local signal-to-noise ratio of the signal. When the signal noise is strong, the penalty weight is increased to suppress noise interference. Negative entropy is used as the signal independence metric to optimize the algorithm objective function. The separation matrix is solved by Newton's iteration method. The algorithm convergence speed is accelerated by dynamically adjusting the iteration step size. The global multi-frequency feature matrix is used as the input of the improved FastICA algorithm. The adaptive regularization term of the improved FastICA algorithm is defined as λ = 0.8 / SNR, where SNR is the local signal-to-noise ratio (sliding window size of 50 sampling points). When SNR < 10dB, λ automatically increases to 1.2 to enhance noise suppression; when SNR ≥ 20dB, λ decreases to 0.5 to reduce interference with the effective signal. Negative entropy is used as the signal independence metric, and the objective function is J(y) = E[G(y)] - E[G(v)]² (v is a Gaussian random variable, and G is a nonlinear function tanh(y)). The separation matrix W is solved using the Newton-Raphson iteration method, and the iteration formula is W... new =W old +(IE[tanh(y)yᵀ])W old The iteration step size is dynamically adjusted: the initial step size is 0.1, the step size increases to 0.2 when the iteration error > 1e-4, and decreases to 0.05 when the iteration error < 1e-5. The iteration termination condition is ||W new -W old || < 1e-6 or the number of iterations ≥ 100. The global multi-frequency feature matrix is standardized (mean 0, variance 1) before being input into the algorithm to ensure convergence speed and separation accuracy.
[0025] Step S124: Build a two-layer serial model architecture. The first layer is a multi-frequency feature enhancement layer. The multi-frequency feature matrix extracted by wavelet packet transform is mapped through a fully connected layer to enhance the feature differences between the metal signal and various interference signals and output the enhanced feature matrix. The second layer is a blind source separation layer. The enhanced feature matrix is input into the improved FastICA algorithm. The first layer has 256 neurons, using a linear activation function y=wx+b, with weights w initialized to a He normal distribution and bias b initialized to 0. The second layer has 128 neurons, using a ReLU activation function y=max(0,wx+b), and a Dropout layer (dropout rate=0.2) is embedded to suppress overfitting. In the feature preprocessing stage, the global multi-frequency feature matrix is mapped to the [0,1] interval through Min-Max normalization, and redundant features with variance <0.01 are removed using a variance screening method, retaining 80% of the features strongly correlated with metal signals and interference signals. The enhanced features are then centered (subtracting the mean vector) and whitened before being input into the improved FastICA blind source separation layer. After the model is concatenated end-to-end, it is trained for 100 rounds using the Adam optimizer (learning rate 0.001) to solidify the optimal network weights and separation parameters. The separation effect feedback mechanism sets a separation accuracy threshold of 95%. When the accuracy is lower than the threshold, the weights and regularization coefficients of the fully connected layer are fine-tuned in steps of 0.05 to ensure the separation effect of real-time signal processing.
[0026] Step S1241: Perform numerical normalization on the global multi-frequency feature matrix output by wavelet packet transform to eliminate the dimensional differences and numerical offsets between features of different dimensions, map all feature values to a unified numerical range, remove redundant feature dimensions, and retain features that are strongly correlated with metal signals and interference signals to obtain regular input data. The global multi-frequency feature matrix (dimension M×F, where M is the number of samples and F is the number of features) output by wavelet packet transform is normalized using Min-Max normalization, with the normalization formula being x. norm =(xx min ) / (x max -x min ), where x min x max The minimum and maximum values of each feature dimension are used to map all feature values to the [0,1] interval, eliminating dimensional differences and numerical offsets between different feature dimensions (e.g., energy values 10-1000, entropy values 1-10). Redundant feature removal uses variance analysis combined with mutual information filtering: the variance of each feature dimension is calculated, and features with a variance ≥0.01 are retained; then the mutual information value between the remaining features and the metal signal label is calculated, and features with a mutual information value ≥0.3 are retained, finally obtaining well-organized input data (dimension M×F', where F' is the number of filtered features). The preprocessing process is implemented using the NumPy library, with a processing time ≤10ms / sample, ensuring real-time requirements.
[0027] Step S1242: Design at least two lightweight fully connected network layers as multi-frequency feature enhancement layers. The first fully connected layer receives the regularized input data and linearly combines the input features through neuron weights. The second fully connected layer uses a non-linear activation function to map and transform the features. Random deactivation units are embedded in the network to suppress overfitting. Feature weighted reconstruction is achieved through network forward propagation, amplifying the feature response corresponding to metal impurities, weakening the feature response of product, packaging, and environmental interference, strengthening the feature difference between metal signals and interference signals, and outputting the enhanced feature matrix. The fully connected network for the multi-frequency feature enhancement layer is constructed using PyTorch. The first layer receives regularized input data and generates a 256-dimensional feature vector through linear combination of neuron weights. Weight updates are performed using gradient descent (learning rate 0.001). The second layer performs nonlinear mapping on the 256-dimensional feature vector to generate a 128-dimensional enhanced feature vector. The ReLU activation function effectively enhances the nonlinear feature expression capability. The Dropout layer randomly deactivates 20% of neurons to avoid the model's over-reliance on certain features. During network training, the feature difference (cosine similarity difference) between the metal signal and the interference signal is used as the loss function. Training stops when the loss function value drops below 0.1. Through forward propagation, features corresponding to metal impurities are assigned high weights (1.2-1.5 times), while features corresponding to product, packaging, and environmental interference are assigned low weights (0.5-0.8 times), achieving weighted feature reconstruction, enhancing feature differences, and outputting an enhanced feature matrix with a dimension of M×128.
[0028] Step S1243: Perform a centering operation on the output enhanced feature matrix to remove the mean component of the features; then eliminate the linear correlation and redundant information between features through whitening transformation, so that the enhanced features meet the input requirements of the improved FastICA algorithm; Calculate the mean of each column of the enhanced feature matrix (M×128) to form a 128-dimensional mean vector μ. Subtract the mean of the corresponding column from each element in the matrix to obtain the centered matrix X. centered =X-μ, removes the mean component of the features, making the feature distribution symmetrical about the origin. Whitening transformation calculates the covariance matrix of the centered matrix and performs eigenvalue decomposition on Σ: Σ=UΛU T Where U is the eigenvector matrix and Λ is the eigenvalue diagonal matrix, a whitening matrix W is constructed. whiten =UΛ (-1 / 2) U T Multiplying the centering matrix by the whitening matrix yields the whitening feature matrix X. whitened =X centered W whitenAfter whitening, the linear correlation between features is ≤0.1, and the variance of each feature dimension is unified to 1, effectively eliminating redundant feature information and enabling the enhanced features to meet the statistical independence requirements of the improved FastICA algorithm for input data.
[0029] Step S1244: Load the FastICA algorithm model with built-in adaptive regularization term, set the nonlinear discriminant function and iterative convergence rule of the algorithm, and automatically adapt and adjust the regularization coefficient of the adaptive regularization term according to the noise intensity of the enhanced feature; at the same time, configure the separation target as four independent components: metal signal, product signal, packaging signal, and environmental interference signal. A FastICA algorithm model based on the Python scikit-learn library is loaded, and the nonlinear discriminant function is set as G(y)=tanh(ay), where a=1.0. This function has higher sensitivity to non-Gaussian signals than traditional functions. The iterative convergence rule is set as follows: the absolute error of the separation matrix iteration update ≤1e-6 or the number of iterations ≥100, to ensure the convergence stability of the algorithm. The regularization coefficient λ of the adaptive regularization term is dynamically adjusted according to the noise intensity of the enhanced features. By calculating the local signal-to-noise ratio (SNR=10log10(signal power / noise power)) of the feature matrix, λ=1.0 when SNR<15dB; λ=0.7 when 15dB≤SNR<25dB; and λ=0.4 when SNR≥25dB, automatically adapting to different noise scenarios. The separation target is configured into four independent components: metal signal (electromagnetic response signal of metal impurities such as iron, copper, and aluminum), product signal (dielectric response signal of food matrix), packaging signal (reflection / absorption signal of packaging material), and environmental interference signal (electromagnetic noise, vibration interference, etc.), thus clearly defining the separation target of the algorithm.
[0030] Step S1245: Input the obtained enhanced feature matrix after adaptation into the initialized blind source separation layer. The algorithm uses the maximization of negative entropy as the criterion for signal independence. It solves the optimal separation matrix through iterative optimization. During the iteration process, the iteration step size is dynamically adjusted to avoid local optima. The adaptive regularization term synchronously suppresses noise interference. The complete decoupling of the four types of signals is achieved through matrix transformation, separating the pure metal feature signal from various interference signals. The adapted enhanced feature matrix (M×128) is input into the initialized blind source separation layer. The algorithm uses the maximization of negative entropy as the signal independence criterion and solves for the optimal separation matrix using Newton's iteration method. During the iteration process, the iteration step size is dynamically adjusted: the initial step size is set to 0.1. The negative entropy growth rate is calculated for each iteration. When the growth rate > 0.05, the step size is increased to 0.15; when the growth rate < 0.01, the step size is decreased to 0.05 to avoid getting trapped in local optima. An adaptive regularization term is applied synchronously to the separation matrix update process. By penalizing the feature components corresponding to noise, noise interference is suppressed, improving the signal-to-noise ratio of the separated signal to over 30dB. After obtaining the optimal separation matrix through iterative optimization, the enhanced feature matrix is multiplied by the separation matrix. Matrix transformation is used to achieve complete decoupling of the four types of signals, outputting a pure metallic feature signal vector (M×1) and three types of interference signal vectors (each M×1).
[0031] Step S1246: Connect the multi-frequency feature enhancement layer and the improved FastICA blind source separation layer end-to-end to solidify the optimal network weights and separation parameters, thereby realizing automatic feature enhancement and signal decoupling after real-time multi-frequency feature input; at the same time, establish a separation effect feedback mechanism to fine-tune the weights of the fully connected layer and the FastICA regularization coefficients in real time according to the signal separation accuracy.
[0032] The multi-frequency feature enhancement layer and the improved FastICA blind source separation layer are concatenated end-to-end using PyTorch's nn.Sequential module to construct a complete inference model. The optimal network weights and separation parameters after training are fixed in ONNX format, and the model file size is ≤50MB, meeting the deployment requirements of edge devices. In real-time processing, the input multi-frequency feature data (single sample dimension 1×F) allows the model to automatically complete feature preprocessing, enhancement mapping, and signal separation. The processing time per sample is ≤50ms, meeting the real-time requirements of online detection. The separation effect feedback mechanism is achieved by calculating the cosine similarity between the separated metal signal and the standard template. A similarity threshold of 0.85 is set. When the similarity is <0.85, the weights of the fully connected layer are fine-tuned in steps of 0.02, and the FastICA regularization coefficient is adjusted in steps of 0.05. After each adjustment, 10 rounds of fine-tuning training are performed to ensure continuous optimization of separation accuracy and adapt to the dynamic changes in complex detection scenarios.
[0033] Step S125: The system collects signal samples of different food matrices, packaging types, environmental noise, and metal impurities. After preprocessing and feature extraction, the signal category labels of each type of sample are labeled. The labeled sample feature vectors are stored according to signal category to form a multi-scenario standard signal feature library. A dynamic update mechanism for the feature library is established to regularly include signal samples of new scenarios. Statistical analysis is performed on the feature vectors of each type of signal in the feature library to extract the common features of each type of signal and form a standard feature template. The system collects signal samples covering 20 food matrices (pork, beef, biscuits, milk powder, etc.), 10 packaging types (PE plastic, paper, aluminum foil, composite film, etc.), 8 types of environmental noise (power frequency interference, electromagnetic radiation, etc.), and 15 types of metallic impurities (diameter 0.1mm-5mm, material: iron, copper, aluminum, stainless steel). 1000 valid data points are collected for each sample, totaling 100,000 samples. After preprocessing (filtering, normalization) and feature extraction (wavelet packet decomposition + statistical features), the samples are labeled with category tags (metal signal / product signal / packaging signal / environmental interference signal) using a "manual labeling + machine verification" method, achieving an accuracy rate of ≥99%. The labeled sample feature vectors are stored in a MySQL database according to category, forming a multi-scenario standard signal feature library. The database supports incremental updates, automatically incorporating signal samples from new scenarios (such as new food matrices and packaging materials) monthly. K-means clustering algorithm is used to statistically analyze the feature vectors of various signals, extracting cluster center vectors as standard feature templates. The template update cycle is synchronized with the feature library.
[0034] Step S126: Extract the feature vectors of the separated candidate metal signal and candidate interference signal, calculate the cosine similarity with the standard feature template of the corresponding category signal in the standard signal feature library, set the similarity threshold according to the signal separation requirements, if the similarity between the candidate signal and the corresponding standard template meets the threshold requirement, the separation is deemed effective, if the similarity does not meet the standard, use the similarity deviation value as a feedback signal, adjust the wavelet packet decomposition layer, the regularization coefficient of the FastICA algorithm and the feature mapping parameters, and re-execute the feature extraction and signal separation process until the validity of the separated signal is verified.
[0035] After extraction and separation, the 16-dimensional feature vectors (including statistical features such as energy and entropy) of the candidate metal signal and candidate interference signal are used to calculate the cosine similarity with the 16-dimensional vectors of the corresponding category standard feature templates in the standard signal feature library. The similarity calculation formula is as follows: , where x i For the candidate signal feature components, y i The standard template feature components are used. A similarity threshold is set: ≥0.85 for metallic signals and ≥0.80 for interference signals. If the similarity between the candidate signal and the corresponding standard template meets the threshold requirement, the separation is considered valid. If the similarity does not meet the threshold, the similarity deviation value Δ = threshold - actual similarity is calculated. Δ is used as a feedback signal: when Δ ≥ 0.1, the wavelet packet decomposition layer number is adjusted ±1; when 0.05 ≤ Δ < 0.1, the FastICA regularization coefficient is adjusted ±0.1; when Δ < 0.05, the feature mapping weight is fine-tuned ±0.05. The feature extraction and signal separation process is re-executed, with a maximum re-execution count ≤ 3 times, to ensure the validity verification of the final separated signal passes.
[0036] Step S130: After feature extraction and dimensionality reduction, the output is fused through a hybrid model of traditional machine learning and lightweight deep learning. The DS evidence theory is introduced and combined with real-time parameters of the production line to dynamically adjust the decision rules. After feature extraction, Principal Component Analysis (PCA) and Local Linear Embedding (LLE) are combined for dimensionality reduction, compressing the feature matrix dimension to 40%-60% of the original dimension. A hybrid model is constructed using traditional machine learning sub-models (random forest, SVM) and lightweight deep learning sub-models (improved MobileNetV3), with fusion weights dynamically allocated based on validation set accuracy. DS evidence theory is introduced to handle model conflict outputs, defining Basic Probability Assignment (BPA) rules for four types of target identification. Real-time production line parameters, including production speed (0-20 m / min) and ambient temperature and humidity (-10℃-60℃, 20%-90%RH), are quantized and encoded to participate in the dynamic adjustment of decision rules. Decision rule adjustments are based on the similarity of separation signals and real-time parameter deviations, with a metal impurity signal confidence threshold of 0.85 set as a baseline, and continuous optimization is achieved through a feedback mechanism.
[0037] Step S131: Standardize the feature matrix after dimensionality reduction, collect and quantize the real-time parameters of the production line, and concatenate them with the signal features to form a complete input feature set of signal features and operating parameters; The feature matrix after dimensionality reduction is standardized using Z-score, with the formula being x. std =(x-μ) / σ (μ is the mean, σ is the standard deviation), mapping the feature values to the [-1,1] interval to eliminate numerical distribution differences. Real-time production line parameters include production speed, food batch identification, ambient temperature and humidity, and packaging type parameters: production speed is normalized to actual values (0-20m / min → 0-1), food batches are uniquely encoded (10 batches → 10-dimensional vector), temperature and humidity are normalized to their corresponding intervals, and packaging type is encoded as a 5-dimensional vector based on material (plastic / paper / aluminum foil, etc.). The quantized parameter vector (18 dimensions) is concatenated with the dimensionality-reduced signal features (80 dimensions) to form a complete 98-dimensional input feature set of "signal features + operating parameters," ensuring the comprehensiveness and adaptability of the input data.
[0038] Step S132: Select random forest and support vector machine to build traditional machine learning sub-models and optimize parameters to improve MobileNetV3 to build lightweight deep learning sub-models and adjust the structure to prevent overfitting. The two types of models are adapted to linearly separable and complex nonlinear signal recognition respectively, and both output category prediction results and corresponding confidence scores. The random forest sub-model sets the number of decision trees to be searched within the range of 50-500, using the Gini coefficient as the node splitting criterion. Optimal decision trees of 200 are obtained through 5-fold cross-validation. The SVM sub-model uses linear and RBF kernels as candidate kernels, with penalty coefficients C∈[0.1,100] and γ∈[0.001,10]. Optimal parameters for the linear kernel (for linearly separable signals) and RBF kernel (for weakly linearly separable signals) are determined through grid search. The improved MobileNetV3 compresses the original number of channels to 0.6 times, adds a lightweight attention module after depthwise separable convolution, and employs the Adam optimizer (initial learning rate 0.001). Overfitting is prevented through early stopping (definition set loss terminates after 5 consecutive rounds of increase) and L2 regularization (λ=0.001). Both models output prediction results and confidence scores (0-1 interval) for four target classes.
[0039] Step S133: Calculate the recognition accuracy of the traditional machine learning sub-model and the lightweight deep learning sub-model based on the validation set data. Dynamically allocate fusion weights according to the accuracy ratio. The higher the accuracy, the larger the weight ratio. Use the category confidence scores output by the two sub-models as the basic data. Obtain the preliminary fusion confidence score distribution by weighted summation. Normalize the preliminary fusion confidence score distribution so that the sum of the confidence scores of each category is 1, forming a standardized fusion output result. The validation set is divided into 10% of the labeled sample dataset. The recognition accuracy (Acc1, Acc2) of the two sub-models is calculated separately. The fusion weight allocation formula is w1=Acc1 / (Acc1+Acc2) and w2=Acc2 / (Acc1+Acc2), with higher accuracy resulting in a larger weight allocation. Let the confidence vector output by the traditional model be [P1,P2,P3,P4], and the deep learning model be [Q1,Q2,Q3,Q4]. The initial fusion confidence is Ri=w1×Pi+w2×Qi (i=1-4). Normalization is performed on the initial fusion result using the formula Ri. norm =Ri / ΣRi, ensuring that the sum of the four confidence levels is 1. For example, if Acc1=92% and Acc2=94%, then w1=0.495 and w2=0.505. After normalization, a standardized fusion output is formed, providing standardized data support for the DS evidence theory.
[0040] Step S134: Define the identification framework as four types of identification targets: metal impurity signal, product interference signal, packaging interference signal, and environmental interference signal. Convert the obtained standardized fusion output result into a basic probability distribution, introduce an uncertainty allocation coefficient, allocate part of the confidence in the confidence ambiguity region to the uncertainty set, use the DS synthesis rule to perform combination operation on the BPA, eliminate conflicting information, obtain the fused comprehensive confidence distribution, and select the category with the highest comprehensive confidence as the preliminary decision result. The identification framework is clearly defined into four categories: metal impurity signals, product interference signals, packaging interference signals, and environmental interference signals. The Ri output will be standardized and integrated. norm Directly convert to BPA: m(Ai) = Ri norm (Ai represents four types of targets). An uncertainty allocation coefficient α = 0.1-0.3 is introduced (the confidence level is determined by max(Ri)). norm )-min(Ri norm ()<0.3), at this time m(Ω)=α (Ω is an uncertain set), m(Ai)=(1-α)×Ri norm The DS synthesis rule is adopted: m(C)=[Σm1(A)m2(B)|A∩B=C] / [1-Σm1(A)m2(B)|A∩B=∅], to eliminate model conflicts (conflict coefficient K<0.5). The category with the highest comprehensive confidence is selected as the preliminary decision result. If the highest confidence is <0.7, the decision rule adjustment process is triggered.
[0041] Step S135: Establish a mapping relationship library between real-time parameters of the production line and decision thresholds, preset the optimal decision threshold range under different parameter combinations, monitor the changes of production line parameters in real time, and when the parameters exceed the current threshold adaptation range, retrieve the corresponding threshold range based on the mapping relationship library, and dynamically adjust the decision judgment criteria in combination with the current comprehensive confidence distribution: when the production speed increases, increase the confidence judgment threshold of metal impurity signals; when the environmental temperature and humidity fluctuate greatly, optimize the uncertainty allocation coefficient, establish a rule adjustment feedback mechanism, record the decision accuracy before and after the adjustment, and continuously optimize the mapping relationship library; A mapping database is established to store the optimal decision threshold ranges corresponding to parameter combinations such as production speed (5-20 m / min, divided into 4 levels) and temperature and humidity (divided into 5 levels). The confidence threshold for metal impurity signals is set at 0.85. For every 5 m / min increase in production speed, the threshold increases by 0.05 (maximum 0.95). When environmental temperature and humidity fluctuations are ≥ ±10%RH or ±5℃, the uncertainty allocation coefficient α is increased by 0.05 (maximum 0.3). Parameter changes are monitored in real time. When a parameter exceeds the current adaptation range (e.g., production speed increases from 10 m / min to 16 m / min), the corresponding threshold range (0.90-0.92) is retrieved from the database. A rule adjustment feedback mechanism records the decision accuracy of 1000 samples before and after the adjustment. If the accuracy improvement is <2%, the threshold corresponding to the parameter combination is re-optimized. The mapping database is updated every 7 days. Step S136: Compare and verify the dynamically adjusted decision results with the standard signal feature library, calculate the decision accuracy, misjudgment rate, and missed judgment rate. If the indicators do not meet the preset requirements, analyze the reasons for the deviation. If it is due to unreasonable fusion weights, recalculate the weight allocation ratio. If it is due to insufficient adaptability between the decision rules and real-time parameters, optimize the mapping relationship library parameters. Feed back the verification results to the hybrid model training and decision rule adjustment stage, update the model parameters and rule mapping relationship, and form a closed-loop mechanism of training, fusion, decision, verification, and optimization.
[0042] The decision results are compared with the standard signal feature library, and the following metrics are calculated: Accuracy = Number of correct decisions / Total number of decisions, False positive rate = Number of false positives / Total number of decisions, False negative rate = Number of false negatives / Total number of metal signals. The preset requirements are: Accuracy ≥ 95%, False positive rate ≤ 3%, False negative rate ≤ 2%. If the metrics are not met, the reasons for the deviation are analyzed: If the fusion weights are unreasonable, the validation set accuracy is recalculated and the weights are reassigned (adjustment step size 0.05); If the adaptability of the decision rules is insufficient, the thresholds of the corresponding parameter combinations in the mapping relationship library are optimized (adjustment step size 0.02). The validation results are fed back to the hybrid model training (adding 500 samples for fine-tuning) and rule adjustment stages to update the model parameters and rule mapping relationships, forming a training-fusion-decision-validation-optimization closed loop, iterating once after each batch of production. Step S140: Build an online incremental learning framework based on federated learning, realize feature drift detection and automatic parameter adjustment through KL divergence and PSI index, and build a dynamic adjustment strategy library in combination with Q-Learning agent; An online incremental learning framework is built based on federated learning, with edge nodes consisting of inspection equipment on various production lines (equipped with STM32H7+XC7A35T) and the cloud serving as an Intel Xeon server. KL divergence is used to quantify the nonlinear differences in feature distribution, and PSI measures the distribution stability shift; these two indicators are jointly used to detect feature drift. A Q-Learning agent constructs a state-action-reward mechanism, dynamically adjusting parameters such as the weights of multi-frequency sensing bands and feature extraction dimensions to form a standardized dynamic adjustment strategy library. The framework supports local data remaining in the database; edge nodes only upload incremental model parameters, which are then aggregated and optimized in the cloud before being distributed. Combined with the strategy library, a collaborative closed loop of drift detection, parameter adjustment, and model optimization is achieved, ensuring the system adapts to dynamic changes in the production scenario. Step S141: Adopt an edge-cloud distributed federated learning topology, configure local data caching and incremental training units for edge nodes, deploy model aggregation and parameter distribution units in the cloud, define the communication protocol and synchronization cycle for training and aggregation, initialize the sliding window dynamic batch parameters, and build a distributed learning environment where local data does not leave the database. A distributed topology of edge and cloud is adopted. Edge nodes are equipped with 8GB DDR4 local cache units and incremental training units (based on Python TensorFlow Lite), while the cloud deploys model aggregation units (supporting federated averaging algorithms) and parameter delivery units (using the MQTT communication protocol). The communication protocol is defined as follows: edge nodes upload parameter increments every 30 minutes, and the cloud completes aggregation and delivers update packages within 10 minutes of receiving the data. The sliding window dynamic batch parameter N is set to 500, and the initial window contains the most recent 500 valid data entries. When building the distributed learning environment, local data on edge nodes is encrypted (AES-128), and only parameter increments are transmitted to ensure data privacy. Simultaneously, the clock is synchronized via the NTP protocol to ensure training-aggregation timing consistency.
[0043] Step S142: Filter recent effective detection data of edge nodes through a sliding window and remove abnormal and duplicate samples. Edge nodes conduct local incremental training based on the incremental random forest algorithm to update model parameters. After receiving the local model parameters of each node, the cloud aggregates them through the federated averaging algorithm and then distributes the optimized global incremental model to each edge node. A sliding window filters the most recent N=500 batches of data for edge nodes based on time series, using the 3σ criterion to remove outliers (amplitudes exceeding the mean ±3σ), and a hash algorithm for deduplication (duplicate threshold ≥95%). Edge nodes are based on the Incremental Random Forest (iRF) algorithm; new data only updates the leaf node weights and branch structure of the decision tree, without retraining the entire model, with training time ≤10 seconds per batch. The cloud receives parameter increments from each edge node (up to 30), and a federated averaging algorithm is used: W global =Σ(ni / N total )×Wi (ni is the number of samples at node i, N) total (Where Wi is the total number of samples and node i is the parameter), after aggregation, a global incremental model is generated (file size ≤ 10MB), which is then distributed to each edge node via HTTP / 2 protocol to complete the parameter iterative update.
[0044] Step S143: Using the drift-free historical features in the standard feature library as the baseline distribution, collect the current real-time signal features of the edge nodes as the distribution to be tested, calculate the KL divergence and PSI dual indicators, set the joint judgment threshold, and automatically trigger the parameter adjustment process after judging feature drift. Taking the drift-free historical features (100,000 samples) in the standard signal feature library as the reference distribution P, and the current real-time features of the edge node as the test distribution Q. The KL divergence is calculated as KL(P||Q)=ΣP(x)log(P(x) / Q(x)), and the PSI is calculated as PSI=Σ(P(x)-Q(x))log(P(x) / Q(x)). The sliding window size is set to 100 samples. Set the joint decision threshold: when PSI>0.2 or KL divergence>0.5, it is determined that the feature drifts. The drift detection module calculates the dual indicators every 5 seconds. When the decision condition is met, it automatically triggers the parameter adjustment process through an interrupt signal, and at the same time records the drift occurrence time, signal type and indicator values, providing a basis for subsequent strategy matching.
[0045] Step S144: Perform parameter calibration according to the drift detection results in grades, automatically adjust the detection frequency band weight distribution of the multi-frequency sensing module, optimize the dimension configuration of wavelet packet decomposition and feature extraction, and dynamically correct the decision threshold of the hybrid model and the uncertainty assignment coefficient of the D-S evidence theory; Perform parameter calibration according to the drift degree classification (mild: 0.2<PSI≤0.3 or 0.5<KL≤0.8; moderate: 0.3<PSI≤0.5 or 0.8<KL≤1.2; severe: PSI>0.5 or KL>1.2). Mild drift: Adjust the multi-frequency sensing frequency band weight (sensitive frequency band weight +0.1); Moderate drift: Optimize the number of wavelet packet decomposition layers (±1 layer) and remove 5% redundant features; Severe drift: Dynamically correct the decision threshold of the hybrid model (±0.05) and the uncertainty assignment coefficient of the D-S evidence theory (±0.03). The parameter calibration is fully automated, the response time ≤3 seconds, and the feature distribution deviation is reduced by more than 50% through adjustment, quickly restoring the detection accuracy.
[0046] Step S145: Construct a state space with the feature drift type, drift degree, real-time production line parameters, and current detection performance of the model as the core, construct an action space with the adjustment range of the frequency band weight, the increase or decrease of the feature extraction dimension, the correction value of the decision threshold, and the incremental learning rate as the core, construct a quantitative reward function with maximizing the detection accuracy and minimizing the misjudgment rate as the core, and calculate the weighted sum of the accuracy improvement value and the misjudgment rate reduction value as the immediate reward of the agent to complete the initialization configuration of the agent; The system includes 3 types of drift, 3 levels of drift, 4 dimensions of real-time production line parameters, and 3 indicators of model detection performance, totaling 3×3×4×3=108 states. The action space contains 4 types of adjustments: frequency band weight adjustment range (-0.2~+0.2, step size 0.05), feature extraction dimension increase / decrease (-10~+10), decision threshold correction value (-0.1~+0.1, step size 0.01), and incremental learning rate (0.0005~0.002, step size 0.0005). The reward function is R=0.6×ΔAcc-0.4×ΔErr (ΔAcc is the accuracy improvement value, ΔErr is the misclassification rate improvement value), with an immediate reward range of [-1,1]. The Q-value table is initialized to 0, the learning rate α=0.1, and the discount factor γ=0.9, completing the agent initialization.
[0047] Step S146: Connect the agent to the online detection system so that it can interact with the feature drift detection module and parameter adjustment module in real time. The agent selects an adjustment strategy from the action space according to the current system state, obtains the reward value of the environment feedback after execution, updates the Q value table based on the Bellman equation, iteratively optimizes the value score corresponding to the state-action, and gradually converges to the optimal decision strategy. A Q-Learning agent is embedded in the online detection system, interacting in real time with the drift detection module and parameter adjustment module via shared memory, with an interaction cycle of 2 seconds. Based on the current system state (e.g., "slight drift + production speed 15m / min + accuracy 93%)", the agent selects an adjustment strategy from the action space (e.g., "sensitive frequency band weight + 0.05 + learning rate 0.001"), and obtains the reward value R from the environmental feedback after execution. The Q-value table is updated based on the Bellman equation: Q(s,a) = Q(s,a) + α[R + γ × maxQ(s',a') - Q(s,a)], iteratively optimizing the state-action value score. When the Q-value change over 100 consecutive iterations is ≤1e-4, convergence to the optimal decision strategy is considered achieved.
[0048] Step S147: Store the optimal adjustment strategies learned by the Q-Learning agent according to drift scenarios, production line conditions, and signal types to form a standardized dynamic adjustment strategy library. When feature drift is detected, retrieve and call the optimal solution in the strategy library in real time to complete parameter adjustment. At the same time, continuously incorporate the learned strategies under new scenarios into the strategy library to realize dynamic expansion and optimization of the strategy library, forming a closed-loop collaborative mechanism of online incremental learning, feature drift detection, and intelligent decision adjustment.
[0049] The dynamic adjustment strategy library uses a key-value pair storage structure, where the key is "drift scenario-operating condition-signal type" (e.g., "slight drift-high-speed production-metal signal"), and the value is the optimal adjustment strategy. The strategy library is deployed locally in the edge node cache, supporting real-time retrieval (retrieval time ≤ 1ms). When feature drift is detected, the optimal strategy is matched to the key and executed; if no match is found, the agent selects an action through exploration (ε-greedy algorithm, ε=0.1). If the reward value R ≥ 0.5 after execution, the "state-action-reward" combination is added to the strategy library. The strategy library is deduplicated and optimized monthly, retaining the top 80% of strategies by usage, enabling dynamic expansion and simplification.
[0050] Step S150: Construct a data-enhanced labeled sample dataset, optimize the model through knowledge distillation and domain adversarial neural networks, and develop a lightweight inference engine for edge devices; We collected raw signal samples from multiple scenarios (including 20 food matrices, 10 packaging types, 8 environmental noise types, and 15 metal impurities), and constructed a labeled sample dataset through multi-dimensional data augmentation (random cropping, noise overlay, etc.). We selected ResNet50 as the teacher model, trained it to convergence, and then transferred the knowledge to a lightweight student model (an improved MobileNetV3) through knowledge distillation. We also embedded a Domain Adversarial Neural Network (DANN) to enhance cross-domain generalization ability. For edge devices (MCU+FPGA heterogeneous architecture), we quantized the student model to INT8 precision, optimized operator fusion and inference processes, and developed a lightweight inference engine based on the NCNN framework. This ensured that the engine's inference latency was ≤50ms and memory usage was ≤200MB, adapting to the low-power, high-real-time requirements of edge devices.
[0051] Step S151: Collect original signal samples from multiple scenarios and label them according to four categories to form a basic sample set. After implementing various data augmentation operations, divide the training, validation, and test sets according to a preset ratio and remove invalid samples to construct a data augmentation-labeled sample dataset that covers all scenarios and has high diversity. 100,000 original signal samples from multiple scenarios were collected and labeled into four categories: metal impurities, product interference, packaging interference, and environmental noise, forming a basic sample set. Data augmentation operations included: random pruning (truncating 70%-90% of the signal length), Gaussian noise superposition (signal-to-noise ratio 20-30dB), frequency band micro-shift (±5%), time axis flipping, and amplitude scaling (0.8-1.2 times), expanding the sample size to 400,000 samples. These samples were divided into a training set (320,000 samples), a validation set (40,000 samples), and a test set (40,000 samples) in an 8:1:1 ratio. Label consistency verification (manual review of 10% of samples) was used to remove incorrectly labeled samples, and feature ambiguity filtering was employed (samples with ambiguity > 0.3 were removed).
[0052] Step S152: Select a deep learning model as the teacher model, train it to convergence based on the original labeled sample set and optimize the model configuration, build a lightweight student model, adopt a lightweight convolutional structure and compress the number of channels, design a knowledge distillation training process, take the output layer probability distribution and intermediate layer feature vector of the teacher model as the distillation target, construct a distillation loss function that combines cross-entropy loss and feature matching loss, use the gradient descent algorithm to iteratively train the student model, introduce an early stopping mechanism, and transfer the knowledge of the teacher model to the student model; ResNet50 was selected as the teacher model and trained for 100 epochs on the original labeled sample set. The network depth (fixed at 50 layers), number of channels (256-1024), and attention module (SE module) were optimized to ensure a recognition accuracy of ≥97%. A lightweight student model was built: depthwise separable convolutions were used, and the number of channels was compressed to 0.6 times that of the teacher model, reducing parameters by more than 60%. Knowledge distillation training process: the probability distribution of the output layer of the teacher model (softmax temperature T=10) and the feature vectors of the intermediate layers were used as distillation targets, and a loss function L=0.3×L was constructed. ce +0.7×L feat (L) ce For cross-entropy loss, L feat (For feature matching loss). The SGD optimizer (learning rate 0.005) was used for 80 iterations of training, and an early stopping mechanism was introduced (termination was achieved when the accuracy on the validation set did not improve for 3 consecutive iterations), transferring the knowledge from the teacher model to the student model.
[0053] Step S153: Embed a domain adversarial neural network in the knowledge distillation training. Use the feature extraction layer of the student model as the feature encoder and add a domain classifier to distinguish the production scenario domain to which the features belong. Construct an adversarial training mechanism. The feature encoder aims to minimize the recognition accuracy of the domain classifier, while the domain classifier aims to maximize the discriminative power of the feature domain. Optimize the game process between the two through alternating iterative training. Integrate domain adversarial optimization with knowledge distillation training to simultaneously optimize the classification accuracy and cross-domain generalization ability of the student model. Evaluate the model performance and adjust relevant parameters for different scenario sample sets until the model's generalization performance across all scenarios meets the detection requirements. A DANN is embedded in the knowledge distillation training. The first 8 depthwise separable convolutional layers of the student model serve as the feature encoder, and 2 new fully connected layers are added as the domain classifier (outputting 5 production scene domains). An adversarial training mechanism is used: the feature encoder aims to minimize the accuracy of the domain classifier (optimizer Adam, learning rate 0.001), while the domain classifier aims to maximize domain discriminative power (optimizer SGD, learning rate 0.003), with alternating iterative training (one classifier training round for every five rounds of encoder training). Domain adversarial optimization is integrated with knowledge distillation, and a new loss function of 0.2 × L_domain (domain classification loss) is added. Evaluation is performed on the 5 scene sample sets in the validation set. If the accuracy for a certain scene is <93%, the domain adversarial training weight coefficients (±0.1) or the encoder structure (adding one convolutional layer) are adjusted until the generalization performance across all scenes meets the detection requirements.
[0054] Step S154: Deconstruct the hardware architecture of the edge device, clarify the upper limit of computing power, storage capacity, computing unit characteristics and operating constraints of the edge device, perform model quantization optimization for the hardware characteristics of the edge device, quantize the weights and feature data of the student model from floating point to integer, carry out operator-level optimization, integrate continuous operators in the student model, optimize operator execution efficiency for the hardware instruction set of the edge device, adapt to the hardware parallel computing architecture, select an inference framework adapted to the edge device, convert the optimized quantized model into a model format supported by the framework, configure the scheduling strategy of the inference engine, optimize the data input and output process and inference caching mechanism, deploy a lightweight inference engine on the edge device, test the indicators and adjust the optimization strategy accordingly until the inference engine meets the operating requirements of the edge device; The MCU is an STM32H743 (288 DMIPS computing power), the FPGA is an XC7A35T (33k logic units), and the storage capacity is 8GB DDR4. Operating constraints are power consumption ≤5W and inference latency ≤50ms. Model quantization optimization: Quantization-aware training is used to quantize the student model from FP32 to INT8, with a quantization error ≤1%. Operator-level optimization: Convolutional layers, BN layers, and activation layers are integrated, and convolutional operators are optimized for the FPGA hardware instruction set (parallelism increased by 4 times). The NCNN inference framework is selected, and the quantized model is converted to .param and .bin formats. A scheduling strategy is configured: complex operators (such as wavelet packet decomposition) are assigned to the FPGA, and simple operators (such as normalization) are assigned to the MCU. The data input / output process (using DMA transfer) and caching mechanism (preloading commonly used parameters) are optimized. Post-deployment testing shows inference latency ≤45ms, memory usage ≤180MB, and accuracy ≥94.5%, meeting the requirements of edge device operation.
[0055] Step S156: Deploy the optimized lightweight student model to the lightweight inference engine, run the test set samples and samples collected in real time on the production line on the edge device, evaluate the model recognition accuracy, inference latency, and memory power consumption indicators, compare the performance of the unoptimized model, and verify the optimization effect of the lightweight inference engine. If there is a loss of accuracy or the inference efficiency is not up to standard, backtrack and adjust the knowledge distillation loss weight, domain adversarial training strategy or operator optimization scheme to form an inference engine collaborative system.
[0056] The optimized lightweight student model was deployed to the NCNN inference engine and run on an edge device with a test set of 40,000 samples and 10,000 samples collected in real time from the production line. Key evaluation metrics were: recognition accuracy ≥ 94%, inference latency ≤ 50ms, and memory consumption ≤ 5W. Compared to the unoptimized model (accuracy 95%, latency 120ms, power consumption 8W), the lightweight design demonstrated a 62.5% reduction in latency, a 37.5% reduction in power consumption, and an accuracy loss ≤ 0.5%. If the accuracy loss > 1%, the knowledge distillation loss weight was adjusted (L_feat weight + 0.1); if the latency exceeded the threshold, the operator fusion strategy was optimized (two new sets of continuous operator fusion were added); if memory usage was too high, redundant branches in the model were simplified (10% of non-critical channels were removed), ultimately forming a collaborative inference engine system with both high generalization ability and edge adaptability.
[0057] Step S160: Based on the heterogeneous architecture of MCU and FPGA / TPU, the detection function is executed in a division of labor. Local caching ensures operation even when the network is down. The model is optimized through edge and cloud collaboration, and the data processing related links are optimized in sync.
[0058] Based on a heterogeneous architecture of MCU (STM32H743) and FPGA / TPU (XC7A35T / Google Coral TPU), the MCU is responsible for system control, data scheduling, and lightweight processing, while the FPGA / TPU handles parallel computing-intensive tasks. Edge devices are configured with hierarchical local caches (2GB L1 cache and 6GB L2 cache) to ensure continuous operation even when the network is offline. The edge and cloud collaborate to optimize the model through federated learning. Edge nodes incrementally update their local models, while the cloud aggregates and generates a global model and distributes an adapted version. Data processing is optimized across all stages: the acquisition stage ensures timing consistency, the feature extraction stage is deployed in parallel, and the inference and decision-making stage is executed in a pipelined manner.
[0059] Step S161: Clarify the division of responsibilities between the MCU and the FPGA / TPU. The MCU is responsible for system control, lightweight data processing and result output, while the FPGA / TPU accelerates parallel computing-intensive tasks, achieves high-speed interaction through standardized interfaces, and dynamically allocates resources according to task requirements. The division of responsibilities between the MCU and FPGA / TPU is clearly defined: the MCU is responsible for system control (device start / stop, parameter configuration), data acquisition scheduling (multi-frequency sensor module control), network status monitoring, and network outage logic switching; it also handles lightweight data preprocessing (timing alignment, simple filtering) and output of detection results (display screen + alarm signal). The FPGA / TPU focuses on parallel computing-intensive tasks such as multi-frequency feature extraction, hybrid model inference, and blind source separation, improving computational efficiency by 5-10 times. High-speed interaction between the two is achieved through an SPI interface (100Mbps transmission rate), and a task scheduling protocol is established: tasks with high real-time requirements (such as signal acquisition synchronization) are assigned to the MCU, while computationally intensive tasks (such as wavelet packet decomposition) are assigned to the FPGA / TPU. The resource allocation is dynamically adjusted according to task complexity (FPGA / TPU computing power accounts for 60%-80%) to ensure efficient and collaborative architecture.
[0060] Step S162: Configure the edge device with a hierarchical local cache to store model parameters, feature library and detection data in a hierarchical manner. Design a network update and network disconnection switching mechanism. When the network is disconnected, the local cache is enabled to maintain the continuity of detection. The data is retransmitted after the network is restored. The first-level cache (2GB DDR4) stores the parameters of the currently running lightweight model (≤50MB), the core subset of the standard signal feature library (5000 samples), and real-time detection data (last hour). The second-level cache (6GB eMMC) backs up historical model versions (5), the complete feature library (100,000 samples), and recent detection logs (7 days). Cache update mechanism: When connected to the network, the model update package (≤10MB) and incremental feature library data (≤100MB) are retrieved from the cloud every 30 minutes, automatically replacing the old version. When the network is down (interruption exceeding 3 seconds), the MCU triggers the cache switching logic, immediately activating the model and feature library in the first-level cache to maintain continuous operation of the detection function. Data is stored in the second-level cache during the downtime and automatically uploaded to the cloud within 10 minutes after the network is restored to complete the data chain.
[0061] Step S163: Edge nodes update their local models through incremental learning, only uploading parameter increments to the cloud. The cloud aggregates and optimizes the global model using a federated averaging algorithm and distributes it. A customized version of the model is designed for the differences in computing power of edge devices, forming a collaborative optimization closed loop. Edge nodes update their local model parameters using an incremental random forest algorithm based on locally collected valid data (500 records per batch). Only parameter increments (≤5MB / batch) are uploaded to the cloud using AES-128 encryption. The cloud server receives parameter increments from each edge node (up to 30) and aggregates them using a federated averaging algorithm: W global =Σ(ni / N total )×Wi (ni is the number of samples at node i, N) total(Total number of samples), multi-node features are integrated to optimize the global model. Addressing the differences in computing power among edge devices, the cloud employs an adaptive model pruning strategy: FPGA nodes retain the complete model structure, MCU single nodes prune 30% of non-critical channels, and TPU nodes optimize operators to adapt to the hardware instruction set. The customized adapted model meets the requirements of inference latency ≤50ms and accuracy ≥94% on different devices, forming a collaborative optimization closed loop of local iteration - cloud aggregation - global distribution.
[0062] Step S164: Collaborative optimization of the entire data processing process, ensuring time consistency and parallel preprocessing in the data acquisition stage, implementing parallel deployment of algorithms in the feature extraction stage, and executing tasks in the pipeline and processing real-time parameters synchronously in the inference and decision-making stage, thereby promoting parallel data processing and decision-making; In the data acquisition stage, the MCU controls the multi-frequency sensing module and the clock module through a hardware-triggered synchronization circuit (trigger delay ≤50ns) to ensure the consistency of signal acquisition timing. The FPGA preprocessing module performs signal filtering (adaptive median filtering) and missing value completion (bilinear interpolation) in parallel, improving processing efficiency by 3 times. In the feature extraction stage, based on the parallel computing capabilities of the FPGA / TPU, the wavelet packet decomposition and PCA dimensionality reduction algorithm are split into 8 parallel tasks and deployed to the core computing unit of the FPGA / TPU, reducing the feature extraction time from 200ms to 40ms. In the inference and decision-making stage, the model inference process is optimized, and the computational tasks of feature enhancement and blind source separation are pipelined on the FPGA / TPU (parallelism 4). The MCU synchronously processes the real-time parameter encoding of the production line (quantization time ≤5ms) and the adjustment of decision rules, realizing parallel advancement of data processing and decision-making, with a total process time ≤100ms.
[0063] Step S165: The MCU integrates a system status monitoring unit to collect computing power and network data in real time, and dynamically adjusts task allocation, synchronization frequency and model strategy for different working conditions; The MCU integrates a system status monitoring unit, which collects real-time data on the heterogeneous architecture's computing power utilization (MCU / FPGA / TPU monitored separately), memory usage, network connection status (packet loss rate, latency), and detection latency data via ADC acquisition and software reading, with a collection cycle of 1 second. Based on the monitoring data, a dynamic adjustment strategy is implemented: when the FPGA / TPU computing power utilization is ≥90%, some non-core preprocessing tasks (such as data format conversion) are migrated to the MCU; when the network bandwidth is ≤1Mbps, the model parameter synchronization frequency is reduced (from 30 minutes / time to 60 minutes / time); when the detection latency is >50ms, a model lightweight degradation strategy is automatically enabled (temporarily closing some non-critical feature extraction channels, with an accuracy loss of ≤1%). Through dynamic adjustments, the system's stability and real-time performance are ensured under complex operating conditions (high production speed, network fluctuations).
[0064] Step S166: Build a simulation test and actual production verification environment, verify system capabilities, analyze bottlenecks and optimize algorithms and scheduling strategies, establish an evaluation index system, and form a stable and reliable detection system through continuous iteration.
[0065] Simulating network conditions (network outage, weak network <1Mbps, full speed >10Mbps) and production conditions (production speed 5-20m / min, temperature and humidity -10℃-60℃ / 20%-90%RH), the efficiency of heterogeneous architecture collaboration, local caching network outage protection capabilities, and edge-cloud collaborative optimization effects were verified. One month's worth of inspection data (1 million records) from an actual production line was collected. Data analysis tools (Python Pandas) were used to identify time bottlenecks (e.g., feature extraction time exceeding 50%) and accuracy loss points (e.g., accuracy decreases by 3% under high temperature conditions). Targeted optimizations were implemented: operator fusion reduced FPGA computation time, a high-temperature compensation model improved environmental adaptability, and a system performance evaluation index system (detection accuracy, inference latency, network outage endurance, etc.) was established. A full-process verification and iterative optimization were conducted quarterly to continuously improve system stability and reliability, ultimately forming a detection system that meets industrial-grade application requirements.
[0066] Based on the same inventive concept, please refer to Figure 2 This paper shows a schematic block diagram of the structure of an intelligent sensor-based online detection system for metal impurities in food, provided in an embodiment of this application, for performing the above-described intelligent sensor-based online detection method for metal impurities in food. The intelligent sensor-based online detection system for metal impurities in food 100 may include a communication unit 110, a machine-readable storage medium 120, and a processor 130.
[0067] In this embodiment, both the machine-readable storage medium 120 and the processor 130 are located within the intelligent sensor-based online detection system for metal impurities in food and are separately configured. However, it should be understood that the machine-readable storage medium 120 may also be independent of the intelligent sensor-based online detection system for metal impurities in food 100 and may be accessed by the processor 130 via a bus interface. Alternatively, the machine-readable storage medium 120 may be integrated into the processor 130 and may communicate with external systems via the communication unit 110.
[0068] The processor 130 is the control center of the intelligent sensor-based online detection system for metal impurities in food 100. It connects to various parts of the system via various interfaces and lines. By running or executing software programs and / or modules stored in the machine-readable storage medium 120, and by calling data stored in the machine-readable storage medium 120, it performs various functions and processes data of the intelligent sensor-based online detection system for metal impurities in food 100, thereby providing overall monitoring of the system. Optionally, the processor 130 may include one or more processing cores; for example, the processor 130 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor. The machine-readable storage medium 120 is used to store machine-executable instructions for executing the scheme of this application, and the processor 130 is used to execute the machine-executable instructions stored in the machine-readable storage medium 120 to realize the intelligent sensing-based online detection method for metal impurities in food provided in the aforementioned method embodiments.
[0069] It should be noted that, in order to simplify the description of the present invention and thus help to understand one or more embodiments of the invention, multiple features may sometimes be grouped into one embodiment, drawing or description thereof in the foregoing description of the embodiments of the present invention.
[0070] The embodiments of this application have been described above with reference to the accompanying drawings. Unless otherwise specified, the embodiments and features in the embodiments of this application can be combined with each other. This application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A smart sensor-based online detection method for metal impurities in food, characterized in that: Includes the following steps: Simultaneously transmit and receive multiple discrete frequency band electromagnetic signals, and generate a multi-dimensional original signal matrix by utilizing their different responses to metals, food, packaging and the environment; Based on the fusion of the improved FastICA blind source separation algorithm and wavelet packet transform, a two-layer model of multi-frequency feature-blind source separation is constructed. The effectiveness of signal separation is verified by relying on a multi-scenario standard signal feature library and cosine similarity matching. After feature extraction and combined dimensionality reduction, the output is fused through a hybrid model of traditional machine learning and lightweight deep learning. The DS evidence theory is introduced and combined with real-time parameters of the production line to dynamically adjust the decision rules. An online incremental learning framework is built based on federated learning. Feature drift detection and automatic parameter adjustment are achieved through KL divergence and PSI index. A dynamic adjustment strategy library is constructed by combining Q-Learning agent. We construct a data-enhanced labeled sample dataset, optimize the model through knowledge distillation and domain adversarial neural networks, and develop a lightweight inference engine for edge devices. The detection function is executed based on the heterogeneous architecture of MCU and FPGA / TPU, and the local cache ensures operation when the network is not connected. The model is optimized through edge and cloud collaboration, and the data processing-related links are optimized in sync.
2. The intelligent sensor-based online detection method for metal impurities in food according to claim 1, characterized in that: The synchronous transmission and reception of multi-discrete frequency band electromagnetic signals, utilizing their differences in response to metals, food, packaging, and the environment, generates a multi-dimensional original signal matrix, including: A multi-channel signal generator based on direct digital synthesis technology is selected. This signal generator supports synchronous output of multiple independent frequency bands. Each frequency band can be configured independently within a set frequency range. According to the detection requirements, the low frequency band, medium frequency band, and high frequency band are divided and the corresponding number of channels are allocated. The amplitude and phase of each signal are calibrated. The transmitting coil is designed according to the electromagnetic characteristics of each frequency band. The transmitting coil with the corresponding structure is adapted to different frequency bands. Each frequency band is equipped with an independent transmitting coil. An impedance matching network is formed by an LC resonant circuit composed of inductors and capacitors to match the coil impedance with the output impedance of the signal generator. A high-precision timing module or network clock protocol is used to provide a unified clock reference for the signal generator, data acquisition card and sensor array. A hardware trigger synchronization circuit is designed, and the main control MCU outputs a synchronization trigger signal to synchronously start the multi-band signal transmission of the signal generator and the signal reception of the data acquisition card. A receiving coil array corresponding to the transmitting coil is configured, with each receiving coil and transmitting coil arranged coaxially to form a transmitting and receiving pair structure. A signal conditioning circuit is designed for the signal characteristics of different frequency bands. This circuit includes a low-noise preamplifier, a bandpass filter, and a differential amplifier circuit to convert the received weak electromagnetic induction signal into a standard analog signal. A multi-channel high-speed ADC acquisition card is selected, with the number of acquisition card channels matching the number of transmission frequency bands, enabling independent acquisition of signals for each frequency band. The timing control of ADC acquisition is implemented through FPGA, and DMA direct memory access is adopted to convert the acquired analog signals into digital signals and store them directly in the buffer. During the acquisition process, a timestamp is added to each data channel through a clock synchronization signal. Frequency band response characteristic calibration and compensation: In a standard environment without metals or interference, the signals of each frequency band are calibrated, blank sample response signals of different food matrices and packaging materials are collected, amplitude and phase calibration coefficient matrices of each frequency band are established, and ambient temperature is collected in real time through a temperature sensor, and the collected signals are dynamically compensated using a pre-stored temperature compensation model. Using timestamps as indexes, the digital signals acquired from each frequency band are arranged in a time sequence to form a single-band time-domain signal vector. A fast Fourier transform is performed on each time-domain signal to extract frequency-domain amplitude and phase features, forming a single-band frequency-domain signal vector. The time-domain vectors and frequency-domain vectors of all frequency bands are integrated into a three-dimensional structure of time dimension, frequency band dimension, and feature dimension to construct a multi-dimensional original signal matrix. The feature dimension of this matrix includes four basic features: time-domain amplitude, time-domain phase, frequency-domain amplitude, and frequency-domain phase.
3. The intelligent sensor-based online detection method for metal impurities in food according to claim 1, characterized in that: The improved FastICA blind source separation algorithm and wavelet packet transform are fused together to construct a multi-frequency feature-blind source separation two-layer model. The effectiveness of signal separation is verified using a multi-scenario standard signal feature library and cosine similarity matching, including: Adaptive median filtering is used to suppress impulse noise in the multi-dimensional original signal matrix, and missing sampling points in the signal acquisition process are completed by linear interpolation. Time alignment of signals in each frequency band is performed based on timestamp information. For the time-domain signal of each frequency band, a wavelet basis function adapted to its frequency range is set. The optimal number of decomposition layers is dynamically adjusted according to the frequency band width and signal complexity to ensure that the target signal frequency band is covered after decomposition. Wavelet packet decomposition is performed on the signal of each frequency band to obtain the high-frequency and low-frequency coefficients of each decomposition node. The energy, entropy, peak factor and kurtosis features of each node are calculated to form a time-domain-frequency domain joint feature vector of a single frequency band. The feature vectors of all frequency bands are concatenated according to the frequency band dimension to construct a global multi-frequency feature matrix. An adaptive regularization term is introduced on the basis of the traditional FastICA algorithm. This regularization term dynamically adjusts the penalty coefficient based on the local signal-to-noise ratio of the signal. When the signal noise is strong, the penalty weight is increased to suppress noise interference. Negative entropy is used as the signal independence metric to optimize the algorithm objective function. The separation matrix is solved by Newton's iteration method. The algorithm convergence speed is accelerated by dynamically adjusting the iteration step size. The global multi-frequency feature matrix is used as the input of the improved FastICA algorithm. A two-layer cascaded model architecture is constructed. The first layer is a multi-frequency feature enhancement layer, which maps the multi-frequency feature matrix extracted by wavelet packet transform through a fully connected layer to enhance the feature differences between the metal signal and various interference signals and outputs the enhanced feature matrix. The second layer is a blind source separation layer, which inputs the enhanced feature matrix into the improved FastICA algorithm. The system collects signal samples from different food matrices, packaging types, environmental noise, and metal impurities. After preprocessing and feature extraction, the system labels the signal categories of each sample. The labeled sample feature vectors are stored according to signal categories to form a multi-scenario standard signal feature library. A dynamic update mechanism for the feature library is established to regularly include signal samples from new scenarios. Statistical analysis is performed on the feature vectors of each type of signal in the feature library to extract the common features of each type of signal and form a standard feature template. The feature vectors of the separated candidate metal signal and candidate interference signal are extracted and their cosine similarity is calculated with the standard feature templates of the corresponding category signals in the standard signal feature library. A similarity threshold is set according to the signal separation requirements. If the similarity between the candidate signal and the corresponding standard template meets the threshold requirements, the separation is deemed effective. If the similarity does not meet the threshold, the similarity deviation value is used as a feedback signal to adjust the wavelet packet decomposition layer, the regularization coefficient of the FastICA algorithm, and the feature mapping parameters. The feature extraction and signal separation process is then re-executed until the validity of the separated signal is verified.
4. The intelligent sensing-based online detection method for metal impurities in food according to claim 3, characterized in that: The constructed two-layer cascaded model architecture consists of two layers. The first layer is a multi-frequency feature enhancement layer, which maps the multi-frequency feature matrix extracted by wavelet packet transform through a fully connected layer to enhance the feature differences between the metal signal and various interference signals, and outputs an enhanced feature matrix. The second layer is a blind source separation layer, which inputs the enhanced feature matrix into the improved FastICA algorithm, including: The global multi-frequency feature matrix output by wavelet packet transform is numerically normalized to eliminate the dimensional differences and numerical offsets between features of different dimensions, map all feature values to a unified numerical range, remove redundant feature dimensions, and retain features that are strongly correlated with metal signals and interference signals to obtain regular input data. At least two lightweight fully connected network layers are designed as multi-frequency feature enhancement layers. The first fully connected layer receives the regularized input data and linearly combines the input features through neuron weights. The second fully connected layer uses a non-linear activation function to map and transform the features. Random deactivation units are embedded in the network to suppress overfitting. Feature weighted reconstruction is achieved through network forward propagation, amplifying the feature response corresponding to metal impurities, weakening the feature response of product, packaging, and environmental interference, strengthening the feature difference between metal signals and interference signals, and outputting an enhanced feature matrix. The output enhanced feature matrix is centered to remove the mean component of the features; then, a whitening transformation is used to eliminate the linear correlation and redundant information between features, so that the enhanced features meet the input requirements of the improved FastICA algorithm. The FastICA algorithm model with built-in adaptive regularization term is loaded, and the nonlinear discriminant function and iterative convergence rule of the algorithm are set. The regularization coefficient of the adaptive regularization term is automatically adapted and adjusted according to the noise intensity of the enhanced feature. At the same time, the separation target is configured as four independent components: metal signal, product signal, packaging signal, and environmental interference signal. The enhanced feature matrix after adaptation is input into the initialized blind source separation layer. The algorithm uses the maximization of negative entropy as the criterion for signal independence and solves the optimal separation matrix through iterative optimization. During the iteration process, the iteration step size is dynamically adjusted to avoid local optima. The adaptive regularization term synchronously suppresses noise interference. The complete decoupling of the four types of signals is achieved through matrix transformation, separating the pure metal feature signal from various interference signals. The multi-frequency feature enhancement layer and the improved FastICA blind source separation layer are connected end-to-end to solidify the optimal network weights and separation parameters, thereby realizing automatic feature enhancement and signal decoupling after real-time multi-frequency feature input. At the same time, a separation effect feedback mechanism is established to fine-tune the weights of the fully connected layer and the FastICA regularization coefficients in real time according to the signal separation accuracy.
5. The intelligent sensing-based online detection method for metal impurities in food according to claim 1, characterized in that: After feature extraction and dimensionality reduction, the output is fused using a hybrid model combining traditional machine learning and lightweight deep learning. This incorporates DS evidence theory and real-time production line parameters to dynamically adjust decision rules, including: The reduced feature matrix is standardized, and real-time parameters of the production line are collected, quantized, and encoded. These parameters are then concatenated with signal features to form a complete input feature set of signal features and operating parameters. Random forest and support vector machine were selected to build traditional machine learning sub-models and optimize parameters. MobileNetV3 was used to build lightweight deep learning sub-models and adjust the structure to prevent overfitting. The two types of models are adapted to linearly separable and complex nonlinear signal recognition, respectively, and both output category prediction results and corresponding confidence scores. The recognition accuracy of traditional machine learning sub-model and lightweight deep learning sub-model is calculated based on the validation set data. The fusion weight is dynamically allocated according to the accuracy ratio, with higher accuracy having a larger weight ratio. The category confidence scores output by the two types of sub-models are used as the basic data, and a preliminary fusion confidence score distribution is obtained by weighted summation. The preliminary fusion confidence score distribution is then normalized so that the sum of the confidence scores of each category is 1, forming a standardized fusion output result. The identification framework is defined as four types of identification targets: metal impurity signals, product interference signals, packaging interference signals, and environmental interference signals. The obtained standardized fusion output results are transformed into basic probability allocations. An uncertainty allocation coefficient is introduced to allocate part of the confidence in the confidence ambiguity region to the uncertainty set. The DS synthesis rule is used to perform combination operations on the BPA to eliminate conflicting information and obtain the fused comprehensive confidence distribution. The category with the highest comprehensive confidence is selected as the preliminary decision result. Establish a mapping relationship library between real-time parameters of the production line and decision thresholds, preset the optimal decision threshold range under different parameter combinations, monitor changes in production line parameters in real time, and when the parameters exceed the current threshold adaptation range, retrieve the corresponding threshold range based on the mapping relationship library and dynamically adjust the decision judgment criteria in combination with the current comprehensive confidence distribution: when the production speed increases, increase the confidence judgment threshold of metal impurity signals; when the environmental temperature and humidity fluctuate greatly, optimize the uncertainty allocation coefficient, establish a rule adjustment feedback mechanism, record the decision accuracy before and after adjustment, and continuously optimize the mapping relationship library; The dynamically adjusted decision results are compared and verified with the standard signal feature library. The decision accuracy, misjudgment rate, and missed judgment rate are calculated. If the indicators do not meet the preset requirements, the reasons for the deviation are analyzed. If it is due to unreasonable fusion weights, the weight allocation ratio is recalculated. If it is due to insufficient adaptability between the decision rules and real-time parameters, the mapping relationship library parameters are optimized. The verification results are fed back to the hybrid model training and decision rule adjustment stages to update the model parameters and rule mapping relationship, forming a closed-loop mechanism of training, fusion, decision, verification, and optimization.
6. The intelligent sensing-based online detection method for metal impurities in food according to claim 5, characterized in that: The method selects random forest and support vector machine to construct traditional machine learning sub-models and optimizes parameters to improve MobileNetV3 by building lightweight deep learning sub-models and adjusting their structure to prevent overfitting. Both models are adapted to linearly separable and complex nonlinear signal recognition, respectively, and both output category prediction results and corresponding confidence scores, including: Training data preprocessing and partitioning: The labeled sample dataset is divided into training set and validation set according to a preset ratio. Z-score standardization is performed on the input features of traditional machine learning sub-models to eliminate dimensional differences. For industrial-grade labeled datasets, data augmentation techniques such as signal cropping, noise superposition, and flipping are used to expand the sample size. At the same time, the feature matrix is adjusted to a three-dimensional tensor format that meets the input requirements of the improved MobileNetV3, adapting to the feature input specifications of deep learning models. Initialize the random forest model framework, set the selectable range of the number of decision trees, node splitting criteria, and maximum tree depth, and use 5-fold cross-validation combined with grid search traversal parameter combination. Select the optimal parameter combination with classification accuracy as the objective function. Record the prediction results of each decision tree during training, integrate and output the final class prediction through a voting mechanism, and calculate the corresponding confidence based on the vote ratio of each class. Radial basis function (RBF) and linear kernel function are selected as candidate kernel functions. The search range of penalty coefficient and kernel function parameters is set. Five-fold cross-validation combined with grid search is used to determine the optimal kernel function type and parameter values. For linearly separable signals, linear kernel function is preferred, and for weakly linearly separable signals, radial basis function is selected. The decision function value output by the model is converted into probability form by Platt scaling to obtain the prediction confidence of each category. The MobileNetV3-Large architecture is modified to be lightweight by compressing the number of channels in the original network, adding a lightweight attention module after the depthwise separable convolution, adjusting the network output layer so that the number of neurons in the fully connected layer matches the number of categories to be recognized, and using the softmax activation function in the output layer. Traditional machine learning sub-models are trained iteratively on the training set until the accuracy of the validation set stabilizes without improvement for multiple consecutive rounds. The improved MobileNetV3 uses the Adam optimizer, sets an initial learning rate and dynamically adjusts it through a learning rate decay strategy, introduces an early stopping mechanism, and terminates training when the validation set loss increases for multiple consecutive rounds. During the training process, an L2 regularization term is added to suppress parameter redundancy. The random forest sub-model generates confidence scores based on the proportion of each category in the decision tree voting; the support vector machine sub-model, after being scaled by Platt, maps the decision function values to probability values in the [0,1] interval as confidence scores; the improved MobileNetV3 calculates the probability distribution of each category through the softmax function of the output layer, and outputs the category prediction results and corresponding confidence scores. The performance of the two sub-models was tested on the validation set. For linearly separable signal sample sets, the classification accuracy, confidence, and discrimination of random forest and support vector machine were evaluated. For complex nonlinear signal sample sets, the feature fitting ability and prediction stability of the improved MobileNetV3 were verified. If the recognition effect did not meet the preset requirements, the parameters of the traditional model were re-optimized or the number of channels, attention module structure, and data augmentation strategy of the deep learning model were adjusted to ensure that the two models were adapted to the recognition requirements of the corresponding signal types.
7. The intelligent sensing-based online detection method and system for metal impurities in food according to claim 1, characterized in that: The online incremental learning framework built on federated learning uses KL divergence and PSI metrics to achieve feature drift detection and automatic parameter adjustment. It also incorporates a Q-Learning agent to construct a dynamic adjustment strategy library, including: We adopt an edge-cloud distributed federated learning topology, configure local data caching and incremental training units for edge nodes, deploy model aggregation and parameter distribution units in the cloud, define the communication protocol and synchronization cycle for training and aggregation, initialize the dynamic batch parameters of the sliding window, and build a distributed learning environment in which local data does not leave the database. The edge nodes filter recent effective detection data by using a sliding window and remove abnormal and duplicate samples. The edge nodes conduct local incremental training based on the incremental random forest algorithm to update the model parameters. The cloud receives the local model parameters of each node and aggregates them through the federated averaging algorithm. Then, the optimized global incremental model is distributed to each edge node. Using the drift-free historical features in the standard feature library as the baseline distribution, the current real-time signal features of the edge nodes are collected as the distribution to be tested. The KL divergence and PSI are used to calculate the joint judgment threshold. After the feature is judged to be drifted, the parameter adjustment process is automatically triggered. Based on the drift detection results, parameter calibration is performed in stages, the detection frequency band weight allocation of the multi-frequency sensing module is automatically adjusted, the dimensional configuration of wavelet packet decomposition and feature extraction is optimized, and the uncertainty allocation coefficient of the hybrid model decision threshold and DS evidence theory is dynamically corrected. A state space is constructed with feature drift type, drift degree, real-time production line parameters, and current model detection performance as the core. An action space is constructed with frequency band weight adjustment range, feature extraction dimension increase or decrease, decision threshold correction value, and incremental learning rate as the core. A quantitative reward function is constructed with maximizing detection accuracy and minimizing misclassification rate as the core. The weighted calculation of accuracy improvement and misclassification rate reduction is used as the agent's immediate reward, and the agent's initial configuration is completed. The agent is connected to the online detection system, enabling it to interact with the feature drift detection module and parameter adjustment module in real time. The agent selects an adjustment strategy from the action space based on the current system state, obtains the reward value from the environment after execution, updates the Q-value table based on the Bellman equation, iteratively optimizes the value score corresponding to the state-action, and gradually converges to the optimal decision strategy. The optimal adjustment strategies learned by the Q-Learning agent are categorized and stored according to drift scenarios, production line conditions, and signal types to form a standardized dynamic adjustment strategy library. When feature drift is detected, the optimal solution in the strategy library is retrieved and called in real time to complete parameter adjustment. At the same time, the learned strategies under new scenarios are continuously added to the strategy library to realize dynamic expansion and optimization of the strategy library, forming a closed-loop collaborative mechanism of online incremental learning, feature drift detection, and intelligent decision adjustment.
8. The intelligent sensor-based online detection method for metal impurities in food according to claim 1, characterized in that: The process of constructing a data-enhanced labeled sample dataset, optimizing the model through knowledge distillation and domain adversarial neural networks, and developing a lightweight inference engine for edge devices includes: Original signal samples from multiple scenarios are collected and labeled into a basic sample set according to four categories. After implementing various data augmentation operations, the training, validation, and test sets are divided according to a preset ratio, and invalid samples are removed to construct a data augmentation-labeled sample dataset that covers all scenarios and has high diversity. A deep learning model was selected as the teacher model. The model was trained to convergence based on the original labeled sample set and the model configuration was optimized. A lightweight student model was built. A lightweight convolutional structure was adopted and the number of channels was compressed. A knowledge distillation training process was designed. The output layer probability distribution and intermediate layer feature vector of the teacher model were used as distillation targets. A distillation loss function combining cross-entropy loss and feature matching loss was constructed. The gradient descent algorithm was used to iteratively train the student model. An early stopping mechanism was introduced to transfer the knowledge of the teacher model to the student model. In the knowledge distillation training, a domain adversarial neural network is embedded. The feature extraction layer of the student model is used as the feature encoder, and a new domain classifier is added to distinguish the production scenario domain to which the features belong. An adversarial training mechanism is constructed. The feature encoder aims to minimize the recognition accuracy of the domain classifier, while the domain classifier aims to maximize the discriminative power of the feature domain. The game process between the two is optimized through alternating iterative training. The domain adversarial optimization and knowledge distillation training are integrated to simultaneously optimize the classification accuracy and cross-domain generalization ability of the student model. The model performance is evaluated and relevant parameters are adjusted for different scenario sample sets until the model's generalization performance across all scenarios meets the detection requirements. Disassemble the hardware architecture of the edge device to clarify its computing power limit, storage capacity, computing unit characteristics and operating constraints. Perform model quantization optimization for the hardware characteristics of the edge device, quantize the weights and feature data of the student model from floating point to integer, carry out operator-level optimization, integrate continuous operators in the student model, optimize operator execution efficiency for the hardware instruction set of the edge device, adapt to the hardware parallel computing architecture, select an inference framework adapted to the edge device, convert the optimized quantized model into a model format supported by the framework, configure the scheduling strategy of the inference engine, optimize the data input and output process and inference caching mechanism, deploy a lightweight inference engine on the edge device, test the indicators and adjust the optimization strategy accordingly until the inference engine meets the operating requirements of the edge device. The optimized lightweight student model is deployed to the lightweight inference engine. Test set samples and samples collected in real time from the production line are run on edge devices to evaluate the model's recognition accuracy, inference latency, and memory power consumption. The performance of the unoptimized model is compared to verify the optimization effect of the lightweight inference engine. If there are problems with accuracy loss or inference efficiency, the knowledge distillation loss weight, domain adversarial training strategy, or operator optimization scheme are adjusted backtrackingly to form an inference engine collaborative system.
9. The intelligent sensing-based online detection method for metal impurities in food according to claim 1, characterized in that: The detection function, based on a heterogeneous architecture of MCU and FPGA / TPU, is executed with division of labor. It relies on local caching to ensure operation even when the network is down. Through edge and cloud collaborative optimization of the model, it synchronously optimizes data processing-related aspects, including: Clearly define the division of responsibilities between the MCU and the FPGA / TPU. The MCU is responsible for system control, lightweight data processing and result output, while the FPGA / TPU accelerates parallel computing-intensive tasks. High-speed interaction is achieved through standardized interfaces, and resources are dynamically allocated according to task requirements. Edge devices are configured with hierarchical local caches to store model parameters, feature libraries and detection data in a hierarchical manner. A network update and network outage switching mechanism is designed. When the network is out of service, the local cache is enabled to maintain continuous detection. Data is retransmitted after the network is restored. Edge nodes update their local models through incremental learning, only uploading parameter increments to the cloud. The cloud aggregates and optimizes the global model using a federated averaging algorithm and then distributes it. Adapted models are customized for the differences in computing power of edge devices, forming a collaborative optimization closed loop. The entire data processing process is optimized collaboratively. The data acquisition stage ensures time consistency and parallel preprocessing, the feature extraction stage implements parallel algorithm deployment, and the inference and decision-making stage executes tasks in a pipeline and processes real-time parameters synchronously, thus promoting parallel data processing and decision-making. The MCU integrates a system status monitoring unit to collect computing power and network data in real time, and dynamically adjusts task allocation, synchronization frequency and model strategy for different operating conditions. Build simulation testing and actual production verification environments to verify system capabilities, analyze bottlenecks and optimize algorithms and scheduling strategies, establish an evaluation index system, and form a stable and reliable testing system through continuous iteration.
10. An intelligent sensor-based online detection system for metal impurities in food, characterized in that, include: processor; A machine-readable storage medium for storing machine-executable instructions of the processor; The processor is configured to execute the intelligent sensing-based online detection method for metal impurities in food according to any one of claims 1 to 9 by executing the machine-executable instructions.