Water quality multi-parameter spectrum real-time detection method based on PYNQ-ZYNQ

By employing algorithms such as variational mode decomposition, adaptive soft thresholding, grouped dilated convolution, attention fusion, kernelized local preservation projection, and sparse autoencoder on the PYNQ-ZYNQ platform, the real-time and accuracy issues of water quality detection have been resolved. This enables online real-time detection of multiple water quality parameters, reduces detection costs, and adapts to the needs of different water quality scenarios.

CN121935581APending Publication Date: 2026-04-28LANZHOU INST OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LANZHOU INST OF TECH
Filing Date
2026-01-08
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing multi-parameter water quality detection methods suffer from problems such as long detection cycles, complex operations, and inability to provide real-time feedback on water quality changes. Furthermore, water quality detection applications based on the ZYNQ platform face challenges such as high AI deployment thresholds, difficulty in updating models, and difficulty in adapting to the band characteristics of spectral data and the resource constraints of embedded platforms.

Method used

A real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ is adopted. Through a combination of algorithms including variational mode decomposition-adaptive soft thresholding denoising, grouped dilated convolution-attention fusion-convolutional neural network, high-dimensional spectral feature extraction, kernelized local preservation projection-sparse autoencoder and gated recurrent unit-memory decay mechanism-long short-term memory network, the method achieves denoising, feature extraction and temporal prediction of spectral data. Combined with the interactive feedback and joint optimization between modules, it adapts to the hardware and software co-operation characteristics of the ZYNQ platform.

Benefits of technology

It improves the accuracy and stability of water quality parameter detection, realizes online real-time detection of multiple water quality parameters, reduces detection costs, adapts to the detection needs of different water quality scenarios, and has broad application prospects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121935581A_ABST
    Figure CN121935581A_ABST
Patent Text Reader

Abstract

The invention provides a PYNQ-ZYNQ-based water quality multi-parameter spectrum real-time detection method, and belongs to the technical field of water quality monitoring technology, spectral analysis technology and artificial intelligence fusion, the method comprises the following steps: S1, system initialization and original spectrum data acquisition; s2, carrying out spectral data denoising enhancement based on a variational mode decomposition-adaptive soft threshold; s3, high-dimensional spectral feature extraction based on a grouped dilated convolution-attention fusion-convolutional neural network; s4, performing feature decoupling and sparse compression based on a kernel locality preserving projection-sparse auto-encoder; s5, water quality index time sequence prediction based on a gating circulation unit-memory attenuation mechanism-long and short-term memory network; and S6, detection result output and multi-module joint optimization are carried out. Automatic, online and intelligent water quality detection is realized, and reliable technical support is provided for scenes such as water environment monitoring and water treatment process optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of water quality testing, monitoring technology, spectral analysis technology and artificial intelligence integration technology, and in particular to a real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ. Background Technology

[0002] Traditional multi-parameter water quality detection methods largely rely on offline laboratory analysis, requiring water sample collection followed by chemical reagent reactions and instrumental analysis to obtain results. This approach suffers from drawbacks such as long detection cycles, complex operations, and the inability to provide real-time feedback on water quality changes. To address the real-time issue, spectroscopic detection technology has been applied to water quality testing due to its advantages of speed, non-contact operation, and reagent-free operation. However, spectral data is susceptible to interference from ambient light, sensor drift, and light scattering, resulting in strong mixed noise and severe coupling of multi-parameter characteristics, directly impacting detection accuracy.

[0003] Meanwhile, embedded platforms are the core carriers for real-time water quality monitoring. The ZYNQ platform, with its hardware-software co-engineering architecture of "PL-side programmable logic + PS-side processing system," possesses the dual advantages of parallel computing and flexible scheduling, making it the preferred solution for deploying AI algorithms. However, existing water quality monitoring applications based on the ZYNQ platform have significant shortcomings: First, AI algorithm deployment has a high barrier to entry, requiring in-depth mastery of professional toolchains, and the tight coupling between hardware and software makes model updates difficult; second, existing applications are mostly general demonstrations, lacking in-depth optimization for spectral time-series data (which has non-stationarity and long-term dependency characteristics); third, traditional deep learning models (conventional CNNs, LSTMs) are difficult to adapt to the band characteristics of spectral data and the resource constraints of embedded platforms, and commonly used data processing algorithms (such as wavelet denoising and PCA dimensionality reduction) cannot effectively solve the problem of spectral noise and feature coupling.

[0004] In summary, existing technologies struggle to balance the real-time performance and accuracy of water quality testing with the engineering practicality of embedded platforms. There is an urgent need for a real-time multi-parameter spectral detection solution for water quality that is optimized for the ZYNQ platform and integrates innovative algorithms and models. Summary of the Invention

[0005] This invention provides a real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ. Addressing the technical pain points of traditional water quality detection methods, such as insufficient real-time performance, poor spectral data processing, and high AI deployment barriers on the ZYNQ platform, this invention improves the accuracy and real-time performance of multi-parameter water quality detection while ensuring resource compatibility with embedded platforms. It simplifies model deployment and update processes, achieving automation, online operation, and intelligent water quality detection, providing reliable technical support for scenarios such as water environment monitoring and water treatment process optimization.

[0006] To achieve the above objectives, the present invention adopts the following technical solution: A real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ includes: Step S1: Initialize the programmable logic terminal and processing system terminal of the ZYNQ platform, and collect raw spectral time-series data through the spectral sensor. The raw spectral time-series data covers the sensitive wavelength ranges corresponding to chemical oxygen demand, ammonia nitrogen, total phosphorus, and total nitrogen. Step S2: The original spectral time series data is denoised and enhanced using variational mode decomposition-adaptive soft thresholding to obtain denoised spectral time series data. The denoising process includes decomposing the original spectral time series data into multiple intrinsic mode function components, distinguishing between noise-dominant components and signal-dominant components, calculating an adaptive threshold based on the local signal-to-noise ratio, processing the noise-dominant components, and reconstructing the data. Step S3: High-dimensional spectral features are extracted from the denoised spectral time-series data using a grouped dilated convolution-attention fusion-convolutional neural network to obtain high-dimensional spectral features. The extraction process includes grouping the denoised spectral time-series data according to sensitive wavelength intervals, using dilated convolution operations with different dilation rates for each group, and calculating group weights and fusing features by combining a band attention mechanism. Step S4: The high-dimensional spectral features are decoupled and sparsely compressed using a kernelized local preservation projection-sparse autoencoder to obtain decoupled sparse features. The decoupling and compression process includes constructing a neighborhood graph and a kernel matrix, mapping the high-dimensional spectral features to a low-dimensional space through the projection matrix, and then sparsely encoding them through the sparse autoencoder. Step S5: The decoupled sparse features are modeled in a time-dependent manner using a gated recurrent unit-memory decay mechanism-long short-term memory network to predict the predicted values ​​of water quality parameters. The modeling process includes controlling memory retention and forgetting through update gates and reset gates, and introducing a memory decay factor to dynamically adjust the memory weights of data at different time steps. Step S6: Calculate the relative error and average relative error between the predicted and actual water quality parameter values. If the average relative error does not exceed the preset threshold, output the detection result. If it exceeds the preset threshold, start multi-module joint optimization and synchronously adjust the parameters of variational mode decomposition-adaptive soft threshold, grouped dilated convolution-attention fusion-convolutional neural network, kernelized local preservation projection-sparse autoencoder and gated recurrent unit-memory decay mechanism-long short-term memory network. Repeat steps S2 to S6 until the requirements are met.

[0007] In this specification, in step S2, during the denoising process of variational mode decomposition-adaptive soft thresholding, the number of intrinsic mode function components is determined based on the noise complexity and signal frequency band distribution of the original spectral time series data. The constraint variational problem is solved iteratively until the convergence condition is met. The convergence condition is set based on the degree of component difference between adjacent iterations.

[0008] In this specification, in step S2, the distinction between the noise-dominant component and the signal-dominant component is achieved through signal-to-noise ratio (SNR) determination. The SNR is calculated based on the signal strength and fluctuation of the component, and the SNR threshold is dynamically adapted according to the acquisition environment of the spectral data and the characteristics of the sensor.

[0009] In this specification, in step S3, the grouping of the grouped dilated convolution-attention fusion-convolutional neural network is based on the boundary of the sensitive wavelength interval corresponding to each water quality parameter. The expansion rate of each group is adapted according to the width and feature density of the corresponding sensitive wavelength interval to ensure that the receptive field covers the effective feature range of the interval.

[0010] In this specification, in step S3, the weight calculation of the band attention mechanism is based on the effective information ratio of each group of features. The normalized weight is determined by measuring the correlation between the group features and water quality parameters, so that the features of key sensitive bands can make a higher contribution in the fusion process.

[0011] In this specification, in step S4, during the construction of the neighborhood graph of the kernelized local projection, the number of nearest neighbor sample points is determined according to the sample density of the high-dimensional spectral features, the kernel function type of the kernel matrix is ​​selected based on the nonlinear distribution characteristics of the features, and the projection matrix is ​​obtained by solving the local neighborhood structure that preserves the features.

[0012] In this specification, in step S4, the network structure of the sparse autoencoder is designed according to the dimension and decoupling requirements of the high-dimensional spectral features. The sparsity constraint is achieved by penalizing the excessively dense distribution of the activation values ​​of the hidden layer, and the target sparsity is dynamically adjusted according to the redundancy of the features.

[0013] In this specification, in step S5, the memory decay factor is negatively correlated with the time step. The closer the time step is to the end of data acquisition, the larger the memory decay factor is, making the time-series dependence weight of recent data higher than that of distant data. The change pattern of the factor is adapted according to the time-series change characteristics of water quality parameters.

[0014] In this specification, the method also includes inter-module interactive feedback steps: grouped dilated convolution - attention fusion - feature extraction effect feedback of convolutional neural network to adjust variational mode decomposition - denoising parameters of adaptive soft thresholding, kernelized local preserving projection - feature decoupling effect feedback of sparse autoencoder to adjust grouped dilated convolution - attention fusion - attention weights of convolutional neural network, gated recurrent unit - memory decay mechanism - prediction effect feedback of long short-term memory network to adjust sparse constraint parameters of kernelized local preserving projection - sparse autoencoder.

[0015] In this specification, in step S6, the total loss function of the multi-module joint optimization allocates loss weights according to the degree of influence of each module on the detection accuracy. The parameter update adopts a gradient descent-type optimization algorithm. Through iterative adjustment, each module is coordinated and adapted until the average relative error meets the preset water quality detection accuracy requirements. The deployment of the ZYNQ platform follows the principle of deploying computationally intensive tasks on the programmable logic end and lightweight logic and scheduling tasks on the processing system end. The real-time detection is ensured by dynamically adjusting the module parameters.

[0016] In summary, the present invention has at least the following beneficial effects: It effectively solves the core pain points of mixed noise interference, multi-parameter feature coupling, and time-dependent distortion in spectral data, improves the accuracy and stability of water quality parameter detection, and avoids feature loss or over-smoothing problems caused by traditional algorithms.

[0017] Adapting to the hardware-software co-operation characteristics of the PYNQ-ZYNQ platform, it ensures real-time detection and meets the low-latency requirements of embedded scenarios through layered deployment of computationally intensive tasks and lightweight logic.

[0018] To reduce the engineering difficulty of deploying AI algorithms on the ZYNQ platform, modular design and interactive feedback mechanisms are used to achieve dynamic iteration and joint optimization of model parameters, thereby improving the system's adaptability and maintainability.

[0019] It enables real-time online detection of multiple water quality parameters without relying on chemical reagents and offline laboratory analysis, reducing manual intervention and lowering detection costs, thus providing technical support for the automation and intelligentization of water quality monitoring.

[0020] The fusion design of niche algorithms and heterogeneous models breaks through the traditional technical path, enhances the creativity and uniqueness of the solution, can adapt to the detection needs of different water quality scenarios, and has broad application prospects. Attached Figure Description

[0021] Figure 1 This is a schematic diagram of the real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ involved in this invention.

[0022] Figure 2 This is a schematic diagram of the detection process involved in this invention.

[0023] Figure 3 This is a schematic diagram of the module interaction feedback process involved in this invention.

[0024] Figure 4 This is a schematic diagram of the multi-module joint optimization process involved in this invention. Detailed Implementation

[0025] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0026] like Figure 1 and Figure 2 As shown, this embodiment provides a real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ. This scheme is based on the hardware and software collaborative architecture of the PYNQ-ZYNQ platform, and constructs a full-process detection system of "data acquisition - noise reduction and enhancement - feature extraction - decoupling and compression - time series prediction - result output - joint optimization". It integrates four key modules: variational mode decomposition (VMD) - adaptive soft thresholding (ASD), grouped dilated convolution (GDC) - attention fusion (AF) - convolutional neural network (CNN), kernelized local preservation projection (KLPP) - sparse autoencoder (SAE), gated recurrent unit (GRU) - memory decay mechanism (MDM) - long short-term memory network (LSTM).

[0027] First, 30 days of time-series spectral data are collected using a spectral sensor, and mixed noise is removed using VMD-ASD. Then, high-dimensional spectral features are extracted using GDC-AF-CNN, focusing on the contribution of key bands. Subsequently, KLPP-SAE is used to decouple features and compress them to reduce computational burden. Finally, GRU-MDM-LSTM is used to capture time-series dependencies and predict water quality parameters for day 31. Parameters are dynamically adjusted between modules through a bidirectional interactive feedback mechanism. Combined with a multi-module joint optimization strategy, detection accuracy and real-time performance are ensured, and the entire process is adapted to the collaborative characteristics of parallel computing on the PL end and logical scheduling on the PS end of the ZYNQ platform.

[0028] Step S1: System initialization and raw spectral data acquisition 1.1 Initialization of PYNQ-ZYNQ Platform Collaborative Architecture The ZYNQ platform's programmable logic unit (PL) and processing system unit (PS) are activated to establish the foundation for hardware-software collaborative operation. The PL loads a customized CNN / LSTM accelerated overlay, which is pre-configured with parallel computing units, timing processing units, and kernel matrix operation modules. Through FPGA logic resource reconfiguration, the parallel execution efficiency of computationally intensive tasks is ensured. Simultaneously, the PL's cache space is initialized, allocating an address range of 0x40000000-0x40010000 for temporary storage of intermediate processing data. On the PS side, a zero-copy DMA driver is started, configured with a transmission bandwidth of 100Mbps, and the source address of the data transmission is set to the address of the spectral sensor data register, while the destination address is set to the address of the PL-side cache. Direct memory access is used to avoid CPU intervention and reduce data transmission latency. The Overlay manager is started to coordinate the resource scheduling of various acceleration modules on the PL side. The spectral sensor Python driver is loaded (forming a collaborative architecture between PYNQ and ZYNQ). This driver supports the UART communication protocol with the sensor, and the communication baud rate is configured to 115200bps. The Jupyter interactive environment is started, and the graphical display module is initialized for the visualization output of subsequent detection results. Finally, the system sampling frequency is set to 1Hz to ensure that one complete set of spectral data is collected every day, meeting the time-series data requirements for a 30-day time step.

[0029] 1.2 Spectral Sensor Calibration and Raw Data Acquisition Select a miniature fiber optic spectral sensor (such as OceanOptics HR4000) compatible with the ZYNQ platform. This sensor covers the sensitive wavelength range of water quality parameters, specifically including the chemical oxygen demand (COD) sensitive wavelength range of 200-250 nm and ammonia nitrogen (…). The sensitive wavelength ranges for total phosphorus (TP) and total nitrogen (TN) are 250-300 nm, 300-350 nm, and 350-400 nm, respectively. The sampling interval is set to 1 nm, and a single acquisition covers 400 wavelength points. Before acquisition, the sensor is calibrated: first, reflectivity calibration is performed using a standard white board, and the spectral intensity values ​​of the standard white board at each wavelength point are recorded as a reference; then, dark current data is collected by obscuring the sensor probe with a dark box to subtract dark current noise from subsequent raw data. After calibration, the sensor probe is immersed in the water sample to be tested and data is collected continuously for 30 days, with one set of data collected each day at a fixed time (e.g., 10:00 AM), generating the raw spectral time-series data matrix. Its expression is ,in Indicates the time step (data from the first 30 days). Indicates the number of wavelength points. Indicates the first Heavenly The original spectral intensity values ​​at each wavelength point The value range is from 1 to 30. The value ranges from 200nm to 400nm (with 1nm intervals).

[0030] 1.3 High-speed transmission of raw data The PS initiates a data transfer request via a zero-copy DMA driver, transferring the raw data matrix stored in the sensor data register. The data is directly transferred to the preset buffer address (0x40000000-0x40010000) on the PL side. During the transfer, the DMA driver sends feedback on the transfer status to the PS side via an interrupt mechanism. When the transfer is complete, the PS side receives an interrupt signal and confirms data integrity (by verifying whether the data length is within the specified range). (Data points), and then notify the PL end that the cached data is ready, providing input for the denoising and enhancement processing in step S2. The raw data collected contains redundant information such as ambient light interference, sensor circuit noise, and baseline drift caused by light scattering. Directly using it for feature extraction would seriously affect the accuracy of subsequent models. Therefore, it needs to be processed by the algorithm in subsequent steps.

[0031] Step S2: Denoising and Enhancement of Spectral Data Based on Variational Mode Decomposition-Adaptive Soft Thresholding (VMD-ASD) The core contribution of the VMD-ASD algorithm lies in solving the problem of non-stationary mixed noise in spectral data. It separates noise and signal components through variational mode decomposition (VMD) and then combines it with adaptive soft thresholding (ASD) to dynamically suppress noise. This not only removes high-frequency random noise and low-frequency baseline drift, but also retains the spectral feature peaks corresponding to water quality parameters, providing high-quality input data for subsequent feature extraction by grouped dilated convolution-attention fusion-convolutional neural network (GDC-AF-CNN).

[0032] 2.1 VMD Model Construction and IMF Component Solution 2.1.1 Construction of Constrained Variational Problem The core idea of ​​VMD is to decompose non-stationary raw spectral time-series data into multiple intrinsic mode function (IMF) components with specific center frequencies. Each component exhibits sparsity, thereby achieving separation of noise and signal. For the raw data... (For time series data at a single wavelength point, to simplify calculations, we first process the data at a single wavelength point, and then extend it to the entire wavelength range.) The constrained variational problem is constructed as follows: ; ; in, The result of decomposition Each IMF component, verified through preliminary experiments, when... This allows for complete separation of noise and signal components from the original data, therefore setting... ; This represents the center frequency corresponding to each IMF component; Represents the partial derivative in the time domain; Represents the Dirac function; This represents the convolution operation; Represents the imaginary unit; Let L2 norm be a measure of the smoothness of the components. The objective of this constrained variational problem is to minimize the sum of the bandwidths of each IMF component after the Hilbert transform, while ensuring that the sum of all IMF components equals the original data.

[0033] 2.1.2 Transformation of Unconstrained Variational Problems To solve the above constrained variational problem, Lagrange multipliers are introduced. and penalty factor By incorporating the constraints into the objective function, the problem is transformed into an unconstrained variational problem: ; in, Indicates inner product operation; penalty factor To balance reconstruction error and the smoothness of IMF components, experimental determination was performed. This value can effectively suppress mode aliasing while ensuring signal reconstruction accuracy.

[0034] 2.1.3 Iterative Solution using the Alternating Direction Multiplier Method (ADMM) The alternating direction multiplier method (ADMM) is used to iteratively solve the unconstrained variational problem. The specific steps are as follows: 1. Initialize IMF components Center frequency Lagrange multipliers Set the iterative convergence threshold Number of iterations ; 2. Fixed and Update IMF weights The updated formula is: ; The formula is derived through convolution operations in the Fourier transform domain. It utilizes the sparsity of the frequency domain to simplify the calculation. Each iteration updates only a single IMF component while keeping the other components unchanged. 3. Fix and Update center frequency The updated formula is: ; in, express The Fourier transform of the center frequency is updated to the centroid of the IMF component energy spectrum, ensuring that each component corresponds to a specific frequency range. 4. Fix and Update Lagrange multipliers The updated formula is as follows ,in This is the iteration step size; 5. Calculate the convergence criterion for iterative iteration: If the condition is met, stop iterating; otherwise, let... Repeat steps 2-4.

[0035] For the original data matrix The above iterative process is performed sequentially for each wavelength point, ultimately yielding 8 IMF component matrices. Each component matrix has a dimension of 1. This corresponds to signal components in different frequency ranges.

[0036] 2.2 Adaptive Soft Thresholding (ASD) Denoising Processing 2.2.1 Identification of Noise Dominant Component and Signal Dominant Component To distinguish noise from signal components in each IMF component, the signal-to-noise ratio (SNR) of each IMF component is calculated. A higher SNR indicates a higher proportion of signal in that component. The formula for calculating the SNR is: ; in, Indicates the first The IMF component in the first The temporal average at each wavelength point. Set the signal-to-noise ratio threshold. After calculating the signal-to-noise ratio (SNR) for all wavelength points of each IMF component, the components with SNR lower than a certain threshold are counted. If the proportion of wavelength points exceeds 50%, then this component is determined to be the dominant noise component. If the proportion is less than or equal to 50%, it is determined to be the dominant component of the signal. This method allows for the accurate separation of the IMF component, which mainly contains high-frequency random noise, and the IMF component, which mainly contains water quality parameter characteristic signals.

[0037] 2.2.2 Adaptive Threshold Calculation For the noise-dominant component, an adaptive soft threshold is used for noise suppression. The threshold value is dynamically adjusted based on the local signal-to-noise ratio (LSNR) to avoid excessive signal smoothing or incomplete noise suppression caused by a fixed threshold. First, the LSNR of each noise-dominant component at each time point is calculated, and the local window size is set to... (Right now The formula for calculating the local signal-to-noise ratio is: ; in, Indicates the first The dominant noise component in the first The wavelength point, the first Local mean values ​​at time points. Adaptive threshold calculation based on local signal-to-noise ratio. : ; in, This is the threshold adjustment coefficient, used to fine-tune the threshold value; Indicates the first The dominant noise component in the first Standard deviation of each wavelength point; This is a statistical threshold factor based on time series length, ensuring the statistical significance of the threshold. A higher local signal-to-noise ratio (SNR) indicates a greater number of signal components at that time point, requiring a smaller threshold to retain more signal; conversely, a lower local SNR requires a larger threshold to more effectively suppress noise.

[0038] 2.2.3 Soft Threshold Processing and Component Correction For each time point and wavelength point of the noise-dominant component, perform soft thresholding: ; This process achieves denoising correction of the noise-dominant component by retaining signal components with absolute values ​​greater than a threshold and shrinking them toward the threshold, while suppressing noise components with absolute values ​​less than the threshold (setting them to 0).

[0039] 2.3 Denoising Data Reconstruction and Validation The dominant signal component is superimposed with the denoised noise component to reconstruct the denoised spectral time-series data matrix. The reconstruction formula is: ; in, This is the denoised data matrix. To verify the denoising effect, the overall denoised signal-to-noise ratio is calculated: ; like Then adjust the penalty factor. After increasing by 500, repeat steps 2.1-2.3 until... After verification, the PL side will output the denoised data matrix. The data is transmitted to the PS-end cache (address range 0x40010000-0x40020000) to provide input for feature extraction in step S3.

[0040] 2.4 Interactive Feedback Mechanism with GDC-AF-CNN The VMD-ASD algorithm interacts bidirectionally with the subsequent GDC-AF-CNN algorithm; the feature extraction performance of GDC-AF-CNN provides feedback to adjust the penalty factor of VMD. This is to further optimize the quality of the denoised data. The module interaction feedback process is as follows: Figure 3 As shown. The interactive feedback formula is: ; in, For feedback adjustment coefficient, For iteration rounds; The feature signal-to-noise ratio after feature extraction by GDC-AF-CNN. This represents the signal-to-noise ratio (SNR) for the current round of denoising. When the feature SNR of GDC-AF-CNN improves, increase it appropriately. To enhance denoising performance; when the feature signal-to-noise ratio decreases, reduce To avoid over-smoothing of the signal, the goal is to ensure that the denoised data can both remove noise and provide sufficient feature details for the CNN.

[0041] Step S3: High-dimensional spectral feature extraction based on Grouped Dilated Convolution-Attention Fusion-Convolutional Neural Network (GDC-AF-CNN) The core contribution of the GDC-AF-CNN algorithm lies in its ability to expand the receptive field and reduce computational load by using grouped dilated convolutions to target the band characteristics of spectral data. Combined with a band attention mechanism, it focuses on key wavelength features, replacing traditional CNNs to achieve more accurate and efficient high-dimensional spectral feature extraction, and providing highly discriminative feature inputs for subsequent feature decoupling and time-series prediction.

[0042] 3.1 GDC-AF-CNN Model Construction The model adopts a progressive structure of “input layer → grouped dilated convolutional layer → band attention layer → pooling layer → fully connected layer → feature output layer”, and the design of each layer is customized and optimized for the characteristics of spectral data.

[0043] 3.1.1 Input Layer Data Reshaping The denoised data matrix obtained in step S2 The input tensor is reshaped into a tensor format that meets the requirements of CNN input. Since the spectral data is single-channel time-band data, the reshaped input tensor is: ;in, (Time step) (Number of wavelength points), 1 indicates a single channel. During the reshaping process, the timing order and wavelength order are kept unchanged to ensure the consistency of the physical meaning of the data.

[0044] 3.1.2 Design of Grouped Hollow Convolutional Layers Considering that the four water quality parameters correspond to different sensitive wavelength ranges, the input tensor is divided according to the wavelength range. Groups, each group corresponds to a sensitive band for one water quality parameter, grouped as follows: Group 1 ( The corresponding COD-sensitive wavelength range is 200-250nm (wavelength points 1-100), group 2 ( )correspond -N sensitive wavelength range 250-300nm (wavelength point 101-200), group 3 ( The corresponding TP sensitive wavelength range is 300-350nm (wavelength point 201-300), group 4 ( This corresponds to the TN sensitive wavelength range of 350-400nm (wavelength points 301-400). Each group uses dilated convolutions with different dilation rates to expand the receptive field without increasing computational cost, capturing cross-band nonlinear feature correlations. Specific parameters are set as follows: Group 1 dilation rate... Group 2 expansion rate Group 3 expansion rate Group 4 expansion rate This setting is determined based on the width and characteristic distribution of the sensitive bands of each parameter, ensuring that the receptive field covers the entire sensitive range.

[0045] The formula for grouped dilated convolution is: ;in, Indicates the first Group input subtensors (dimensions) ); Indicates the grouped convolution kernel. (kernel size) (Input the number of channels) (Number of output channels), the convolutional kernels for each group are initialized independently; (Step size) ensures that the feature map size does not shrink; This represents the dilation rate of the corresponding group. The specific convolution operation process is as follows: ; in, For the convolution kernel time dimension index, Indexed by channel dimension, For time-series indexes, Wavelength point indexing. Through the dilation rate design of dilated convolution, the receptive field of the first group is 3, the second group is 7, the third group is 11, and the fourth group is 15, which not only covers the local features of each sensitive band, but also captures the global correlation across wavelength points.

[0046] The output sub-tensors of the four dilated convolutions are concatenated along the channel dimension to obtain the output tensor of the grouped dilated convolutional layer: ; where 256 is the sum of the number of output channels in the four groups ( ).

[0047] 3.1.3 Band Attention Layer Design To focus on the key wavelength characteristics of each water quality parameter and suppress invalid band features such as those caused by ambient light interference, a band attention mechanism is embedded, which enhances the contribution of effective features through adaptive weight allocation. First, the feature intensity of each group is calculated. : ; in, express The Subtensor (dimension) ), Reflecting the The overall strength of the group features. Attention weights are calculated based on feature strength. : ;in, This ensures the normalization of weights. Groups with higher feature strengths have larger attention weights, and their features account for a higher proportion in subsequent fusion.

[0048] Attention fusion is achieved by multiplying the attention weights by the subtensors of the corresponding groups: ; The fused tensor It retains the feature information of the four groups and highlights the contribution of key bands through weight allocation.

[0049] 3.1.4 Design of Pooling Layer and Fully Connected Layer To reduce feature dimensionality and computational cost, a max pooling layer is used to reduce the dimensionality of the fused feature tensor. The pooling kernel size is... Step length The calculation formula is: ; in, This is the channel index. The dimension of the feature tensor after pooling is... The timing length remains unchanged, while the wavelength dimension is compressed to half of its original value.

[0050] Fully connected layers map pooled feature tensors into fixed-dimensional high-dimensional feature vectors, with weight matrices... Bias term ,in (Feature dimension), the calculation formula is: ; in, Indexed by feature dimensions. Output of the fully connected layer. This is the high-dimensional spectral characteristic tensor, denoted as... .

[0051] 3.2 GDC-AF-CNN Model Training The core objective of model training is to optimize parameters such as convolution kernels and weight matrices so that the extracted high-dimensional features are as consistent as possible with the manually labeled real feature labels, thereby ensuring the effectiveness of the features.

[0052] 3.2.1 Construction of Training Dataset Spectral data and corresponding manually labeled features were collected from 1000 water quality samples. Each sample set included 30 days of spectral data (after noise reduction) and corresponding high-dimensional feature labels. (Extracted using spectral analysis software, dimensions) The dataset was divided into a training set (700 sets), a validation set (200 sets), and a test set (100 sets) in a ratio of 7:2:1. Input-output sample pairs were constructed using the sliding window method, with a window size of 30 days and a step size of 1 day.

[0053] 3.2.2 Definition of Loss Function Mean squared error (MSE) is used as the loss function to measure the difference between the features extracted by the model and the true labels: ; in, The number of samples in the training set. Indicates the first The feature output of each training sample Indicates the first The true feature labels of each training sample.

[0054] 3.2.3 Adam Optimizer Parameter Update The Adam optimizer is used to minimize the loss function and update the model parameters. The parameter update formula is: ; ; ; in, (First-order moment estimation of attenuation coefficient) (Second-order moment estimation of attenuation coefficient) The gradient of the loss function with respect to the parameters. The square of the gradient; The learning rate; To prevent small constants with a denominator of 0; For iteration rounds.

[0055] 3.2.4 Training Process Execution Set batch size (32 samples per batch), iteration rounds After each training round, the loss function value is calculated using the validation set. If the loss value on the validation set no longer decreases after 5 consecutive rounds, training is stopped and the current optimal model parameters are saved. If the stopping condition is not met, iteration continues until the maximum number of rounds is reached. After training, the model performance is evaluated using a test set. The feature extraction accuracy must reach above 90%. Otherwise, the model parameters are adjusted (such as increasing the number of convolutional kernels or adjusting the learning rate), and training is repeated.

[0056] 3.3 Interactive Feedback Mechanism with KLPP-SAE GDC-AF-CNN interacts bidirectionally with the subsequent kernel-preserving projection-sparse autoencoder (KLPP-SAE). The feature decoupling effect of KLPP-SAE provides feedback to adjust the band attention weights of GDC-AF-CNN, while the feature extraction signal-to-noise ratio of GDC-AF-CNN provides feedback to adjust the penalty factor of VMD-ASD. The module interaction feedback process is as follows: Figure 3 As shown. First, calculate the signal-to-noise ratio for feature extraction: ; Will Feedback is sent to step S2 for updating. Simultaneously, the decoupling accuracy of each group's features received from KLPP-SAE feedback is... (No. (Purity of group features after decoupling), calculate average decoupling accuracy. Adjust attention weights: ; in, For correction factor, For each iteration round, the attention weight of groups with decoupling accuracy higher than the average is appropriately increased to enhance the contribution of the group's features; for groups with decoupling accuracy lower than the average, the attention weight is decreased to avoid exacerbating feature coupling and ensure that the extracted high-dimensional features are more conducive to subsequent decoupling processing.

[0057] Step S4: Feature decoupling and sparse compression based on kernelized local preserving projection-sparse autoencoder (KLPP-SAE) The core contribution of the KLPP-SAE algorithm lies in solving the problem of multi-parameter feature coupling in high-dimensional spectral features. It preserves the local structure of features and maps them to a low-dimensional space by kernelized local preservation projection (KLPP). Combined with sparse autoencoder (SAE) to compress redundant features, it outputs low-dimensional, sparse, and highly discriminative decoupled features, reducing the computational burden of subsequent time series prediction models and improving prediction accuracy.

[0058] 4.1 KLPP-SAE Model Construction The model adopts a structure of "input layer → KLPP layer → SAE layer → decoupled sparse feature output layer" to achieve decoupling and compression of high-dimensional features.

[0059] 4.1.1 KLPP Layer (Nucleoside Preservation Projection) Design The core objective of the KLPP layer is to map high-dimensional features to a low-dimensional manifold space, preserve the local neighborhood structure of each water quality parameter feature, and achieve feature decoupling.

[0060] 1. Neighborhood graph construction: This involves processing the high-dimensional features output from step S3. Each time series point is considered as a sample point, and for each sample point... Searching by Euclidean distance Construct an adjacency matrix using the nearest neighbor sample points. : ; in, The kernel width is determined through cross-validation; Represents sample points The set of 10 nearest neighbor sample points; This represents the Euclidean distance between two sample points. The adjacency matrix is ​​used to describe the local correlation strength between sample points.

[0061] 2. Degree matrix calculation: Degree matrix It is a diagonal matrix, with diagonal elements , representing the sum of neighborhood associations for each sample point.

[0062] 3. Construction of the Laplace matrix: Laplace matrix It is used to characterize the structural properties of neighborhood graphs.

[0063] 4. RBF kernel matrix calculation: The kernel matrix is ​​constructed using radial basis functions (RBF). nuclear width The calculation formula is: ; Kernel matrices map high-dimensional features to kernel space, avoiding the complexity of directly processing high-dimensional data.

[0064] 5. Solving for the projection matrix: by minimizing the objective function ,subjectto Solve for the projection matrix ,in (Low-dimensional feature dimension) Represents the matrix trace operation. Let represent the identity matrix. The objective function ensures that the projected low-dimensional features retain the local structure of the original features, achieving feature decoupling. The solution process is achieved through eigenvalue decomposition, selecting the minimum eigenvalue... The eigenvectors corresponding to each eigenvalue form the projection matrix.

[0065] 6. Low-dimensional feature projection: Projecting high-dimensional features... By mapping to a low-dimensional space using a projection matrix, low-dimensional decoupling features are obtained. .

[0066] 4.1.2 SAE Layer (Sparse Autoencoder) Design The core objective of the SAE layer is to sparsely encode low-dimensional decoupled features, compress redundant features, and improve the compactness and discriminability of features.

[0067] 1. SAE Structure Design: SAE adopts a symmetrical structure of "input layer - hidden layer - output layer", with an input layer dimension of 128 (corresponding to...). The hidden layer dimension is 64 (sparse feature dimension), and the output layer dimension is 128 (consistent with the input layer dimension).

[0068] 2. Forward propagation process: Input layer to hidden layer: ,in This is the weight matrix from the input layer to the hidden layer. For bias terms, It is the ReLU activation function. This is the output of the hidden layer (sparse features).

[0069] Hidden layer to output layer: ,in This is the weight matrix from the hidden layer to the output layer. For bias terms, Reconstruct features for the output layer.

[0070] 3. Sparse Constraint Design: To achieve feature sparsity, KL divergence is introduced as a sparse constraint term to penalize excessively dense distribution of hidden layer activation values. ;in, The target sparsity (the proportion of non-zero activation values ​​in the hidden layer). This represents the average activation value of the hidden layer.

[0071] 4. Definition of Total Loss Function: The total loss function is the weighted sum of the reconstruction loss and the sparse constraint term. ; in, is the sparse regularization coefficient, which balances the weights of reconstruction loss and sparse constraints.

[0072] 4.1.3 Decoupling Sparse Feature Output After SAE training is complete, retrieve the hidden layer output. As the final decoupling sparse feature, it is denoted as This feature retains the core information of each water quality parameter while eliminating redundant features and coupling components, thus adapting to the input requirements of subsequent time-series prediction models.

[0073] 4.2KLPP-SAE Model Training The core objective of model training is to optimize parameters such as the projection matrix and SAE weight matrix so that the decoupled sparse features retain the key information of the original features while meeting the sparsity requirements.

[0074] 4.2.1 Construction of Training Dataset Using the same 1000 dataset as GDC-AF-CNN, the input is the high-dimensional features extracted by GDC-AF-CNN. The output labels are The dataset itself (the unsupervised training characteristics of the autoencoder) is used, while also referencing manually labeled purity labels for each parameter feature (used to evaluate the decoupling effect). The dataset partitioning is consistent with GDC-AF-CNN (7:2:1).

[0075] 4.2.2 Adam Optimizer Parameter Update Minimize the total loss function using the Adam optimizer Update model parameters The parameter update formula is: ; ; ; in, , , For learning rate, , For iteration rounds.

[0076] 4.2.3 Training Process Execution Set batch size iteration rounds After each training round, the decoupling accuracy is calculated using the validation set. (No. The purity of the decoupled features is measured by the correlation coefficient between the features of that group and other groups (the lower the correlation coefficient, the higher the decoupling accuracy). If the decoupling accuracy on the validation set does not improve after 5 consecutive rounds, training is stopped and the optimal model parameters are saved; otherwise, iteration continues. After training, the average decoupling accuracy on the test set should reach above 85%, and the sparsity should be between 0.12 and 0.18; otherwise, parameters (such as kernel width and sparsity regularization coefficient) should be adjusted and retraining should be performed.

[0077] 4.3 Interactive Feedback Mechanism with GRU-MDM-LSTM KLPP-SAE interacts bidirectionally with the subsequent gated recurrent unit-memory decay mechanism-long short-term memory network (GRU-MDM-LSTM). The prediction accuracy of GRU-MDM-LSTM is used to adjust the target sparsity of KLPP-SAE. Simultaneously, the decoupling accuracy feedback of KLPP-SAE adjusts the attention weights of GDC-AF-CNN. The module interaction feedback process is as follows: Figure 3 As shown. The interactive feedback formula is: ; in, For correction factor, For iteration rounds; The prediction accuracy of GRU-MDM-LSTM; The target accuracy is [target value]. When the prediction accuracy exceeds the target accuracy, increase [the target value] appropriately. To enhance feature sparsity; when the prediction accuracy is lower than the target accuracy, reduce To retain more feature information, ensuring that decoupling sparse features can both reduce the difficulty of time series modeling and provide sufficient information support for prediction.

[0078] Step S5: Time-series prediction of water quality indicators based on Gated Recurrent Unit-Memory Decay Mechanism-Long Short-Term Memory Network (GRU-MDM-LSTM) The core contribution of the GRU-MDM-LSTM algorithm lies in integrating the lightweight characteristics and memory decay mechanism of the Gated Recurrent Unit (GRU) to replace the traditional LSTM. While reducing the parameter scale, it accurately captures the temporal dependencies of the 30-day time step, prioritizes the retention of memory weights of recent key data, and improves the accuracy and efficiency of water quality indicator prediction.

[0079] 5.1 GRU-MDM-LSTM Model Construction The model adopts an "input layer → GRU gated layer → memory decay layer → output layer" structure. The design of each layer is optimized for the characteristics of time series data to ensure the accuracy of time series dependency capture.

[0080] 5.1.1 Input Layer and Data Adaptation The input layer receives the decoupled sparse features output from step S4. This feature has been freed of redundant and coupled components and can be directly used as the time-series input data for the model without additional preprocessing.

[0081] 5.1.2 GRU Gating Layer Design The GRU gating layer controls the memorization and forgetting of time-series data through update and reset gates, simplifying the structure of traditional LSTM and reducing the parameter size.

[0082] 1. Update Gate Calculation: Update the gate control's retention rate of the previous hidden state. The calculation formula is as follows: ; in, To update the gate weight matrix, To update the gate bias term; for Hidden state at time (initial value) (zero vector); Indicates will and Input feature concatenation at time step (dimension) ); The Sigmoid activation function has an output value range of [0,1]. The closer the value is to 1, the higher the proportion of the hidden state from the previous time step is retained.

[0083] 2. Reset Gate Calculation: The reset gate controls the forgetting rate of the hidden state at the previous moment. The calculation formula is as follows: ; in, To reset the gate weight matrix, To reset the gate bias term; the closer the output value of the Sigmoid activation function is to 0, the higher the proportion of forgetting the hidden state from the previous moment.

[0084] 5.1.3 Memory decay layer design To address the issue of traditional GRUs over-remembering redundant data from the distant past, a memory decay mechanism is introduced. This mechanism dynamically adjusts the memory weights based on the "time distance" of the time-series data; the further back in time the data is stored, the lower the memory weight, prioritizing the retention of recent key data. (Memory decay factor) The calculation formula is: ; in, The attenuation coefficient is used, and through experiments, it has been verified that this value can balance the weight distribution of near-term and long-term data. For time-series indexes (1-30), when (The most recent day) at, The memory weight is the largest; when (The furthest day) It has the smallest memory weight, which effectively suppresses the interference of redundant data in the long term.

[0085] 5.1.4 Calculation of Candidate Hidden State and Final Hidden State 1. Candidate Hidden States: Calculate candidate hidden states by combining the reset gate and the memory decay factor. ; in, The candidate state weight matrix is... Candidate state bias terms; This is the Hadamard product (element-wise product). It is a hyperbolic tangent activation function with an output value range of [-1, 1], used to introduce nonlinear characteristics.

[0086] 2. Final Hidden State: Combining the update gate and candidate hidden states, calculate the final hidden state: ; The formula indicates that the final hidden state consists of two parts: one part is the hidden state of the previous time step after adjustment by the update gate and memory decay factor, and the other part is the candidate hidden state after adjustment by the update gate, thus realizing the dynamic capture of time-series dependencies.

[0087] 5.1.5 Output Layer Design The output layer maps the final hidden state to predicted values ​​of four water quality parameters, calculated using the following formula: ; in, The output layer weight matrix (4 corresponds to COD, -N, TP, TN (four water quality parameters). For output layer bias terms; Indicates based on the previous The first day of data prediction The ultimate goal is to predict the water quality parameters for day 31. .

[0088] 5.2 Training the GRU-MDM-LSTM Model The core objective of model training is to optimize parameters such as gating weights and output weights so that the predicted water quality parameter values ​​are as consistent as possible with the actual values ​​detected manually.

[0089] 5.2.1 Construction of Training Dataset Decoupling sparsity features of 1000 water quality samples and corresponding actual water quality parameter labels Each sample group contains 30 days of characteristic data and the actual water quality parameter values ​​for day 31 (obtained manually in the laboratory, dimensionless). The dataset was divided into a training set (700 sets), a validation set (200 sets), and a test set (100 sets) in a 7:2:1 ratio, and input-output sample pairs were constructed using the sliding window method.

[0090] 5.2.2 Definition of Loss Function Mean squared error (MSE) is used as the loss function to measure the difference between the predicted and the actual values: ; in, The number of samples in the training set. Indicates the first The 31st day of the sample The true values ​​of each water quality parameter This represents the corresponding predicted value.

[0091] 5.2.3 Adam Optimizer Parameter Update The Adam optimizer is used to minimize the loss function and update the model parameters. The parameter update formula is: ; ; ; in, , , For learning rate, , For iteration rounds.

[0092] 5.2.4 Training Process Execution Set batch size iteration rounds After each training round, the prediction accuracy is calculated using the validation set. : ; in, To verify the real labels, These are the predicted values ​​for the validation set. If the accuracy on the validation set does not improve after 5 consecutive rounds, training stops and the optimal model parameters are saved; otherwise, iteration continues. After training, the prediction accuracy on the test set must reach above 90%; otherwise, parameters (such as the decay coefficient) are adjusted. After retraining (learning rate), the training will resume.

[0093] 5.3 Interactive Feedback Mechanism with KLPP-SAE The prediction accuracy of GRU-MDM-LSTM is directly fed back to KLPP-SAE to adjust the target sparsity. This forms a closed-loop optimization. The module interaction feedback process is as follows: Figure 3 As shown in step 4.3, when the prediction accuracy is higher than the target accuracy, the value should be appropriately increased. To further compress redundant features; when the prediction accuracy is lower than the target accuracy, reduce This is to retain more effective features and ensure the compatibility of decoupled sparse features with the time series prediction model.

[0094] Step S6: Output of detection results and joint optimization of multiple modules 6.1 Visual output of test results The PS terminal outputs the predicted water quality parameters for day 31 from GRU-MDM-LSTM. The data is transferred to the Jupyter interactive environment to generate a structured text report, presenting the detection results with precise numerical values ​​and key conclusions. The report contains four core parts: first, the single-parameter prediction results, which clearly define COD, ... The predicted values ​​for the four parameters -N, TP, and TN on day 31 (units are mg / L, mg / L, mg / L, mg / L respectively), and their 95% confidence intervals (expressed in the format of "[lower limit, upper limit]") are given, along with a trend conclusion compared to the historical values ​​of the previous 30 days (e.g., "The predicted COD value has increased by 2.1% compared to the average of the past 7 days, which is consistent with the recent water quality change pattern"). Secondly, multi-parameter error data are provided, directly listing the specific relative error values ​​for each parameter (retaining two decimal places), clarifying whether the error of each parameter is within the allowable range (≤5%). Thirdly, feature importance is ranked, listing the key band intervals extracted by GDC-AF-CNN from high to low contribution (e.g., "220-230nm (COD feature band) contribution 35.2%, 270-280nm (...)..."). The report includes the following parameters: "Contribution of -N characteristic bands (28.7%)", indicating the water quality parameters corresponding to each band; and fourth, the model performance indicators, clearly stating the prediction accuracy (rounded to two decimal places), average relative error (rounded to two decimal places), and total latency per detection (in milliseconds), while also explaining whether each indicator meets the preset requirements (prediction accuracy ≥ 90%, average relative error ≤ 5%, detection latency ≤ 100 ms). The structured report allows users to directly copy numerical data through the Jupyter environment for subsequent data archiving or further analysis.

[0095] 6.2 Calculation and Judgment of Prediction Error Calculate the relative error and average relative error for each water quality parameter to assess the reliability of the prediction results: ; ; in, For the first The relative error of each parameter, This represents the average relative error. A preset error threshold is set. ,like If the prediction result is reliable, the final structured detection report will be output; otherwise... This triggers a multi-module joint optimization process, improving prediction accuracy.

[0096] 6.3 Joint Optimization of Parameters from Multiple Modules When the prediction results do not reach the preset accuracy, joint optimization of four modules—VMD-ASD, GDC-AF-CNN, KLPP-SAE, and GRU-MDM-LSTM—is initiated. By synchronously adjusting the parameters of each module, overall performance is improved. The multi-module joint optimization process is as follows: Figure 4 As shown.

[0097] 6.3.1 Definition of Joint Loss Function Construct a total loss function that comprehensively considers the loss contribution of each module: ; in, , , The loss weights are determined through sensitivity analysis. The weight is the largest because the prediction loss directly reflects the accuracy of the detection result. and The weights correspond to the losses of feature extraction and feature decoupling, respectively, to ensure that each module is optimized collaboratively.

[0098] 6.3.2 Joint Parameter Update The parameters of all modules are updated using gradient descent. The updated formula is: ; in, The joint learning rate is lower than the learning rate of a single module to avoid parameter oscillations. This represents the gradient of the total loss function with respect to the joint parameters. is the L2 norm of the gradient, used to normalize the gradient direction.

[0099] 6.3.3 Optimization Iteration Termination Condition Set the maximum number of joint optimization rounds. After each round of optimization, steps S2-S5 are repeated to calculate the average relative error. .like If the optimization stops, output the optimized structured detection report; if the maximum number of rounds is reached... If the requirements are still not met, a structured detection report will be output with the note "It is recommended to re-collect sample data for model retraining".

[0100] Step S7: Real-time performance assurance and system maintenance of the ZYNQ platform 7.1 Hardware Parallel Optimization and Real-Time Monitoring The PL (Plug-in) employs a pipelined design, mapping computationally intensive tasks such as VMD decomposition, GDC-AF-CNN convolution operations, KLPP kernel matrix calculations, and GRU-MDM-LSTM gating calculations to the parallel computing units of the FPGA, enabling multi-task parallel execution. Timing constraints are optimized for the overlay using logic synthesis tools to ensure the total time for a single detection is ≤100ms, meeting real-time detection requirements. The PS (Power Supply) deploys a real-time monitoring module that collects the processing time of each module every 100ms, recording the VMD-ASD denoising time, GDC-AF-CNN feature extraction time, KLPP-SAE decoupling time, GRU-MDM-LSTM prediction time, and data transmission time. If the time of a module exceeds a preset threshold (e.g., VMD-ASD denoising time >30ms), the module parameters are automatically adjusted (e.g., reducing the number of IMF components in VMD). (Up to 6), to ensure that the overall testing delay does not exceed the standard.

[0101] 7.2 System Operation and Maintenance and Model Updates Establish a regular system operation and maintenance mechanism: The spectral sensor is calibrated weekly, standard white board and dark current data are re-acquired, and the calibration parameters of the sensor driver are updated; the ZYNQ platform's overlay and driver are tested monthly for stability, and cache space is cleared to avoid performance degradation caused by data residue; new water quality sample data (no less than 100 sets) are collected quarterly to incrementally train the GDC-AF-CNN, KLPP-SAE, and GRU-MDM-LSTM models, updating model parameters to adapt to changes in the water quality environment. During model updates, compatibility with the original system is maintained without modifying the hardware architecture or software interfaces, ensuring the system's sustainable operation.

[0102] In some embodiments, VMD-ASD and KLPP-SAE form a bidirectional interaction: Interaction mechanism: Positive correlation: Denoising data from VMD-ASD After features are extracted by GDC-AF-CNN, KLPP-SAE calculates the "noise residual" of the decoupled features. The impact of the small noise remaining after quantization and denoising on decoupling; Reverse feedback: Noise residual in KLPP-SAE Feedback adjusts the local window size in the adaptive soft threshold calculation of VMD-ASD. Optimize the precision of noise reduction; at the same time, VMD-ASD's noise reduction signal-to-noise ratio... Feedback adjustment of RBF core width in KLPP-SAE This allows the kernel space mapping to better adapt to the characteristics of the denoised data.

[0103] Interactive formula: (1) Calculation of noise residual degree (KLPP-SAE→VMD-ASD) ; in, These are the feature values ​​that managers want to denoise (laboratory-level noise removal) after KLPP processing. The smaller the value, the more beneficial the noise reduction effect is to decoupling.

[0104] (2) Adjusting the size of the local window in VMD-ASD ; in, The value range is [2,4], to avoid the window being too large, which would cause local information distortion, or too small, which would cause inaccurate threshold calculation.

[0105] (3) KLPP-SAE kernel width adjustment (VMD-ASD→KLPP-SAE) ; Where 25dB is the target denoising signal-to-noise ratio, when When it is higher than 25dB, increase the value appropriately. To expand nuclear space coverage; below 25 dB, reduce Focus on local effective features.

[0106] Core function: Through bidirectional feedback of noise residual and denoising signal-to-noise ratio, the denoising process is adapted to the feature decoupling depth, avoiding "incomplete denoising leading to decoupling interference" or "mismatched kernel width leading to decoupling distortion", thus improving the purity of decoupled features.

[0107] In some embodiments, VMD-ASD and GRU-MDM-LSTM interact bidirectionally: Interaction mechanism: Positive correlation: The denoised data quality of VMD-ASD directly affects the foundation of subsequent feature extraction and temporal modeling; GRU-MDM-LSTM calculates "temporal smoothness". This reflects the adaptability of the temporal continuity of the denoised data to the modeling process; Reverse Feedback: Timing Smoothness of GRU-MDM-LSTM and prediction relative error Joint feedback adjusts the penalty factor of VMD-ASD Meanwhile, the time-series fluctuation coefficient of VMD-ASD denoised data Feedback adjusts the memory decay factor of GRU-MDM-LSTM This allows the memory weight allocation to better adapt to the temporal stability of the data.

[0108] Interactive formula: (1) Calculation of temporal smoothness (GRU-MDM-LSTM→VMD-ASD) ; The closer the value is to 1, the smoother the time series data is, and the better it is for LSTM to capture long-term dependencies (the optimal range is [0.8, 1.0]).

[0109] (2) Combined adjustment of VMD-ASD penalty factor ; Wherein, 0.9 is the target temporal smoothness and 0.03 is the target average relative error. By using the joint weight of temporal smoothness and prediction error, the denoising effect and temporal continuity are balanced.

[0110] (3) Adjustment of memory decay coefficient of GRU-MDM-LSTM (VMD-ASD→GRU-MDM-LSTM) ; ; in, For the first The time-series mean at each wavelength point The time series fluctuation coefficient (target value 0.05); The larger the value, the more volatile the data. Slow down memory decay and retain more historical data for reference.

[0111] Core function: Establish a direct link between preprocessing and final prediction, so that the denoising process not only considers noise removal, but also adapts to the smoothness requirements of time series modeling; at the same time, it allows the memory mechanism of the time series prediction model to adapt to the actual fluctuation characteristics of the data, and improves the accuracy of long-term reliance on capture.

[0112] In some embodiments, GDC-AF-CNN and GRU-MDM-LSTM interact bidirectionally: Interaction mechanism: Positive correlation: High-dimensional features extracted by GDC-AF-CNN After decoupling via KLPP-SAE, GRU-MDM-LSTM calculates the "feature temporal correlation". The degree of matching between quantitative characteristics and the temporal changes of water quality parameters; Reverse Feedback: Temporal Correlation of Features in GRU-MDM-LSTM Feedback adjusts the grouped dilated convolution dilation rate of GDC-AF-CNN Meanwhile, the feature contribution of GDC-AF-CNN Feedback adjusts the output gate weight matrix of the GRU-MDM-LSTM This allows predictions to focus more on the parameters corresponding to features with high contribution.

[0113] Interactive formula: (1) Calculation of temporal correlation of features (GRU-MDM-LSTM→GDC-AF-CNN) ; in, For the first The time-series vector of group features, Its mean; These are the time-series true values ​​of the corresponding water quality parameters. Its mean; The closer to 1, the better the feature matches the time-series changes of the parameter (value range [-1, 1]).

[0114] (2) GDC-AF-CNN expansion rate adjustment ; The dilation rate is adjusted with a step size of 2 to avoid frequent fluctuations and ensure the temporal correlation between the receptive field adaptation features and parameters of the grouped convolution.

[0115] (3) GRU-MDM-LSTM output gate weight adjustment (GDC-AF-CNN→GRU-MDM-LSTM) ; ; in, For the first The set of dimensional indexes for group-group features. For the first The contribution of the group features (the sum of the contributions of the 4 groups of features is 1, with a target value of 0.25); by adjusting the output gate weights, the group features with high contribution have a greater impact on the prediction results.

[0116] Core function: To achieve direct linkage between feature extraction and temporal prediction, enabling the grouped convolution of GDC-AF-CNN to more accurately capture features related to the temporal sequence of parameters, while allowing GRU-MDM-LSTM to focus on high-contribution features, reducing the interference of invalid features on temporal modeling, and improving prediction accuracy.

Claims

1. A real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ, characterized in that, include: Step S1: Initialize the programmable logic terminal and processing system terminal of the ZYNQ platform, and collect raw spectral time-series data through the spectral sensor. The raw spectral time-series data covers the sensitive wavelength ranges corresponding to chemical oxygen demand, ammonia nitrogen, total phosphorus, and total nitrogen. Step S2: The original spectral time series data is denoised and enhanced using variational mode decomposition-adaptive soft thresholding to obtain denoised spectral time series data. The denoising process includes decomposing the original spectral time series data into multiple intrinsic mode function components, distinguishing between noise-dominant components and signal-dominant components, calculating an adaptive threshold based on the local signal-to-noise ratio, processing the noise-dominant components, and reconstructing the data. Step S3: High-dimensional spectral features are extracted from the denoised spectral time-series data using a grouped dilated convolution-attention fusion-convolutional neural network to obtain high-dimensional spectral features. The extraction process includes grouping the denoised spectral time-series data according to sensitive wavelength intervals, using dilated convolution operations with different dilation rates for each group, and calculating group weights and fusing features by combining a band attention mechanism. Step S4: The high-dimensional spectral features are decoupled and sparsely compressed using a kernelized local preservation projection-sparse autoencoder to obtain decoupled sparse features. The decoupling and compression process includes constructing a neighborhood graph and a kernel matrix, mapping the high-dimensional spectral features to a low-dimensional space through the projection matrix, and then sparsely encoding them through the sparse autoencoder. Step S5: The decoupled sparse features are modeled in a time-dependent manner using a gated recurrent unit-memory decay mechanism-long short-term memory network to predict the predicted values ​​of water quality parameters. The modeling process includes controlling memory retention and forgetting through update gates and reset gates, and introducing a memory decay factor to dynamically adjust the memory weights of data at different time steps. Step S6: Calculate the relative error and average relative error between the predicted water quality parameter value and the actual water quality parameter value. If the average relative error does not exceed the preset threshold, output the detection result. If the preset threshold is exceeded, multi-module joint optimization is initiated, and the parameters of variational mode decomposition-adaptive soft thresholding, grouped dilated convolution-attention fusion-convolutional neural network, kernelized local preservation projection-sparse autoencoder and gated recurrent unit-memory decay mechanism-long short-term memory network are adjusted synchronously. Steps S2 to S6 are repeated until the requirements are met.

2. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S2, during the variational mode decomposition-adaptive soft thresholding denoising process, the number of intrinsic mode function components is determined based on the noise complexity and signal frequency band distribution of the original spectral time series data. The constraint variational problem is solved iteratively until the convergence condition is met. The convergence condition is set based on the degree of component difference between adjacent iterations.

3. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S2, the distinction between noise-dominant components and signal-dominant components is achieved through signal-to-noise ratio (SNR) determination. The SNR is calculated based on the signal strength and fluctuation of the components, and the SNR threshold is dynamically adapted according to the acquisition environment of the spectral data and the characteristics of the sensor.

4. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S3, the grouping of the grouped dilated convolution-attention fusion-convolutional neural network is based on the boundary of the sensitive wavelength interval corresponding to each water quality parameter. The expansion rate of each group is adapted according to the width and feature density of the corresponding sensitive wavelength interval to ensure that the receptive field covers the effective feature range of the interval.

5. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S3, the weight calculation of the band attention mechanism is based on the effective information ratio of each group of features. The normalized weight is determined by measuring the correlation between the group features and water quality parameters, so that the features of key sensitive bands can make a higher contribution in the fusion process.

6. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S4, during the construction of the neighborhood graph of the kernelized local projection, the number of nearest neighbor sample points is determined according to the sample density of the high-dimensional spectral features, the kernel function type of the kernel matrix is ​​selected based on the nonlinear distribution characteristics of the features, and the projection matrix is ​​obtained by solving the local neighborhood structure that preserves the features.

7. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S4, the network structure of the sparse autoencoder is designed according to the dimension and decoupling requirements of the high-dimensional spectral features. The sparsity constraint is achieved by penalizing the excessively dense distribution of the activation values ​​of the hidden layer, and the target sparsity is dynamically adjusted according to the redundancy of the features.

8. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S5, the memory decay factor is negatively correlated with the time step. The closer the time step is to the end of data collection, the larger the memory decay factor is, making the time-series dependence weight of recent data higher than that of distant data. The change pattern of the factor is adapted according to the time-series change characteristics of water quality parameters.

9. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, It also includes inter-module interaction feedback steps: grouped dilated convolution - attention fusion - feature extraction effect feedback of convolutional neural network to adjust variational mode decomposition - denoising parameters of adaptive soft thresholding, kernelized local preserving projection - feature decoupling effect feedback of sparse autoencoder to adjust grouped dilated convolution - attention fusion - attention weights of convolutional neural network, gated recurrent unit - memory decay mechanism - prediction effect feedback of long short-term memory network to adjust sparse constraint parameters of kernelized local preserving projection - sparse autoencoder.

10. The real-time multi-parameter spectral detection method for water quality based on PYNQ-ZYNQ according to claim 1, characterized in that, In step S6, the total loss function of the multi-module joint optimization allocates loss weights according to the degree of influence of each module on the detection accuracy. The parameter update adopts a gradient descent-type optimization algorithm. Through iterative adjustment, the modules are coordinated and adapted until the average relative error meets the preset water quality detection accuracy requirements. The deployment of the ZYNQ platform follows the principle of deploying computationally intensive tasks on the programmable logic end and lightweight logic and scheduling tasks on the processing system end. The real-time detection is ensured by dynamically adjusting the module parameters.