A spectral detection device and method for pet food

By combining dark-field and standard whiteboard calibration with a spectral sampling method, along with logarithmic mapping and local spline basis functions, the problems of unstable instrument calibration and cumbersome model parameter tuning in pet food spectral detection are solved. This achieves efficient and automated spectral detection, improving detection consistency and model versatility.

CN120668594BActive Publication Date: 2026-01-30BRITISH TESTING TECH (FOSHAN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510869397.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2026-01-30
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

Existing pet food spectral detection technologies suffer from problems such as unstable instrument calibration, insufficient signal preprocessing, cumbersome model parameter optimization, lack of adaptability in judgment thresholds, and high false judgment rate, making it difficult to achieve automated and batch testing.

Method used

A spectral sampling method combining dark field and standard whiteboard calibration is adopted. The dynamic range is compressed by logarithmic mapping, a local linear spline basis function is constructed, the adaptive regularization coefficient is calculated, the spline coefficients are solved and the spectrum is reconstructed, a statistical reference model is established, and a complete test report is generated.

Benefits of technology

It improves detection consistency and sensitivity, enhances the ability to identify weak spectral features, reduces noise interference, realizes flexible decomposition and adaptive fitting of spectral morphology, provides full-band error quantification indicators, and improves the model's versatility and detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120668594B_ABST
    Figure CN120668594B_ABST
Patent Text Reader

Abstract

This invention relates to the field of pet food spectral detection technology, and discloses a pet food spectral detection device and method. The method involves sampling at equal intervals within a preset wavelength range, eliminating noise interference through dark current and standard white plate calibration; taking the natural logarithm of reflectance to balance the dynamic range; constructing a linear spline basis at equal intervals, and adaptively calculating the regularization coefficient based on the energy ratio of the signal and basis functions; constructing an augmented matrix based on the inner product of the basis functions and the signal, and solving for the spline coefficients using Gaussian elimination; reconstructing the spectrum using the coefficients and quantifying the residuals; establishing a reference model based on the mean and standard deviation of multiple qualified sample coefficients; comparing the Euclidean distance between the coefficients of the sample to be tested and the model mean with a threshold, and generating residuals, distances, thresholds, and a judgment report; the entire process requires no empirical parameters or manual tuning, enabling batch online adaptive detection, achieving rapid and accurate detection with noise correction, feature enhancement, overfitting suppression, and traceability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of pet food spectral detection technology, specifically to a pet food spectral detection device and detection method. Background Technology

[0002] Pet food is a crucial source of nutrition and health for pets, and its ingredients and quality directly impact their growth, development, immune function, and digestive abilities. With the rapid growth of the pet consumer market, the requirements for pet food quality control are constantly increasing. Spectroscopic detection technology, due to its advantages of being non-destructive, rapid, and allowing for online monitoring, is gradually becoming an important means of food safety testing.

[0003] First, common spectrometer calibration methods rely on manually setting thresholds or empirical parameters. The traditional approach involves manually measuring dark current with the light source off and measuring a reference signal on a standard white board, then calculating reflectance using a fixed formula. However, due to factors such as instrument temperature drift, light source intensity fluctuations, and ambient light interference, the obtained dark current and reference signal are prone to deviation, leading to unstable reflectance after calibration. This experience-based calibration method struggles to meet the consistency requirements between different batches of samples and various spectrometer models. Second, preprocessing of the calibrated reflectance signal typically involves simple translation or linear transformation to remove DC offset or scale the signal amplitude. However, this method fails to effectively compress the signal dynamic range and cannot highlight the weak characteristic information of trace components on the spectral curve. In complex pet food matrices, absorption peaks of major components such as proteins, fats, and vitamins, as well as various additives, often overlap or mask each other, making it difficult for simple preprocessing to extract weak spectral features suitable for quality assessment. Third, for modeling and decomposing spectral signals, most literature employs methods such as polynomial fitting, wavelet denoising, or fixed-order Fourier decomposition. These methods require pre-setting the polynomial order, wavelet basis type, or number of Fourier expansion terms, and empirically adjusting the regularization parameters to balance fitting accuracy and spectral smoothness. Since model parameters are closely related to sample type and sampling conditions, each application necessitates a repetitive and tedious parameter tuning process, making automation and batch testing difficult. Furthermore, existing technologies typically employ statistical methods such as peak alignment or principal component analysis (PCA) to determine sample compliance. PCA relies on a large amount of data from existing qualified samples and pre-trained models, lacking adaptability to setting thresholds for new samples; peak alignment is susceptible to spectral drift and matrix effects, leading to a high false positive rate. Moreover, these methods often only provide "qualified / unqualified" results, failing to offer intuitive visualizations such as residuals and distances, which is detrimental to continuous improvement and traceability management in the quality control process.

[0004] Therefore, this case aims to propose a spectral detection device and method for pet food. First, the original signal is calibrated with a dark field and a standard white board to eliminate the influence of the instrument and the environment. Then, the dynamic range is compressed through logarithmic mapping. Subsequently, a local linear spline basis function is constructed with equidistant nodes to achieve flexible decomposition of complex spectral shapes. An adaptive regularization coefficient is introduced to balance the fitting accuracy and stability. Next, the spline coefficients are solved and the spectrum is reconstructed to evaluate the full-spectrum residual norm. Finally, a statistical reference model is established based on multiple verified qualified samples. The qualification is determined by the distance between the sample to be tested and the model, and a complete test report is generated. Summary of the Invention

[0005] This invention provides a pet food spectral detection device and detection method, which helps to solve the problems mentioned in the background art.

[0006] This invention provides the following technical solution: a method for spectral detection of pet food, comprising:

[0007] Within the preset minimum and maximum scanning wavelength range, the sample is spectrally sampled at equal intervals, and the dark current signal measured by the spectrometer under dark field conditions and the reference reflectance intensity measured after placing a standard white plate are calibrated.

[0008] The obtained corrected reflectance signal is subjected to a natural logarithmic transform to obtain a logarithmic domain spectral signal.

[0009] The wavelength range of the logarithmic domain signal is divided into several equally spaced intervals. The endpoints of each interval are used as spline node positions, and corresponding linear spline basis functions are constructed based on each node position.

[0010] The adaptive regularization coefficient is calculated based on the ratio of the total energy of the logarithmic domain spectral signal to the total energy of the linear spline basis function;

[0011] A system of linear equations is constructed based on the inner product relationship between the linear spline basis functions and the logarithmic domain signal, and the spline coefficients are obtained by solving the Gaussian elimination method.

[0012] The original spectral signal is reconstructed using spline coefficients and the residuals between the reconstructed signal and the original signal at each wavelength are calculated to construct the evaluation total residual norm.

[0013] For multiple verified qualified pet food samples, the corresponding spline coefficients were obtained, and the mean and standard deviation of each coefficient were calculated based on the spline coefficients to establish a qualified sample reference model.

[0014] The spline coefficients of the sample to be tested are obtained, and the Euclidean distance between them and the average value of the reference model is calculated. The distance is then compared with the judgment threshold to determine the qualification of the sample to be tested. Finally, a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result is generated.

[0015] Optionally, the step of sampling the sample at equal intervals within a preset minimum and maximum scanning wavelength range, and calibrating the dark current signal measured by the spectrometer under dark field conditions and the reference reflectance intensity measured after placing a standard white plate, specifically includes:

[0016] Set the spectral scanning range to [λ] min ,λ max The sampling interval is Δλ; where λ min λ is the minimum scanning wavelength. max Maximum scanning wavelength;

[0017] Calculate the total number of sampling points

[0018] Calculate the i-th sampling wavelength λ i =λ min +(i-1)Δλ, i = {1,2,...N}; where i is the sampling index;

[0019] Under conditions of no sample and with the light source off, the dark current D at the i-th wavelength was measured and recorded sequentially using the built-in photodiode array sensor of the spectrometer. i ;

[0020] Place a standard white board with a reflectivity of ≈1, turn on the light source, and use a photoelectric sensor to measure and record the reference intensity R at the i-th wavelength. i ;

[0021] A uniformly pulverized pet food sample was placed in the sample chamber. After turning on the light source, the original intensity was collected and recorded using a photoelectric sensor.

[0022] Calculate the corrected reflectance at point i.

[0023] Optionally, performing a natural logarithmic transform on the obtained corrected reflectivity signal specifically includes:

[0024] Reflectance I after correction at point i i Perform a logarithmic transformation to obtain the logarithmic domain signal S at point i. i Specifically:

[0025] S i =ln(1+I) i ).

[0026] Optionally, the step of dividing the wavelength range of the logarithmic domain signal into several equally spaced intervals, using the endpoints of each interval as spline node positions, and constructing corresponding linear spline basis functions based on each node position specifically includes:

[0027] Calculate the total number of spline nodes

[0028] Set the wavelength of the k-th spline node to...

[0029] Where k = {1,...,K} is the spline node index;

[0030] Set the bandwidth between nodes to equal spacing.

[0031] Constructing linear spline basis functions: Among them, the function max(a,b) returns the larger of a and b; |*| is the absolute value function; B i,k For wavelength λ i The k-th basis function value.

[0032] Optionally, the calculation of the adaptive regularization coefficient based on the ratio of the total energy of the logarithmic domain spectral signal to the total energy of the linear spline basis function specifically includes:

[0033] Statistical logarithmic signal energy

[0034] Calculate the sum of the basis function energies

[0035] Set the adaptive regularization coefficient to

[0036] Optionally, the step of constructing a system of linear equations based on the inner product relationship between the linear spline basis functions and the logarithmic domain signal, and obtaining the spline coefficients by solving the Gaussian elimination method, specifically includes:

[0037] Construct the coefficient matrix

[0038] in, M is the set of real matrices with K rows and K columns; k,l The elements of the coefficient matrix are k,l = {1,2,...,K}, δ k,l For Kroneck δ, δ is true if and only if k = l. k,l =1, otherwise δ k,l =0; l is the matrix column index;

[0039] Construct a constant vector Among them, b k Elements of a constant vector; It is a set of real column vectors of length K;

[0040] Constructing augmented matrices Where | indicates that b is added as an augmenting column after M; It is a set of real matrixes with K rows and K+1 columns;

[0041] Perform the following steps to eliminate rows of p from 1 to K-1:

[0042] S110, Subject: E p,p ≠0; where p is the pivoting step index of Gaussian elimination;

[0043] S120. For each row e = {p+1,...K}, perform the following steps:

[0044] S121, Elimination Factor:

[0045] S122, Update all columns v = {p,...,K+1} in this row: E e,v ←E e,v -f e,p E p,v ;

[0046] Let the Kth unknown be...

[0047] Let the k-th unknown be... Where k = {K-1,...,1};

[0048] Constructing spline basis coefficient vectors Among them, each w k The linear coefficients corresponding to the k-th basis function.

[0049] Optionally, the step of using spline coefficients to perform weighted reconstruction of the original spectral signal and calculating the residuals between the reconstructed signal and the original signal at each wavelength point to construct an evaluation total residual norm specifically includes:

[0050] Reconstructed signal in, This is the reconstructed signal at point i.

[0051] Calculate the residual at point i.

[0052] Construct the total residual norm

[0053] Optionally, the step of obtaining corresponding spline coefficients for multiple verified qualified pet food samples, and calculating the mean and standard deviation of each coefficient based on the spline coefficients to establish a qualified sample reference model specifically includes:

[0054] For J verified qualified samples, obtain the spline basis coefficient vector w respectively. (j) , j = {1,...,J}; where j is the index of the qualified sample;

[0055] Calculate the reference mean of the k-th base coefficient:

[0056] Calculate the Euclidean distance between the coefficients and the mean of the j-th reference sample.

[0057] Calculate the average distance

[0058] Calculate the standard deviation of distance

[0059] Optionally, the step of obtaining the spline coefficients of the sample to be tested, calculating the Euclidean distance between them and the average value of the reference model, comparing them with the judgment threshold, determining the passability of the sample to be tested, and finally generating a test report containing the total residual norm, Euclidean distance, judgment threshold, and judgment result, specifically includes:

[0060] Obtain the coefficient vector w of the sample to be tested (new) ;

[0061] Calculate the coefficient space distance with the reference model

[0062] Set the decision threshold to T = μ + 3σ;

[0063] Construct a pass / fail judgment function

[0064] If Result = 1, then the sample to be tested is deemed qualified.

[0065] If Result = 0, the sample to be tested is deemed unqualified.

[0066] Output the total residual norm r and the coefficient spatial distance d. new The determination threshold T and the determination result.

[0067] An apparatus for implementing the pet food spectral detection method, comprising:

[0068] Wavelength sampling and calibration unit: used for wavelength sampling and instrument calibration;

[0069] Signal mapping unit: used for logarithmic signal mapping;

[0070] Spline node and basis function construction unit: used for selecting spline nodes and constructing basis functions;

[0071] Adaptive regularization coefficient calculation unit: used for adaptive regularization coefficient calculation;

[0072] Coefficient matrix construction and solution unit: used for coefficient matrix construction and Gaussian elimination solution;

[0073] Spectral Reconstruction and Residual Evaluation Unit: Used for spectral reconstruction and residual evaluation;

[0074] Reference model building unit: used for building reference models for qualified samples;

[0075] Judgment and Report Output Unit: Used for judging and reporting new samples.

[0076] The present invention has the following beneficial effects:

[0077] 1. This innovative approach combines dark-field background signals with standard white board signals during the sampling and calibration phases, performing full-spectrum scanning of unknown samples at fixed intervals to obtain calibrated, dimensionless reflectance signals. Traditional techniques typically rely solely on white board calibration, neglecting the masking effect of dark-field background on weak signals. This approach, however, simultaneously acquires dark-field signals, effectively eliminating instrument background noise and significantly improving sensitivity to low-reflectance features. Furthermore, by pre-calculating the sample sampling point distribution, uniform coverage across the entire spectral range is ensured, meeting resolution requirements while avoiding data redundancy. Compared to existing simple scanning methods with fixed step sizes or manual adjustments, this approach reduces noise interference and improves detection consistency without increasing hardware costs, laying a solid foundation for subsequent signal processing and model building.

[0078] 2. After obtaining the corrected reflectance signal, this scheme, for the first time, maps it entirely to the logarithmic domain. This not only simply compresses the dynamic range but also enhances the identifiability of weak spectral features. Traditional spectral detection often directly fits the original reflectance, easily becoming dominated by high-intensity signal regions while neglecting weak absorption peaks. Logarithmic mapping, however, smoothly reduces the signal differences between different segments, allowing for a more balanced focus on low-intensity bands in the subsequent basis function fitting stage. Simultaneously, this mapping improves numerical stability, avoiding numerical overflow or gradient imbalance problems that may occur with direct fitting. Compared to common polynomial fitting or direct Fourier transform, logarithmic processing better reflects the physical characteristics of absorption spectra, providing a robust preprocessing method for accurately extracting fingerprint peak shapes.

[0079] 3. This scheme constructs linear spline basis functions based on the logarithmic domain signal, using a pre-defined equidistant node distribution as a principle, thereby achieving flexible decomposition of the entire spectral morphology. Compared with traditional global polynomial fitting, local spline basis functions can better capture subtle abrupt changes and detailed features in different bands of the spectrum, avoiding overfitting or oscillations caused by higher-order polynomials. Simultaneously, through adaptive selection of the number of nodes, it dynamically balances fitting accuracy and computational complexity, ensuring detail reproduction without excessive waste of computational resources.

[0080] 4. After constructing the spline basis functions, this scheme innovatively calculates the adaptive regularization coefficient dynamically based on the ratio of the overall signal energy to the basis function energy, thus balancing fitting accuracy and algorithm stability. Traditional regularization methods typically use fixed coefficients or empirical values ​​for parameter tuning, which cannot account for differences in signal intensity between different samples. This scheme, however, uses a data-driven approach to automatically adjust the regularization strength, avoiding feature loss due to over-smoothing and reducing noise amplification caused by overfitting.

[0081] 5. For the linear equation system composed of spline basis functions and the inner product of the logarithmic domain signal, this scheme employs a stable and efficient matrix elimination process to solve the coefficient vector, ensuring that the optimal local fitting weights can still be obtained under finite accuracy conditions. Existing methods often use iterative optimization or least squares solutions, which suffer from slow convergence speed and easy getting trapped in local minima. However, by using the row and column elimination strategy of the augmented matrix, not only can the parameter solution be completed in one go, but it also has high determinism and traceability, facilitating engineering implementation and hardware acceleration. The advantages of this approach are that it significantly shortens the computation time, improves the solution accuracy, and avoids numerical drift that may occur during iteration, providing an accurate and reliable coefficient foundation for subsequent spectral reconstruction.

[0082] 6. Using the spline coefficients obtained above, this scheme reconstructs the original spectrum through weighted reassembly and calculates the full-spectrum residual norm between the reconstructed signal and the actual observed signal to quantify the fitting effect. Compared with traditional evaluation methods that only focus on local peak differences or overall correlation coefficients, the residual norm can provide a quantitative indicator of cumulative error across the entire band, more intuitively reflecting the degree to which the model restores spectral details. This evaluation method takes into account both local and global aspects, outputting in one-dimensional scalar form, which can serve as an important feature for subsequent quality judgment; at the same time, it retains error distribution information, providing a clear basis for further model optimization or anomaly diagnosis. This method solves the pain point of the lack of a unified evaluation standard in existing technologies, improving the scientific nature and consistency of quality assessment.

[0083] 7. For multiple verified and qualified pet food samples, this method extracts their spline coefficients and calculates the central tendency and fluctuation range of each coefficient based on statistical principles, thereby constructing a reference model for qualified samples. Traditional spectral detection often relies on single samples or empirical thresholds, lacking a quantitative understanding of the differences among sample groups; while this method, through large-scale statistics, obtains more representative characteristic means and distribution ranges, fully taking into account the natural variability between samples. This not only improves the model's versatility in dealing with various brands and formulas but also avoids the risk of misjudgment due to single data anomalies, providing a more stable and reliable benchmark for subsequent sample judgment.

[0084] 8. After establishing the reference model, this solution measures the distance between the coefficient features of the sample to be tested and the central features of the reference model, and automatically determines whether it is qualified or not according to preset rules. Finally, a complete report is generated, including the residual norm, matrix metric, threshold, and judgment result. Compared with traditional methods that manually set thresholds or rely on simple similarity indicators, this solution rationally sets the judgment boundary based on statistical distribution principles, making the qualification standard both scientifically rigorous and adjustable and controllable. Automated report generation not only improves detection efficiency but also ensures the consistency and traceability of the output content, facilitating subsequent quality file management and audit tracking, and meeting the dual requirements of modern quality control for rapid response and traceability. Attached Figure Description

[0085] Figure 1 This is a schematic diagram of the process of the present invention. Detailed Implementation

[0086] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0087] Example, refer to Figure 1 A method for spectral detection of pet food, comprising:

[0088] Within the preset minimum and maximum scanning wavelength range, the sample is spectrally sampled at equal intervals, and the dark current signal measured by the spectrometer under dark field conditions and the reference reflectance intensity measured after placing a standard white plate are calibrated.

[0089] The obtained corrected reflectance signal is subjected to a natural logarithmic transform to obtain a logarithmic domain spectral signal.

[0090] The wavelength range of the logarithmic domain signal is divided into several equally spaced intervals. The endpoints of each interval are used as spline node positions, and corresponding linear spline basis functions are constructed based on each node position.

[0091] The adaptive regularization coefficient is calculated based on the ratio of the total energy of the logarithmic domain spectral signal to the total energy of the linear spline basis function;

[0092] A system of linear equations is constructed based on the inner product relationship between the linear spline basis functions and the logarithmic domain signal, and the spline coefficients are obtained by solving the Gaussian elimination method.

[0093] The original spectral signal is reconstructed using spline coefficients and the residuals between the reconstructed signal and the original signal at each wavelength are calculated to construct the evaluation total residual norm.

[0094] For multiple verified qualified pet food samples, the corresponding spline coefficients were obtained, and the mean and standard deviation of each coefficient were calculated based on the spline coefficients to establish a qualified sample reference model.

[0095] The spline coefficients of the sample to be tested are obtained, and the Euclidean distance between them and the average value of the reference model is calculated. The distance is then compared with the judgment threshold to determine the qualification of the sample to be tested. Finally, a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result is generated.

[0096] By performing spectral sampling of samples at equal intervals within the preset minimum and maximum scanning wavelength ranges, combined with dark-field and standard white-plate calibration, the interference problems caused by instrument background noise and ambient light variations were resolved, ensuring the accuracy and consistency of the original data. By performing natural logarithmic mapping on the corrected reflectivity signal, the problem of weak features being masked by excessive signal dynamic range was solved, allowing weak absorption peaks to be presented in a balanced manner. By dividing the logarithmic domain signal into several equally spaced intervals and constructing linear spline basis functions, the technical bottleneck of oscillation and overfitting in global polynomial fitting was overcome, enhancing the response capability to local features in different bands. By calculating the adaptive regularization coefficient based on the ratio of the total signal energy to the total basis function energy, the problem of fixed regularization intensity failing to balance accuracy and stability was solved, achieving dynamic adjustment of the regularization intensity. By constructing an augmented matrix and using Gaussian elimination to solve for spline coefficients, the problems of slow convergence and susceptibility to local minima in iterative optimization are solved, improving the stability and traceability of coefficient solutions. By weighted reconstruction of the original spectral signal and calculation of the full-spectrum residual norm, the shortcomings of focusing only on local peak differences while ignoring the overall fitting error are addressed, providing an objective quantitative indicator for evaluating fitting accuracy. By obtaining spline coefficients from multiple verified qualified samples and statistically analyzing their mean and standard deviation to establish a reference model, the problem of unquantifiable inter-sample differences caused by judgment based on a single sample or empirical threshold is solved, significantly improving the model's universality and reliability. By measuring the distance between the coefficients of the sample to be tested and the reference model and comparing it with the judgment threshold, the problems of strong subjectivity and difficulty in traceability of traditional manual thresholds are solved, achieving automation of the detection process and traceability of results.

[0097] Within a preset range of minimum and maximum scanning wavelengths, the sample is spectrally sampled at equal intervals, and the dark current signal measured by the spectrometer under dark field conditions and the reference reflectance intensity measured after placing a standard white plate are calibrated. Specifically, this includes:

[0098] Set the spectral scanning range to [λ] min ,λ max The sampling interval is Δλ; where λ minλ is the minimum scanning wavelength. max Maximum scanning wavelength;

[0099] Calculate the total number of sampling points

[0100] Calculate the i-th sampling wavelength λ i =λ min +(i-1)Δλ, i = {1,2,...N}; where i is the sampling index;

[0101] Determine the number and location of discrete sampling points in the spectrum to ensure coverage of the required band and meet resolution requirements;

[0102] Under conditions of no sample and with the light source off, the dark current D at the i-th wavelength was measured and recorded sequentially using the built-in photodiode array sensor of the spectrometer. i ; Measure and correct the instrument's background noise, and remove interference from non-sample signals;

[0103] Place a standard white board with a reflectivity of ≈1, turn on the light source, and use a photoelectric sensor to measure and record the reference intensity R at the i-th wavelength. i Obtain the full-scale reference signal for subsequent reflectivity normalization.

[0104] A uniformly pulverized pet food sample was placed in the sample chamber. After turning on the light source, the original intensity was collected and recorded using a photoelectric sensor. Collect the raw light intensity data of the sample to be tested for subsequent calibration;

[0105] Calculate the corrected reflectance at point i. The raw readings are converted into dimensionless reflectance to eliminate the influence of instruments and the environment.

[0106] By sequentially measuring the dark-field current under conditions of no sample and with the light source off, the technical challenge of instrument-specific electronic noise masking weak signals was solved, ensuring a stable baseline for subsequent signals. By placing a standard white plate with approximately one reflectance and measuring the reference intensity at each wavelength after turning on the light source, measurement drift caused by light source intensity fluctuations and detector nonlinear response was resolved, obtaining a reliable normalized reference. By placing a uniformly pulverized pet food sample in the sample chamber and collecting the original light intensity, the influence of sample surface inhomogeneity and sample morphology differences on optical path transmission was addressed, ensuring the representativeness of the spectral data. By comparing the original intensity with the reference signal and calculating the dimensionless reflectance, the problems of dimensional inconsistencies and inter-instrument differences caused by variations in experimental conditions were resolved. The resulting reflectance signal not only eliminated the influence of environmental and hardware factors but also possessed high repeatability and comparability.

[0107] The step of performing a natural logarithmic transform on the obtained corrected reflectivity signal specifically includes:

[0108] Reflectance I after correction at point i i Perform a logarithmic transformation to obtain the logarithmic domain signal S at point i. i Specifically:

[0109] S i =ln(1+I) i );

[0110] Compress the dynamic range, enhance weak spectral features, and improve the stability of subsequent fitting.

[0111] By applying a natural logarithmic transformation to the obtained corrected reflectance signal, the problem of excessively large dynamic range in the original reflectance signal, leading to high-intensity regions dominating the fitting and neglecting low-intensity features, is solved, thus constructing a more balanced numerical distribution. This transformation effectively compresses signal intensity differences, enabling subsequent fitting methods to simultaneously focus on peak absorption and weak absorption bands, thereby improving the extraction capability of all spectral features. Simultaneously, the natural logarithmic mapping significantly improves numerical stability, reducing the risk of numerical overflow or distortion caused by large signal regions during algorithm iteration and matrix solving. Furthermore, this step, combined with subsequent local spline fitting, ensures an accurate description of the entire spectrum and provides preprocessing guarantees for adaptive regularization and coefficient solving. This logarithmic transformation not only reduces the difficulty of signal processing but also enhances the discriminability of weak features, laying the foundation for improving overall detection accuracy and sensitivity.

[0112] The process of dividing the wavelength range of the logarithmic domain signal into several equally spaced intervals, using the endpoints of each interval as spline node positions, and constructing corresponding linear spline basis functions based on each node position specifically includes:

[0113] Calculate the total number of spline nodes The number of nodes is adaptively selected based on the data size to balance fitting accuracy and computational complexity;

[0114] Set the wavelength of the k-th spline node to...

[0115] Where k = {1,...,K} is the spline node index;

[0116] Set the bandwidth between nodes to equal spacing.

[0117] Nodes are arranged at equal intervals across the entire wavelength band to determine the influence range of each spline base.

[0118] Constructing linear spline basis functions: Among them, the function max(a,b) returns the larger of a and b; |*| is the absolute value function; B i,k For wavelength λi Find the k-th basis function value; construct piecewise linear basis functions to provide local fitting units for signal decomposition.

[0119] By dividing the entire wavelength range of the natural logarithm domain signal into several equally spaced intervals and setting spline nodes at the endpoints of these intervals, the problem of oscillations and local fitting inaccuracies in high-order global polynomial fitting is solved. Furthermore, by constructing local linear spline basis functions within each interval, the problem of the global model failing to account for significant differences in the morphological characteristics of different spectral bands is addressed, achieving a fine response to minute changes in each band. This segmented construction method not only accurately captures local spectral details, such as the peak shape and half-maximum width of absorption peaks, but also significantly reduces the computational complexity of fitting and avoids overfitting. Simultaneously, this step provides a controllable set of basis functions for subsequent adaptive regularization based on energy ratios and the solution of linear equations, making the overall fitting highly interpretable, easy to implement and accelerate with hardware, thus improving algorithm efficiency and stability.

[0120] The calculation of the adaptive regularization coefficient based on the ratio of the total energy of the logarithmic domain spectral signal to the total energy of the linear spline basis function specifically includes:

[0121] Statistical logarithmic signal energy Measure the overall signal strength to provide data-driven parameters for regularization;

[0122] Calculate the sum of the basis function energies The total "energy" of the basis function set is measured and adjusted in conjunction with the signal energy to improve smoothness.

[0123] Set the adaptive regularization coefficient to Adaptive balancing of data fitting and basis function smoothing avoids overfitting or underfitting.

[0124] By statistically analyzing the total energy of the natural logarithm domain signal and calculating the sum of the energies of all spline basis functions, this approach addresses the problem that traditional fixed or empirical regularization coefficients cannot simultaneously account for different signal intensities and basis function characteristics. Furthermore, by using the ratio of these two factors as the basis for calculating the adaptive regularization coefficient, it solves the technical challenges of overfitting under weak signal or high noise conditions, and underfitting under high signal strength. The adaptive regularization coefficient automatically adjusts the regularization intensity based on the true energy distribution of the current signal and the basis function set, thus suppressing noise amplification while maintaining fitting accuracy. This not only improves the algorithm's stability under various sample conditions but also significantly reduces the workload of manual parameter tuning and the influence of subjective factors, thereby significantly enhancing the model's generalization ability and batch processing consistency.

[0125] The process of constructing a system of linear equations based on the inner product relationship between the linear spline basis functions and the logarithmic domain signal, and then solving for the spline coefficients using Gaussian elimination, specifically includes:

[0126] Construct the coefficient matrix

[0127] in, M is the set of real matrices with K rows and K columns; k,l The elements of the coefficient matrix are k,l = {1,2,...,K}, δ k,l For Kroneck δ, δ is true if and only if k = l. k,l =1, otherwise δ k,l =0; l is the matrix column index;

[0128] Construct a constant vector Among them, b k Elements of a constant vector; It is a set of real column vectors of length K;

[0129] The fitting problem is transformed into a system of linear equations, where matrix M and vector b represent the inner product of basis functions and the signal projection, respectively.

[0130] Constructing augmented matrices Where | indicates that b is added as an augmenting column after M; It is a set of real number matrices with K rows and K+1 columns; it facilitates the application of Gaussian elimination to simultaneously process the coefficient matrix and the constant term;

[0131] Perform the following steps to eliminate rows of p from 1 to K-1:

[0132] S110, Subject: E p,p ≠0; where p is the pivoting step index of Gaussian elimination;

[0133] S120. For each row e = {p+1,...K}, perform the following steps:

[0134] S121, Elimination Factor:

[0135] S122, Update all columns v = {p,...,K+1} in this row: E e,v ←E e,v -f e,p E p,v ;

[0136] Eliminate the lower triangular elements row by row to transform the matrix into an upper triangular form;

[0137] Let the Kth unknown be...

[0138] Let the k-th unknown be... Where k = {K-1,...,1};

[0139] Starting from the last row, calculate backwards to obtain all spline basis coefficients w. k ;

[0140] Constructing spline basis coefficient vectors Among them, each w k The linear coefficients corresponding to the k-th basis function.

[0141] By constructing a system of linear equations from the inner product of local linear spline basis functions and the logarithmic domain signal, the technical path of transforming signal decomposition into a linear solution problem is solved. The step of applying an augmented matrix and using Gaussian elimination to solve all spline coefficients in one go overcomes the drawbacks of slow convergence and potential local minima in iterative optimization. This direct solution method exhibits high determinism and traceability, achieving stable and accurate coefficient results even under finite precision conditions. Furthermore, this step simplifies the computation process, facilitating parallelization or hardware acceleration, significantly reducing computation time and improving solution accuracy. It provides a reliable parameter basis for subsequent spectral reconstruction, ensuring high-fidelity reproduction of sample spectral features by the detection system.

[0142] The process of using spline coefficients to perform weighted reconstruction of the original spectral signal and calculating the residuals between the reconstructed signal and the original signal at each wavelength point to construct an evaluation total residual norm specifically includes:

[0143] Reconstructed signal in, Let be the reconstructed signal at point i; reorganize the basis functions and coefficients to obtain the best linear approximation of the original signal;

[0144] Calculate the residual at point i.

[0145] Construct the total residual norm

[0146] To assess reconstruction accuracy, the residual norm r is a global quantification of the fitting error.

[0147] By applying a reconstruction step consisting of a weighted combination of spline basis functions and solved coefficients to the original spectral signal, the problem of not being able to directly compare the fitting effect is solved. By calculating the residuals between the reconstructed signal and the actual observed signal point by point and summing them into the total residual norm, the shortcomings of traditional methods that only focus on local peak differences or the overall correlation coefficient evaluation are not comprehensive are addressed. The total residual norm provides a quantitative indicator of the cumulative error across the entire spectrum, which can reflect both the overall fitting quality and reveal local fitting deficiencies, providing an accurate basis for algorithm optimization and anomaly diagnosis. This evaluation mechanism takes into account the accuracy requirements at both the local and global levels, enabling the detection system to provide timely feedback on different types of signal distortion or noise causes, thereby improving the interpretability and robustness of the results.

[0148] The process involves obtaining corresponding spline coefficients from multiple verified and qualified pet food samples, calculating the mean and standard deviation of each coefficient based on the spline coefficients, and establishing a reference model for qualified samples. Specifically, this includes:

[0149] For J verified qualified samples, obtain the spline basis coefficient vector w respectively. (j) , j={1,...,J}; where j is the index of qualified samples; obtain the characteristic coefficients of multiple known qualified samples for statistical analysis;

[0150] Calculate the reference mean of the k-th base coefficient: Establish a central model of qualified samples as a criterion for judgment;

[0151] Calculate the Euclidean distance between the coefficients and the mean of the j-th reference sample. Measure the degree of deviation of each reference sample from the mean model;

[0152] Calculate the average distance

[0153] Calculate the standard deviation of distance

[0154] Calculate the average deviation and fluctuation range to provide a statistical basis for threshold setting.

[0155] By extracting spline coefficients from multiple verified and qualified pet food samples and summing them into a coefficient vector, the problem of single samples or empirical thresholds being unable to cover the differences in the sample population is solved. By calculating the mean and standard deviation of each coefficient and establishing a central model and fluctuation range, the technical pain point of not being able to quantify the natural variability between samples is addressed. This statistical reference model can reflect the typical characteristics of the sample population and define a reasonable tolerance range, providing a scientific basis for determining the threshold. This model significantly improves the adaptability of the detection algorithm to samples with different formulas and different production batches, reduces the risk of false positives and false negatives, and significantly enhances the versatility and reliability of the system.

[0156] The process involves obtaining the spline coefficients of the sample to be tested, calculating the Euclidean distance between them and the average value of the reference model, comparing this distance with the judgment threshold to determine the pass / fail status of the sample, and finally generating a test report containing the total residual norm, Euclidean distance, judgment threshold, and judgment result. Specifically, this includes:

[0157] Obtain the coefficient vector w of the sample to be tested (new) ;

[0158] Calculate the coefficient space distance with the reference model Evaluate the difference between the feature coefficients of the test sample and the reference model;

[0159] Set the judgment threshold to T = μ + 3σ; based on the three-σ principle of normal distribution, set the pass / fail threshold;

[0160] Construct a pass / fail judgment function

[0161] If Result = 1, then the sample to be tested is deemed qualified.

[0162] If Result = 0, the sample to be tested is deemed unqualified.

[0163] To form objective and consistent quality judgment conclusions;

[0164] Output the total residual norm r and the coefficient spatial distance d. new It provides a comprehensive set of detection indicators and final judgments, including the judgment threshold T and judgment results, to facilitate user decision-making and archiving.

[0165] By obtaining the spline coefficients of the test sample and measuring the distance with the central features of the reference model, the problem of difficulty in quantifying the difference between the sample and the pass / fail standard is solved. By comparing the measurement results with the pre-statistically derived judgment threshold, the problem of subjective threshold setting easily introducing bias is solved. By automatically generating a test report containing the residual norm, distance index, threshold, and final judgment result, the problems of incomplete test result recording and errors in manual summarization are solved. This process realizes a fully automated closed loop from feature extraction to decision output, which not only improves the test efficiency but also ensures the consistency and traceability of the results, providing a reliable basis for quality management and subsequent auditing.

[0166] This embodiment also provides an apparatus for a spectral detection method for pet food, comprising:

[0167] Wavelength sampling and calibration unit: used for wavelength sampling and instrument calibration;

[0168] Signal mapping unit: used for logarithmic signal mapping;

[0169] Spline node and basis function construction unit: used for selecting spline nodes and constructing basis functions;

[0170] Adaptive regularization coefficient calculation unit: used for adaptive regularization coefficient calculation;

[0171] Coefficient matrix construction and solution unit: used for coefficient matrix construction and Gaussian elimination solution;

[0172] Spectral Reconstruction and Residual Evaluation Unit: Used for spectral reconstruction and residual evaluation;

[0173] Reference model building unit: used for building reference models for qualified samples;

[0174] Judgment and Report Output Unit: Used for judging and reporting new samples.

[0175] By dividing the steps of the method into several functional units and integrating them on the same device platform, the problems of data transmission delay and compatibility differences that exist when each algorithm module is deployed separately in practical applications are solved. Through unit-based design steps such as signal mapping, basis function construction, adaptive regularization calculation, and augmented matrix solution, the problems of high system complexity and difficulty in maintenance when multiple functions are coupled are solved. Through modular interfaces and unified control logic, the problem of overall transformation required when upgrading or replacing algorithms is solved, and hardware and software decoupling is achieved. This device can realize the integrated operation of the entire process from data acquisition, preprocessing, fitting analysis to decision output, which significantly improves the integration, stability and maintenance convenience of the detection system, and provides reliable support for industrial deployment and large-scale promotion.

[0176] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0177] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method of spectral detection of pet food, characterized in that, The method comprises the following steps: Within the preset minimum and maximum scanning wavelength range, the sample is spectrally sampled at equal intervals, and the dark current signal measured by the spectrometer under dark field conditions and the reference reflection intensity measured after placing a standard white board are calibrated; The obtained corrected reflectance signal is subjected to natural logarithmic transformation to obtain a logarithmic domain spectrum signal; The wavelength range of the logarithmic domain signal is divided into several equal interval ranges, the end points of each interval range are taken as spline node positions, and corresponding linear spline basis functions are constructed based on the node positions, specifically including: calculating the total number of spline nodes ; The first spline node wavelength is ; wherein is an index of the spline node; Setting the inter-node equidistant bandwidth as ; Constructing linear spline basis functions: ; where the function returns the greater of ; and is an absolute value function; is the value of the th basis function at the wavelength An adaptive regularization coefficient is calculated based on the ratio of the total energy of the logarithmic domain spectrum signal to the total energy of the linear spline basis function, specifically including: Statistical log signal energy ; Computing the energy sum of basis functions ; Setting the adaptive regularization coefficient as ; A linear equation set is constructed according to the inner product relationship between the linear spline basis function and the logarithmic domain signal, and the spline coefficient is obtained by solving the linear equation set through the Gaussian elimination method; The original spectrum signal is weighted and reconstructed by using the spline coefficient, and the residual error of the reconstructed signal and the original signal at each wavelength point is calculated to construct an evaluation total residual error norm; The spline coefficients of a plurality of verified qualified pet food samples are obtained, and the average value and the standard deviation of each coefficient are calculated based on the spline coefficients to establish a qualified sample reference model; The spline coefficient of the to-be-tested sample is obtained, the Euclidean distance between the spline coefficient and the average value of the reference model is calculated, and the qualified property of the to-be-tested sample is determined by comparing the Euclidean distance with a determination threshold, and finally a detection report containing the total residual error norm, the Euclidean distance, the determination threshold and the determination result is generated.

2. The method of claim 1, wherein the pet food is a dry pet food. The wavelength sampling and calibration unit is configured to perform wavelength sampling and instrument calibration. The spectral scanning range is set as , and the sampling interval is ; wherein, is the minimum scanning wavelength; is the maximum scanning wavelength; counting total sampling points ; Compute the sampled wavelengths , ; where, is the sample index; In the absence of sample and with the light source turned off, the dark current at the first and second wavelengths is measured and recorded sequentially using the spectrometer's built-in photodiode array sensor ; Place a standard white board with reflectivity ~ 1, turn on the light source, and use the photoelectric sensor to measure and record the first Wavelength reference intensity ; The pulverized pet food sample is placed in the sample chamber, and the original intensity is collected and recorded by the photoelectric sensor after the light source is turned on ; The computer calculates the Point corrected reflectance .

3. The method of claim 2, wherein the pet food is a dry pet food. The signal mapping unit is configured to perform logarithmic signal mapping. After the point correction, the reflectivity is Point correction reflectivity After logarithmic transformation, the first Point logarithmic domain signal , Specifically: 。 4. The pet food spectral detection method of claim 3, wherein, The spline node and basis function construction unit is configured to select spline nodes and construct basis functions. Constructing a coefficient matrix : ; wherein is a row, a column of a real matrix; is an element of the coefficient matrix; , is the Kronecker product, if and only if , , otherwise ; is a matrix row index; constitute a constant vector : ; wherein is an element of the constant vector; is a set of real number column vectors of length ; Constructing an augmented matrix , ; wherein, represents adding as an augmented column to after; is a set of real matrices of rows, columns. The following steps are performed, for from 1 to Perform row reduction: S110, pivot: ; wherein, is a Gaussian elimination pivot step index; S120, for each row performing the following steps: S121, Elimination Factor: ; S122, update all columns of the row : ; Setting the first unknown to ; Let the unknowns be ; where ; constructing a spline basis coefficient vector ; wherein each linear coefficient corresponding to the th basis function.

5. The method of claim 4, wherein the pet food is a dry pet food. The adaptive regularization coefficient calculation unit is configured to calculate an adaptive regularization coefficient. reconstructed signal ; wherein is the reconstructed nth point signal; calculating the first point residual ; Constructing total residual norm .

6. The pet food spectral detection method of claim 5, wherein, The coefficient matrix construction and solving unit is configured to construct a coefficient matrix and solve the coefficient matrix by the Gaussian elimination method. For The spline base coefficient vector is obtained from the verified qualified sample , ; wherein is the qualified sample index; Computing the reference mean value of the first base coefficients: ; computing the first Euclidean distance of the portion of the reference sample coefficients from the mean ; Calculate average distance ; Computing distance standard deviation .

7. The method of claim 6, wherein the pet food is a dry pet food. The spectrum reconstruction and residual error evaluation unit is configured to reconstruct a spectrum and evaluate a residual error. obtaining a vector of sample coefficients to be tested ; Computing a coefficient space distance to a reference model ; The determination threshold is set to ; Constructing a qualification decision function ; If then the sample under test is determined to be acceptable; If then the sample under test is determined to be non-conforming; output total residual norm , coefficient space distance , decision threshold and decision result.

8. A device for the spectroscopic detection of pet food according to claim 7, characterized in that ​ ​ ​ ​ ​ ​ ​ Reference model establishing unit: for qualified sample reference model establishing; Determination and report output unit: for new sample determination and report output.

Citation Information

Patent Citations

  • Non-destructive inspection method of total amount of meat bacteria

    CN101806703A

  • Rapid detection method for fatty acid content of Beijing duck based on near infrared spectrum technology

    CN119643501A