Pet food spectrum detection device and detection method

Through the spectral detection method of dark field and standard white plate calibration, logarithmic mapping, local linear spline basis function decomposition and adaptive regularization, the problems of unstable instrument calibration and tedious model parameter tuning in pet food spectral detection are solved, and efficient and reliable spectral signal processing and automated judgment are achieved.

CN120668594AActive Publication Date: 2025-09-19BRITISH TESTING TECH (FOSHAN) CO LTD

Patent Information

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

AI Technical Summary

Technical Problem

Existing pet food spectral detection technology has problems such as unstable instrument calibration, excessive signal dynamic range, cumbersome model parameter tuning, lack of adaptability of judgment thresholds and high misjudgment rate, making it difficult to achieve automated and batch testing.

Method used

Through dark field and standard white board calibration, logarithmic mapping, local linear spline basis function decomposition, adaptive regularization and Gaussian elimination method, combined with statistical reference model, automatic processing and judgment of spectral signals are achieved.

Benefits of technology

It improves detection consistency and sensitivity, enhances the recognition of weak spectral features, reduces noise interference, ensures calculation stability and model versatility, and generates traceable detection reports.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120668594A_ABST
    Figure CN120668594A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of pet food spectrum detection, and discloses a pet food spectrum detection device and a detection method. Sampling at equal intervals in a preset wavelength range, and eliminating noise interference through dark current and standard whiteboard calibration; taking a natural logarithm of the reflectivity to balance a dynamic range; constructing a linear spline basis in an equidistant and segmented manner, and adaptively calculating a regularization coefficient according to the energy ratio of the signal to the basis function; constructing an augmented matrix according to a basis function and a signal inner product, and solving a spline coefficient through Gaussian elimination; reconstructing a spectrum by using the coefficient and quantifying a residual error; establishing a reference model based on the coefficient mean value and the standard deviation of the multiple qualified samples; comparing the Euclidean distance between the to-be-detected sample coefficient and the model mean value with a threshold value, and generating a residual error, a distance, a threshold value and a judgment report; empirical parameters or manual adjustment and optimization are not needed in the whole process, online adaptive detection in batches can be achieved, and noise correction, feature enhancement, over-fitting suppression and traceable rapid and accurate detection are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of pet food spectral detection, and in particular to a pet food spectral detection device and detection method. Background Art

[0002] Pet food is a vital source of nutrition and health for pets. The quality of its ingredients directly impacts their growth, immune function, and digestion and absorption abilities. With the rapid growth of the pet consumer market, the requirements for pet food quality control are constantly increasing. Spectral detection technology, due to its non-destructive, rapid, and online monitoring capabilities, is becoming an increasingly important tool for food safety testing.

[0003] First, common spectrometer calibration methods rely on manually set thresholds or empirical parameters. Traditionally, dark current is measured manually with the light source off, along with a reference signal measured on a standard whiteboard. Reflectance is then calculated 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, resulting in unstable calibrated reflectance. This empirical calibration method struggles to meet consistency requirements across sample batches and 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 approach fails to effectively compress the signal dynamic range and cannot highlight the weak signatures of trace components in the spectral curve. In complex pet food matrices, absorption peaks of major components such as protein, fat, and vitamins, as well as various additives, often overlap or obscure each other. Simple preprocessing makes it difficult to extract the weak spectral features necessary for quality assessment. Third, for spectral signal modeling and decomposition, most literature utilizes 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 adjust the regularization parameters to balance the fitting accuracy and spectral smoothness. Since the model parameters are closely related to the sample type and sampling conditions, each application requires repeating the tedious parameter tuning process, making it difficult to achieve automation and batch testing. In addition, when determining the eligibility of samples, existing technologies generally adopt statistical methods such as peak comparison or principal component analysis (PCA). PCA relies on a large amount of data from existing qualified samples and a pre-trained model, and lacks the ability to adapt to the judgment threshold setting for new samples; peak comparison is easily affected by spectral drift and matrix effects, resulting in a high misjudgment rate. In addition, these methods often only give "pass / fail" results, but cannot provide intuitive visual indicators such as residuals and distances, which is not conducive to the continuous improvement and traceability management of the quality control process.

[0004] To this end, this case aims to propose a pet food spectral detection device and detection method. First, the original signal is calibrated with dark field and standard whiteboard to eliminate instrument and environmental influences, and 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 fitting accuracy and stability. The spline coefficients are then 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 of the sample to be tested 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] The present invention provides a pet food spectral detection device and detection method, which facilitate solving the problems mentioned in the above background technology.

[0006] The present invention provides the following technical solution: a pet food spectral detection method, comprising:

[0007] Within the preset minimum scanning wavelength and maximum scanning wavelength range, the sample spectrum is 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 plate are calibrated;

[0008] Performing natural logarithm transformation on the obtained corrected reflectance signal 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 the spline node positions, and the corresponding linear spline basis functions are constructed based on the node positions;

[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 linear equation system is constructed according to the inner product relationship between the linear spline basis function and the logarithmic domain signal, and the spline coefficients are obtained by solving them using the Gaussian elimination method;

[0012] The original spectral signal is weighted reconstructed using the spline coefficients, and the residual between the reconstructed signal and the original signal at each wavelength point is calculated to construct the total residual norm for evaluation;

[0013] Obtain corresponding spline coefficients for multiple verified qualified pet food samples, calculate the mean and standard deviation of each coefficient based on the spline coefficients, and establish a qualified sample reference model;

[0014] Obtain the spline coefficient of the sample to be tested, calculate the Euclidean distance between it and the average value of the reference model, and compare it with the judgment threshold to judge the eligibility of the sample to be tested. Finally, generate a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result.

[0015] Optionally, the spectral sampling of the sample is performed at equal intervals within a preset minimum scanning wavelength and maximum scanning wavelength range, and the dark current signal measured by the spectrometer under dark field conditions and the reference reflection intensity measured after placing a standard white plate are calibrated, specifically including:

[0016] Set the spectrum scanning range to [λ min ,λ max ], the sampling interval is Δλ; where λ min is the minimum scanning wavelength; λ max is the 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] In the absence of a sample and with the light source turned off, the spectrometer's built-in photodiode array sensor is used to measure and record the dark current D at the i-th wavelength in sequence. i ;

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

[0021] Place the crushed pet food sample in the sample chamber, turn on the light source, and use the photoelectric sensor to collect and record the original intensity.

[0022] Calculate the corrected reflectivity of point i

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

[0024] The reflectivity after correction for point i is I i Perform logarithmic transformation to obtain the logarithmic domain signal S of the i-th point i , specifically:

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

[0026] Optionally, dividing the wavelength range of the logarithmic domain signal into a number of 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 kth spline node to

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

[0030] Set the bandwidth between nodes to be equally spaced

[0031] Construct 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 At wavelength λ i The kth basis function value at .

[0032] Optionally, 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, specifically including:

[0033] Statistical logarithmic signal energy

[0034] Calculate the sum of basis function energies

[0035] Set the adaptive regularization coefficient to

[0036] Optionally, constructing a linear equation system according to the inner product relationship between the linear spline basis function and the logarithmic domain signal, and solving the system by Gaussian elimination to obtain spline coefficients, specifically includes:

[0037] Construct coefficient matrix

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

[0039] Constructing a constant vector Among them, b k are the elements of the constant vector; is a set of real column vectors of length K;

[0040] Constructing augmented matrix Among them, | means adding b as an augmented column to M; is a set of real matrices with K rows and K+1 columns;

[0041] Perform the following steps to perform row elimination on p from 1 to K-1:

[0042] S110, Pivot: E p,p ≠0; where p is the Gaussian elimination pivot step index;

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

[0044] S121, Elimination Factor:

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

[0046] Set the Kth unknown to be

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

[0048] Construct spline basis coefficient vector Among them, each w k The linear coefficient corresponding to the kth basis function.

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

[0050] Reconstructing the signal in, is the reconstructed signal of point i;

[0051] Calculate the residual at point i

[0052] Constructing the total residual norm

[0053] Optionally, obtaining corresponding spline coefficients for a plurality of 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 (j) , j = {1,...,J}; where j is the qualified sample index;

[0055] Calculate the reference mean of the kth basis coefficient:

[0056] Calculate the Euclidean distance between the jth reference sample coefficient and the mean

[0057] Calculate the average distance

[0058] Calculate distance standard deviation

[0059] Optionally, the spline coefficient of the sample to be tested is obtained, the Euclidean distance between the spline coefficient and the average value of the reference model is calculated, and the Euclidean distance is compared with the judgment threshold to judge the eligibility of the sample to be tested, and finally a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result is generated, specifically including:

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

[0061] Calculate coefficient space distance to reference model

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

[0063] Constructing a qualified judgment function

[0064] If Result=1, the sample to be tested is determined to be qualified;

[0065] If Result=0, the sample to be tested is judged to be unqualified;

[0066] Output total residual norm r, coefficient space distance d new , determination threshold T and determination result.

[0067] A device 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 spline node selection and basis function construction;

[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 of qualified samples;

[0075] Judgment and report output unit: used for new sample judgment and report output.

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

[0077] 1. In the sampling and calibration stage, the dark field background signal is innovatively combined with the standard white plate signal, and the full spectrum of the unknown sample is scanned at fixed intervals to obtain a calibrated, dimensionless reflectance signal. Traditional technologies usually rely solely on white plate calibration, ignoring the masking of weak signals by the dark field background. This solution simultaneously obtains the dark field signal, effectively eliminating the instrument background noise and significantly improving the sensitivity to low-reflection features. In addition, by pre-calculating the distribution of sample sampling points, uniform coverage is ensured across the entire spectral range, which not only meets the resolution requirements but also avoids data redundancy. Compared with the existing simple scanning methods with fixed step size or manual adjustment, this solution can reduce noise interference and improve 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 maps it as a whole to the logarithmic domain for the first time, which 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, which is easily dominated by the high-intensity signal area and ignores the weak absorption peak; while the logarithmic mapping can smoothly narrow the signal gap between each segment, so that the subsequent basis function fitting stage has a more balanced focus on the low-intensity band. At the same time, the mapping also improves numerical stability and avoids numerical overflow or gradient imbalance problems that may occur during direct fitting. Compared with common polynomial fitting or direct Fourier transform, logarithmic processing is more in line with the physical characteristics of the absorption spectrum, providing a solid preprocessing method for accurately extracting fingerprint peaks.

[0079] 3. Based on the logarithmic domain signal, this solution constructs linear spline basis functions based on a preset equidistant node distribution, thereby achieving flexible decomposition of the entire spectral morphology. Compared with traditional global polynomial fitting, local spline basis functions can better capture subtle mutations and detailed features in different spectral bands, avoiding the overfitting or oscillation caused by high-order polynomials. At the same time, through the adaptive selection of the number of nodes, a dynamic balance is achieved between fitting accuracy and computational complexity, ensuring the accuracy of detail restoration without excessive waste of computing resources.

[0080] 4. After constructing the spline basis functions, this solution innovatively dynamically calculates an adaptive regularization coefficient based on the ratio of the overall signal energy to the basis function energy, balancing fitting accuracy and algorithm stability. Traditional regularization methods typically use fixed coefficients or empirically tuned parameters, which cannot account for differences in signal strength between samples. This solution, however, uses a data-driven approach to automatically adjust the regularization strength, avoiding feature loss caused by oversmoothing while also reducing noise amplification caused by overfitting.

[0081] 5. For the linear equations composed of spline basis functions and the inner product of logarithmic domain signals, this solution adopts a stable and efficient matrix elimination process to solve the coefficient vector, ensuring that the optimal local fitting weight can still be obtained under the condition of limited precision. In existing methods, iterative optimization or least squares solution is often used, which has the problems of slow convergence speed and easy to fall into local minima; however, through the row and column elimination strategy of augmented matrix, not only can the parameter solution be completed in one go, but it also has a high degree of certainty and traceability, which is convenient for engineering implementation and hardware acceleration. The benefit of this is that it significantly shortens the calculation time, improves the solution accuracy, and avoids the numerical drift that may occur in the iterative process, providing an accurate and reliable coefficient basis for subsequent spectral reconstruction.

[0082] 6. Using the spline coefficients solved above, this solution restores the original spectrum through weighted reconstruction, and calculates the full-spectrum residual norm between the reconstructed signal and the actual observed signal to quantify the fitting effect. Compared with the traditional evaluation method that only focuses on the local peak position difference or the overall correlation coefficient, the residual norm can provide a quantitative indicator of error accumulation in the entire band, which more intuitively reflects the degree to which the model restores the spectral details. This evaluation method takes into account both the local and the overall, and outputs it in the form of a one-dimensional scalar, which can be used as an important feature for subsequent quality judgment; at the same time, it retains the error distribution information, providing a clear basis for further model optimization or abnormality diagnosis. This method solves the pain point of the lack of a unified evaluation standard in the existing technology, and improves the scientificity and consistency of quality assessment.

[0083] 7. This solution extracts the spline coefficients of multiple verified pet food samples and, based on statistical principles, calculates the central tendency and fluctuation range of each coefficient to construct a reference model for qualified samples. Traditional spectral detection relies on single samples or empirical thresholds, lacking a quantitative understanding of the differences between sample groups. This solution, however, uses large-scale statistics to obtain more representative characteristic means and distribution ranges, fully accounting for the natural variability between samples. This not only improves the model's versatility in handling a variety of different 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 judgments.

[0084] 8. After the reference model is established, this solution measures the distance between the coefficient characteristics of the sample to be tested and the central characteristics of the reference model, and automatically determines whether it is qualified based on preset rules, and finally generates a complete report containing the residual norm, distance matrix measurement, threshold and judgment results. Compared with the traditional method of manually setting thresholds or judging based on simple similarity indicators, this solution reasonably sets the judgment boundary based on the principle of statistical distribution, making the qualification standard both scientific and rigorous as well as adjustable and controllable. Automated report generation not only improves detection efficiency, but also ensures the consistency and traceability of the output content, facilitates subsequent quality file management and audit tracking, and meets the dual needs of modern quality control for rapid response and traceability. BRIEF DESCRIPTION OF THE DRAWINGS

[0085] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0086] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0087] Example, see Figure 1 , a pet food spectral detection method, comprising:

[0088] Within the preset minimum scanning wavelength and maximum scanning wavelength range, the sample spectrum is 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 plate are calibrated;

[0089] Performing natural logarithm transformation on the obtained corrected reflectance signal 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 the spline node positions, and the corresponding linear spline basis functions are constructed based on the node positions;

[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 linear equation system is constructed according to the inner product relationship between the linear spline basis function and the logarithmic domain signal, and the spline coefficients are obtained by solving them using the Gaussian elimination method;

[0093] The original spectral signal is weighted reconstructed using the spline coefficients, and the residual between the reconstructed signal and the original signal at each wavelength point is calculated to construct the total residual norm for evaluation;

[0094] Obtain corresponding spline coefficients for multiple verified qualified pet food samples, calculate the mean and standard deviation of each coefficient based on the spline coefficients, and establish a qualified sample reference model;

[0095] Obtain the spline coefficient of the sample to be tested, calculate the Euclidean distance between it and the average value of the reference model, and compare it with the judgment threshold to judge the eligibility of the sample to be tested. Finally, generate a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result.

[0096] By sampling the spectrum of the sample at equal intervals within the preset minimum scanning wavelength and maximum scanning wavelength range and combining the dark field with the standard white plate calibration, the interference problem caused by the background noise of the instrument and the change of ambient light is solved, and the accuracy and consistency of the original data are guaranteed; by performing natural logarithmic mapping on the corrected reflectance signal, the problem of weak features being masked due to the excessive dynamic range of the signal is solved, and the weak absorption peak is presented in a balanced manner; by dividing the logarithmic domain signal into several equally spaced intervals and constructing a linear spline basis function, the technical bottleneck of oscillation and overfitting in global polynomial fitting is solved, and the response capability to local features of different bands is enhanced; by calculating the adaptive regularization coefficient based on the ratio of the total energy of the signal to the total energy of the basis function, the problem that the fixed regularization strength cannot take into account both accuracy and stability is solved, and the dynamic adjustment of the regularization strength is achieved; By constructing an augmented matrix and using Gaussian elimination to solve the spline coefficients, the problems of slow convergence of iterative optimization and easy falling into local minima are solved, and the stability and traceability of coefficient solution are improved; by weighted reconstruction of the original spectral signal and calculation of the full spectrum residual norm, the defect of only focusing on local peak differences and ignoring the overall fitting error is solved, and an objective quantitative indicator is provided for fitting accuracy evaluation; by obtaining spline coefficients from multiple verified qualified samples and calculating their average and standard deviations to establish a reference model, the problem of the inability to quantify the differences between samples caused by judging by a single sample or empirical threshold is solved, and the versatility and reliability of the model are significantly improved; by measuring the distance between the coefficients of the sample to be tested and the reference model and comparing them with the judgment threshold, the problem of strong subjectivity and difficulty in tracing of traditional manual thresholds is solved, and the automation of the detection process and the traceability of the results are achieved.

[0097] The method includes: sampling the spectrum of the sample at equal intervals within the preset minimum scanning wavelength and maximum scanning wavelength range, and calibrating the dark current signal measured by the spectrometer under dark field conditions and the reference reflection intensity measured after placing a standard white plate, specifically including:

[0098] Set the spectrum scanning range to [λ min ,λ max ], the sampling interval is Δλ; where λ minis the minimum scanning wavelength; λ max is the 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 of the spectrum to ensure coverage of the required band and meet resolution requirements;

[0102] In the absence of a sample and with the light source turned off, the spectrometer's built-in photodiode array sensor is used to measure and record the dark current D at the i-th wavelength in sequence. i ;Measure and correct the instrument background noise to remove non-sample signal interference;

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

[0104] Place the crushed pet food sample in the sample chamber, turn on the light source, and use the photoelectric sensor to collect and record the original intensity. Collect the original light intensity data of the sample to be tested for subsequent correction;

[0105] Calculate the corrected reflectivity of point i Convert raw readings to dimensionless reflectance, eliminating instrumental and environmental effects.

[0106] By measuring the dark-field current sequentially without a sample and with the light source turned off, the technical problem of the instrument's own electronic noise masking weak signals was solved, ensuring a stable baseline for subsequent signals. By placing a standard white board with a reflectivity approximately equal to one and measuring the reference intensity of each wavelength after turning on the light source, the measurement drift caused by light source intensity fluctuations and detector nonlinear response was solved, and a reliable normalized reference was obtained. By placing a uniformly crushed pet food sample in the sample chamber and collecting the original light intensity, the effects of sample surface unevenness and sample morphology differences on optical path transmission were solved, ensuring the representativeness of the spectral data. By comparing the original intensity with the reference signal and calculating the dimensionless reflectivity, the dimensional inconsistency and inter-instrument differences caused by changes in experimental conditions were solved. The reflectivity signal finally generated not only eliminates the influence of environmental and hardware factors, but also has a high degree of repeatability and comparability.

[0107] The performing a natural logarithm transformation on the obtained corrected reflectivity signal specifically includes:

[0108] The reflectivity after correction for point i is I i Perform logarithmic transformation to obtain the logarithmic domain signal S of the i-th point 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 performing a natural logarithmic transformation on the corrected reflectivity signal, the problem of the original reflectivity signal's excessive dynamic range, which causes high-intensity regions to dominate the fitting while ignoring low-intensity features, is resolved, resulting in a more balanced numerical distribution. This transformation effectively compresses signal intensity differences, enabling subsequent fitting methods to focus on both peak absorption and weak absorption bands, thereby improving the ability to extract all spectral features. Simultaneously, the natural logarithmic mapping significantly improves numerical stability, reducing the risk of numerical overflow or distortion caused by large-amplitude signal regions on algorithm iteration and matrix solution. 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 solution. This logarithmic transformation not only reduces the difficulty of signal processing but also enhances the distinguishability of weak features, laying the foundation for improving overall detection accuracy and sensitivity.

[0112] The method of dividing the wavelength range of the logarithmic domain signal into a number of equally spaced intervals, using the endpoints of each interval as the 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 Adaptively select the number of nodes based on the data scale to balance fitting accuracy and computational complexity;

[0114] Set the wavelength of the kth spline node to

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

[0116] Set the bandwidth between nodes to be equally spaced

[0117] Arrange nodes at equal intervals across the entire band to determine the influence range of each spline basis;

[0118] Construct 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 At wavelength λi The kth basis function value is found; a piecewise linear basis function is constructed to provide a local fitting unit 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 the intervals, the problem of high-order global polynomial fitting prone to oscillation and local fitting inaccuracy is solved; by constructing local linear spline basis functions in each interval, the problem of the global model being difficult to take into account when the characteristic morphologies of different bands in the spectrum are quite different is solved, and a fine response to slight changes in each band is achieved; this segmented construction method can not only accurately capture the local details of the spectrum, such as the peak shape and half-width of the absorption peak, but also significantly reduce the complexity of the fitting calculation and avoid overfitting; at the same time, this step provides a controllable set of basis functions for the subsequent energy ratio-based adaptive regularization and solution of the linear equation system, making the overall fitting highly interpretable and easy to implement and accelerate with hardware, thereby improving the efficiency and stability of the algorithm.

[0120] 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, specifically comprising:

[0121] Statistical logarithmic signal energy Measures the overall strength of the signal and provides data-driven regularization;

[0122] Calculate the sum of basis function energies Measure the total "energy" of the basis function set and adjust the smoothness in conjunction with the signal energy;

[0123] Set the adaptive regularization coefficient to Adaptively balance data fitting with basis function smoothing to avoid overfitting or underfitting.

[0124] By counting the total energy of the natural logarithm domain signal and calculating the sum of the energies of all spline basis functions, the problem that traditional fixed or empirical regularization coefficients cannot take into account different signal strengths and basis function characteristics is solved; by taking the ratio of the two as the basis for calculating the adaptive regularization coefficient, the technical difficulties that the algorithm is prone to overfitting under weak signal or high noise conditions, and underfitting when the signal strength is large are solved; the adaptive regularization coefficient can automatically adjust the regularization strength according to the true energy distribution of the current signal and the basis function set, thereby suppressing noise amplification while ensuring fitting accuracy; this not only improves the stability of the algorithm under various sample conditions, but also greatly reduces the workload of manual parameter adjustment and the influence of subjective factors, and significantly improves the model generalization ability and batch processing consistency.

[0125] The method of constructing a linear equation system according to the inner product relationship between the linear spline basis function and the logarithmic domain signal and solving the system by Gaussian elimination method to obtain the spline coefficients specifically includes:

[0126] Construct coefficient matrix

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

[0128] Constructing a constant vector Among them, b k are the elements of the constant vector; is a set of real column vectors of length K;

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

[0130] Constructing augmented matrix Among them, | means adding b as an augmented column to M; is a set of real matrices with K rows and K+1 columns; it is convenient to apply Gaussian elimination to process the coefficient matrix and constant terms simultaneously;

[0131] Perform the following steps to perform row elimination on p from 1 to K-1:

[0132] S110, Pivot: E p,p ≠0; where p is the Gaussian elimination pivot step index;

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

[0134] S121, Elimination Factor:

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

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

[0137] Set the Kth unknown to be

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

[0139] Calculate backward from the last row to get all the spline basis coefficients w k ;

[0140] Construct spline basis coefficient vector Among them, each w k The linear coefficient corresponding to the kth basis function.

[0141] By constructing the inner product results of local linear spline basis functions and logarithmic domain signals into a system of linear equations, the technical path of converting the signal decomposition problem into a linear solution problem is solved; by applying the augmented matrix and using Gaussian elimination method to solve all spline coefficients at one time, the defects of slow convergence speed of iterative optimization and the possibility of falling into local minima are solved; this direct solution method is highly deterministic and traceable, and can still obtain stable and accurate coefficient results under limited precision conditions; at the same time, this step simplifies the calculation process, facilitates parallelization or hardware acceleration, significantly shortens the calculation time and improves the solution accuracy, provides a reliable parameter basis for subsequent spectral reconstruction, and ensures the detection system to reproduce the sample spectral characteristics with high fidelity.

[0142] The weighted reconstruction of the original spectral signal using the spline coefficients, and the calculation of the residual between the reconstructed signal and the original signal at each wavelength point to construct the evaluation total residual norm specifically include:

[0143] Reconstructing the signal in, is the reconstructed signal at point i; reorganize the basis functions and coefficients to obtain the best linear approximation to the original signal;

[0144] Calculate the residual at point i

[0145] Constructing the total residual norm

[0146] To evaluate the 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 being unable to intuitively compare the fitting effects is solved; by calculating the residuals between the reconstructed signal and the actual observed signal at each wavelength point and summarizing them into the total residual norm, the defects of traditional evaluation that only focuses on local peak differences or the overall correlation coefficient are solved; the total residual norm provides a quantitative indicator of the accumulated errors of the entire spectrum, which can not only reflect the overall fitting quality, but also reveal local fitting deficiencies, providing an accurate basis for algorithm optimization and abnormality 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 method of obtaining corresponding spline coefficients for a plurality of qualified pet food samples, calculating the mean and standard deviation of each coefficient based on the spline coefficients, and establishing a qualified sample reference model specifically includes:

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

[0150] Calculate the reference mean of the kth basis coefficient: Establish a central model of qualified samples as a judgment benchmark;

[0151] Calculate the Euclidean distance between the jth reference sample coefficient and the mean Measure the degree of deviation of each reference sample from the mean model;

[0152] Calculate the average distance

[0153] Calculate distance standard deviation

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

[0155] By extracting spline coefficients from multiple verified pet food samples and summarizing them into coefficient vectors, the problem that a single sample or empirical threshold is difficult to cover the differences in the sample group is solved; by calculating the mean and standard deviation of each coefficient and establishing a central model and fluctuation range, the technical pain point that the natural variability between samples cannot be quantified is solved; this statistical reference model can not only reflect the typical characteristics of the sample group, but also define a reasonable tolerance interval, providing a scientific basis for determining the threshold; this model greatly improves the adaptability of the detection algorithm to samples with different formulas and different production batches, reduces the risk of misjudgment and missed judgment, and significantly enhances the versatility and reliability of the system.

[0156] The spline coefficient of the sample to be tested is obtained, the Euclidean distance between the spline coefficient and the average value of the reference model is calculated, and the Euclidean distance is compared with the judgment threshold to judge the eligibility of the sample to be tested. Finally, a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result is generated, which specifically includes:

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

[0158] Calculate coefficient space distance to reference model Evaluate the difference between the characteristic coefficients of the sample to be tested and the reference model;

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

[0160] Constructing a qualified judgment function

[0161] If Result=1, the sample to be tested is determined to be qualified;

[0162] If Result=0, the sample to be tested is judged to be unqualified;

[0163] Form objective and consistent quality judgment conclusions;

[0164] Output total residual norm r, coefficient space distance d new , judgment threshold T and judgment result; provide comprehensive detection indicators and final judgment to facilitate user decision-making and archiving.

[0165] By obtaining the spline coefficients of the sample to be tested and measuring the distance with the central feature of the reference model, the problem of difficulty in quantifying the difference between the sample and the qualified standard is solved; by comparing the measurement results with the judgment threshold obtained by pre-statistical means, the problem of bias easily introduced by subjective setting of the threshold is solved; by automatically generating a test report containing the residual norm, distance index, threshold and final judgment result, the problems of incomplete record of test results and error-prone manual summary are solved; this process realizes a fully automated closed loop from feature extraction to decision output, which not only improves the detection efficiency, but also ensures the consistency and traceability of the results, providing a reliable basis for quality management and subsequent audits.

[0166] This embodiment also provides a device for a pet food spectral detection method, 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 spline node selection and basis function construction;

[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 of qualified samples;

[0174] Judgment and report output unit: used for new sample judgment and report output.

[0175] By dividing each step of the method into several functional units and integrating them into the same device platform, the problems of data transmission delay and compatibility differences that exist when each algorithm module is deployed separately in actual application are solved; through the steps of unit design such as signal mapping, basis function construction, adaptive regularization calculation, and augmented matrix solution, the problem of high system complexity and difficulty in maintenance during multi-functional coupling is solved; through the steps of modular interface and unified control logic, the difficult problem of overall transformation required for subsequent upgrades or replacements of algorithms is solved, and the decoupling of hardware and software is achieved; the device can realize 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, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus.

[0177] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.

Claims

1. A pet food spectral detection method, characterized in that: include: Within the preset minimum scanning wavelength and maximum scanning wavelength range, the sample spectrum is 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 plate are calibrated; Performing natural logarithm transformation on the obtained corrected reflectance signal to obtain a logarithmic domain spectral signal; The wavelength range of the logarithmic domain signal is divided into several equally spaced intervals, the endpoints of each interval are used as the spline node positions, and the corresponding linear spline basis functions are constructed based on the node positions; 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; A linear equation system is constructed according to the inner product relationship between the linear spline basis function and the logarithmic domain signal, and the spline coefficients are obtained by solving them using the Gaussian elimination method; The original spectral signal is weighted reconstructed using the spline coefficients, and the residual between the reconstructed signal and the original signal at each wavelength point is calculated to construct the total residual norm for evaluation; Obtain corresponding spline coefficients for multiple verified qualified pet food samples, calculate the mean and standard deviation of each coefficient based on the spline coefficients, and establish a qualified sample reference model; Obtain the spline coefficient of the sample to be tested, calculate the Euclidean distance between it and the average value of the reference model, and compare it with the judgment threshold to judge the eligibility of the sample to be tested. Finally, generate a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result.

2. The pet food spectral detection method according to claim 1, characterized in that: The method includes: sampling the spectrum of the sample at equal intervals within the preset minimum scanning wavelength and maximum scanning wavelength range, and calibrating the dark current signal measured by the spectrometer under dark field conditions and the reference reflection intensity measured after placing a standard white plate, specifically including: Set the spectrum scanning range to [λ min ,λ max ], the sampling interval is Δλ; where λ min is the minimum scanning wavelength; λ max is the maximum scanning wavelength; Calculate the total number of sampling points Calculate the i-th sampling wavelength λ i =λ min +(i-1)Δλ, i={1,2,...N}; where i is the sampling index; In the absence of a sample and with the light source turned off, the spectrometer's built-in photodiode array sensor is used to measure and record the dark current D at the i-th wavelength in sequence. i ; Place a standard white plate with a reflectivity of ≈1, turn on the light source, and use a photoelectric sensor to measure and record the reference intensity R of the i-th wavelength. i ; Place the crushed pet food sample in the sample chamber, turn on the light source, and use the photoelectric sensor to collect and record the original intensity. Calculate the corrected reflectivity of point i 3. The pet food spectral detection method according to claim 2, characterized in that: The performing a natural logarithm transformation on the obtained corrected reflectivity signal specifically includes: The reflectivity after correction for point i is I i Perform logarithmic transformation to obtain the logarithmic domain signal S of the i-th point i , specifically: S i =ln(1+I i )。 4. The pet food spectral detection method according to claim 3, characterized in that: The method of dividing the wavelength range of the logarithmic domain signal into a number of equally spaced intervals, using the endpoints of each interval as the spline node positions, and constructing corresponding linear spline basis functions based on each node position specifically includes: Calculate the total number of spline nodes Set the wavelength of the kth spline node to Where k = {1,...,K}, is the spline node index; Set the bandwidth between nodes to be equally spaced Construct 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 At wavelength λ i The kth basis function value at .

5. The pet food spectral detection method according to claim 4, characterized in that: 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, specifically comprising: Statistical logarithmic signal energy Calculate the sum of basis function energies Set the adaptive regularization coefficient to 6. The pet food spectral detection method according to claim 5, characterized in that: The method of constructing a linear equation system according to the inner product relationship between the linear spline basis function and the logarithmic domain signal and solving the system by Gaussian elimination method to obtain the spline coefficients specifically includes: Construct coefficient matrix in, is a set of real matrices with K rows and K columns; M k,l are the elements of the coefficient matrix; k, l = {1, 2, ..., K}, δ k,l is Kronecker δ, if and only if k = l, δ k,l =1, otherwise δ k,l =0; l is the matrix column index; Constructing a constant vector Among them, b k are the elements of the constant vector; is a set of real column vectors of length K; Construct the augmented matrix E = [M|b], Among them, | means adding b as an augmented column to M; is a set of real matrices with K rows and K+1 columns; Perform the following steps to perform row elimination on p from 1 to K-1: S110, Pivot: E p,p ≠0; where p is the Gaussian elimination pivot step index; S120. For each row e={p+1,...K}, perform the following steps: S121, Elimination Factor: S122. Update all columns of this row v={p,...,K+1}:E e,v ←E e,v -f e,p E p,v ; Set the Kth unknown to be Let the kth unknown be Where k = {K-1,...,1}; Construct spline basis coefficient vector Among them, each w k The linear coefficient corresponding to the kth basis function.

7. The pet food spectral detection method according to claim 6, characterized in that: The weighted reconstruction of the original spectral signal using the spline coefficients, and the calculation of the residual between the reconstructed signal and the original signal at each wavelength point to construct the evaluation total residual norm specifically include: Reconstructing the signal in, is the reconstructed signal of point i; Calculate the residual at point i Constructing the total residual norm 8. The pet food spectral detection method according to claim 7, characterized in that: The method of obtaining corresponding spline coefficients for a plurality of qualified pet food samples, calculating the mean and standard deviation of each coefficient based on the spline coefficients, and establishing a qualified sample reference model specifically includes: For J verified qualified samples, obtain the spline basis coefficient vector w (j) , j = {1,...,J}; where j is the qualified sample index; Calculate the reference mean of the kth basis coefficient: Calculate the Euclidean distance between the jth reference sample coefficient and the mean Calculate the average distance Calculate distance standard deviation 9. The pet food spectral detection method according to claim 8, characterized in that: The spline coefficient of the sample to be tested is obtained, the Euclidean distance between the spline coefficient and the average value of the reference model is calculated, and the Euclidean distance is compared with the judgment threshold to judge the eligibility of the sample to be tested. Finally, a test report containing the total residual norm, Euclidean distance, judgment threshold and judgment result is generated, which specifically includes: Get the coefficient vector w of the sample to be tested (new) ; Calculate coefficient space distance to reference model Set the judgment threshold to T = μ + 3σ; Constructing a qualified judgment function If Result=1, the sample to be tested is determined to be qualified; If Result=0, the sample to be tested is judged to be unqualified; Output total residual norm r, coefficient space distance d new , determination threshold T and determination result.

10. A device using the pet food spectral detection method according to claim 9, characterized in that: include: Wavelength sampling and calibration unit: used for wavelength sampling and instrument calibration; Signal mapping unit: used for logarithmic signal mapping; Spline node and basis function construction unit: used for spline node selection and basis function construction; Adaptive regularization coefficient calculation unit: used for adaptive regularization coefficient calculation; Coefficient matrix construction and solution unit: used for coefficient matrix construction and Gaussian elimination solution; Spectral reconstruction and residual evaluation unit: used for spectral reconstruction and residual evaluation; Reference model building unit: used for building reference models of qualified samples; Judgment and report output unit: used for new sample judgment 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

  • Blueberry acidity detection method based on hyperspectral imaging

    CN119985342A

Cited By

  • Flower moisture determination system and method based on image data

    CN121877772A