Method for discovering respiratory diseases of group health-preserving pigs under condition of balanced feed nutrition
By combining TAVM-UNet and NMF, the overlapping cough sounds in group-housed pigs were effectively separated and reconstructed, solving the problem of noise interference in the group and enabling accurate monitoring and early warning of respiratory diseases in pigs, thus improving the practicality of automated monitoring.
Patent Information
- Application Number
- CN202511684551.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2026-02-10
AI Technical Summary
In group-housed environments, the coughing sounds of pigs are often mixed together. Existing technologies are unable to effectively separate and identify individual coughing sounds, resulting in inaccurate monitoring of respiratory diseases and the easy masking of early symptoms. There is also a lack of effective automated monitoring methods.
A method based on TAVM-UNet and NMF was adopted. The TAVM-UNet model was used to extract and separate the aliased cough sound spectrum, and the NMF algorithm was used to reconstruct the time domain waveform of a single cough sound, so as to realize the early monitoring of respiratory diseases in pigs.
It significantly improves the accuracy of disease surveillance and early warning capabilities, enhances the practicality of automated surveillance, enables the detection of disease early, and reduces the burden of manual inspections.
Smart Images

Figure CN121506200A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of pig sound technology in pig farming, and more specifically, relates to a method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition. Background Technology
[0002] Respiratory diseases are one of the main threats to the health of pigs. Manually identifying sick pigs is time-consuming and labor-intensive, impacting the effectiveness of herd health management. Therefore, using intelligent algorithms for real-time respiratory disease detection is one of the effective ways to improve pig health.
[0003] Currently, scholars both domestically and internationally have made some progress in the study of pig sounds. Song et al. embedded SENets attention into the DenseNets model, achieving an accuracy of 93.8% in recognizing pig cough sounds. Jie et al. proposed a domestic pig sound classification system based on TransformerCNN, extracting multiple audio features such as logmel spectrogram, MFCC, and CST, improving the model's recognition rate by approximately 2.23% compared to single-feature models. Yuan Guoqing et al. proposed a method for separating and recognizing pig cough audio; PANNS-CNN6 was used to recognize cough sounds separated by an improved UNet model, achieving a single cough sound recognition rate of over 90%.
[0004] Shen et al. proposed a method for recognizing pig cough sounds by integrating acoustic and deep features, with an accuracy rate of 97.35%; Shen Mingxia et al. proposed a method for recognizing pig sounds based on deep neural networks, extracting MFCC features of cough, sneezing, grunting and snoring sounds of Meishan pigs, with a model recognition rate of 96.71%.
[0005] In the area of blind source separation, Hassan et al. proposed a sparse component analysis method based on adaptive temporal thresholding. This method reduces noise interference by calculating the mean of the TF vector norm and using adaptive threshold sparse coding, and then recovers the source signal using the least squares method. Pan et al. proposed a method for reconstructing pig audio based on the L1 norm, estimating the mixing matrix using a hierarchical clustering algorithm, and achieving the separation of audio from up to five different pig states. Peng Shuo et al. proposed an underdetermined separation method for pig audio based on SCA, estimating the mixing matrix using the SVD-AP clustering algorithm. p The audio signal is reconstructed using the norm, and the optimal P value is selected to separate the signal.
[0006] Domestic and international research on pig sounds mainly focuses on audio recognition and blind source separation, and has not yet been extended to the extraction, separation, and reconstruction of mixed cough sounds from pigs in group rearing environments. Summary of the Invention
[0007] To address this, this invention proposes a method for separating and reconstructing overlapping cough sounds from multiple pigs based on TAVM-UNet and NMF. The TAVM-UNet model is used to extract overlapping cough sounds from multiple pigs, and then the NMF algorithm is applied to separate and reconstruct these overlapping cough sounds, obtaining each individual cough sound within the overlapping cough sounds. This enables effective monitoring and early warning of early respiratory diseases in pigs.
[0008] To achieve the above objectives, the present invention provides the following technical solution: A method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition includes the following steps: Step 1: Collect audio data of pigs in different states, convert the audio time-domain waveform into a Mel spectrogram, and obtain the Mel spectrogram of mixed audio data of group-raised pigs; Step 2: Input the mixed audio Mel spectrogram of group-raised pigs into the trained TAVM-UNet model to separate the mixed spectrogram of single pig cough / multiple pig cough. Step 3: Convert the Mel spectrogram of single-pig cough / multi-pig cough aliasing into a time-domain waveform of cough aliasing; Step 4: Use the NMF algorithm to separate the time-domain waveforms of the multiple pig coughs and reconstruct the time-domain waveforms of each cough sound in the multiple pig coughs.
[0009] A further optimization of this technical solution involves converting the time-domain waveform into a Mel spectrum, with the specific steps as follows: Step 1.1, Preprocessing: Resample, frame, and window the pig sounds using a Hamming window. Window function values for each sample for: (1) Where L is the frame length; Step 1.2, Short-Time Fourier Transform: Perform a short-time Fourier transform on each windowed signal frame to obtain the amplitude or power spectrum in the time-frequency domain. The short-time Fourier transform result of the m-th frame signal is shown below. for: (2) Where k is the frequency point index, corresponding to the frequency. The power spectrum can be obtained by squaring the amplitude spectrum. ; Step 1.3, Mel filter bank mapping: Convert the linear spectrum to the Mel spectrum, and construct a triangular filter bank using the triangular window function. Filters ( ) frequency response : (3) In the formula, Indicates the first STFT At each frequency point (Hz), the STFT power spectrum is multiplied by the Mel Filter Bank to obtain the Mel power spectrum: (4) Among them, Indicates the first Frame, First Energy in the Mel frequency band; Step 1.4, Nonlinear Correction: Take the logarithm of the Mel power spectrum from the previous step and perform logarithmic compression to obtain the Mel dB spectrum: (5) In the formula, To avoid numerical overflow.
[0010] Further optimization of this technical solution, the method for constructing the TAVM-UNet network model is as follows: TAVM-UNet network model The Patch Embedding layer divides the input spectrogram into 4×4 non-overlapping blocks and converts the number of channels to C to complete the initial encoding. The encoding layer performs spatial resolution downsampling, reducing the size and increasing the number of channels, and extracts features through VSS blocks. The decoding layer performs upsampling to restore the spectrogram size and reduce the number of channels. VSS blocks combined with skip connections gradually restore the audio features. The Final Projection layer uses 1×1 convolution operations to restore the features output by the decoding layer to the input size and number of channels, completing the audio reconstruction. As the core module of the VM-UNet network, each VSS block includes a linear layer, a 2D state space, layer normalization, depthwise convolution, and residual connections. A temporal attention mechanism is embedded after the Linear Layer and before Dw-Conv in the VSS block. Temporal weights are generated through temporal attention to enhance the network's ability to extract cross-frame features of cough audio segments. The temporal attention module takes a feature audio spectrogram as input, where T is the number of frames, B is the batch size, C is the number of channels, and H and W are the spatial dimensions. The temporal attention unit recombines time and channels, and in TAU, it is processed in parallel by intra-frame static attention and inter-frame dynamic attention. Intra-frame static attention is achieved by performing convolution operations on each channel independently using DW Conv and depth-dilated convolutions: (6) in, Let c be the convolution kernel parameters for the c-th channel. Let the element value of the c-th channel of the input feature map be at position (i+m,j+n). (7) In the formula, Let d be the convolution kernel parameter and d be the dilation rate. Then, perform a 1×1 convolution operation on the channels in each time period to obtain a tensor S with dimensions T×C×S×W. Perform global average pooling on each time frame to extract global channels: (8) In the formula, F t For the feature map in frame t The element values, h and w are the height and width of the feature map, obtained by global average pooling. Input to the fully connected layer to generate inter-frame channel weight vectors : (9) In the formula For the parameter matrix, It is the ReLU activation function. Using the sigmoid activation function, the attention weight tensor D can be obtained by accumulating the channel weights of all frames: (10) in, The channel weight vector generated by formula (9) for each frame is finally obtained by element-wise multiplication of the static intra-frame attention and the inter-frame dynamic attention to obtain the attention weight. ; The VSS block enhancement model's ability to extract cross-frame features is achieved by using local features of the cough audio spectrogram obtained from deep convolution and activation functions, then calculating attention scores using the SS2D module to construct global features of the cough spectrogram. The linear layer convolves and fuses the SS2D output with the input normalized features, and finally adds residual connections to output features. The loss function, defined as MSELoss mean squared error, is as follows: (11) In the formula, For the i-th real label, Let be the i-th predicted value, and N be the number of samples.
[0011] In a further optimization of this technical solution, the Mel spectrum in step 3 is converted into a time-domain waveform. The specific steps are as follows: Step 3.1, Inverse logarithmic operation: Restore the Mel dB spectrum to Mel power. Perform the inverse logarithmic operation: (12) In the formula, ref is the reference amplitude, Mel () represents the dB spectrum; Step 3.2, Recover the linear power spectrum: Calculate the power spectrum inversely according to equation (4). That is, the following equation can be solved: P m (13) In the formula, Given the Mel filter bank matrix, the solution is obtained. : (14) In the formula, To obtain the linear power spectrum, the square root of the linear power spectrum is used to obtain the STFT amplitude spectrum. The complex spectrum is then calculated by combining the amplitude spectrum with the original phase. : (15) In the formula, The phase term is in complex exponential form. The imaginary unit; Step 3.3, ISTFT: Reconstruct the time-domain waveform of the newborn pig's sound using inverse Fourier transform. : (16) In the formula, The frame length of the STFT. For frequency points, The number of time-domain sampling points. This is the restored time-domain signal of the m-th frame.
[0012] A further optimization of this technical solution is that step 4, separating the cough aliasing time-domain waveform, includes: Non-negative matrix factorization (NMF) is a matrix factorization algorithm that requires both input and output matrix elements to be non-negative. The basic idea of the NMF algorithm is: given a non-negative matrix... Find two nonnegative matrix factors and To satisfy as much as possible: (17) Among them, As a basis matrix, For the coefficient matrix, the number of selected features k is typically much smaller than 1. and , The steps of the NMF algorithm are as follows: (1) Set the initialization iteration matrices W and H; (2) Select the objective function; (3) According to the multiplication iteration rule, the W and H matrices are continuously and alternately updated; (4) When the maximum number of iterations is reached, the cost function converges, that is, the algorithm decomposition ends; When initializing W and H matrices, the initial matrices are adjusted during random initialization to force most elements close to 0, so that their matrix product is close to the target matrix V before the iteration begins, thus accelerating convergence and providing the estimated value in formula (17). and The approximation degree of the matrix is determined by selecting the normalized KL divergence reconstruction error as the objective function. : (18) In the formula Original matrix The Middle line, number Column elements, Normalization constant For separating the sound of pig coughs, since the audio of pig coughs has certain sparsity characteristics and is discontinuously distributed in the time-frequency domain, the basis matrix needs to be considered. sum coefficient matrix By adding sparsity constraints and continuously updating the sparsity in the iterative estimation matrix, the objective function becomes: (19) In the formula, For sparsity strength, the following is required Sparse regularization weights, , ; The optimization process of NMF is to find the optimal... and To minimize the above objective function and solve the optimization problem with sparse constraints, a multiplicative iterative update rule is used, as shown in the following formula: (20) (21) In the formula, Represents the coefficient matrix The Middle line, number List, The basis matrix W represents the first... line, number The elements of the column are continuously adjusted alternately according to the iterative update rule in the above formula. and Matrix, reduce and The difference in these factors causes the objective function to eventually converge, at which point the output of the completed iteration can be obtained. and The matrix NMF decomposition is complete.
[0013] A further optimization of this technical solution is that, in step 4, the time-domain waveform of each cough sound in the multi-pig cough aliasing sound includes: The recovery of each cough signal is accomplished using time-frequency masking, and then the time-domain signal is obtained through inverse Fourier transform. The specific steps for reconstructing the source signal are as follows: (1) Calculate the spectrum of a single source: For the th source Each source (k=1, 2, ..., k) is used to reconstruct its time-frequency domain amplitude. : (22) In the formula, Let be the spectral basis vector of the k-th source. Let k be the time activation vector of the k-th source; (2) Generate mask: Calculate the proportion of the energy of the k-th source signal to the total energy of the mixed signal at each time frequency point: (23) of which The value range is [0,1]; (3) Separating the spectrum of complex numbers: using the mask obtained in the previous step Modify the complex time spectrum of the mixed audio When separating complex numbers, the spectrum This preserves the phase information of the original signal; (4) Recovering the time-domain signal: Using ISTFT to extract the time-domain signal The signal is converted to a time-domain signal while ensuring that the parameters are completely consistent with the STFT to ensure that the time-domain signal is reconstructed.
[0014] Unlike existing technologies, the above technical solution has the following beneficial effects: 1. Significantly improves the accuracy and personalization of disease monitoring: It can effectively separate overlapping cough sounds, solving the core problem of sound interference in group rearing environments. The separated individual cough sound signals are of higher quality, containing purer disease-related acoustic features that are easier to analyze and identify, greatly improving the accuracy of diagnosis.
[0015] 2. Enhanced early warning capabilities: Early, mild coughing symptoms in individual pigs can easily be masked by group noise or loud coughing from other pigs. This technology can effectively capture these previously overlooked weak or early coughing signals through separation, thereby detecting early signs of disease.
[0016] 3. Improve the practicality of automated monitoring: The solution design takes into account the reality of multiple pigs coexisting in actual farms, enhancing the robustness and practicality of automated sound monitoring technology in complex acoustic environments. Furthermore, the sound analysis-based technology itself is non-contact, enabling continuous and automated monitoring of pig health, reducing the burden and stress of manual inspections.
[0017] 4. Advantages at the algorithm level: Compared to pure end-to-end deep separation models that may require a large amount of labeled data or are extremely expensive in terms of computing resources, this combined approach may achieve a balance between model training complexity and computational efficiency, making it more suitable for practical deployment. Attached Figure Description
[0018] Figure 1 A flowchart for the method of separating and reconstructing cough sounds in group-raised pigs under conditions of balanced feed nutrition; Figure 2 Generate a flowchart for the Mel spectrogram; Figure 3 The diagram shows the structure of the VM-UNet network model. Figure 4 For time-attention modules; Figure 5 The improved VSS block structure diagram; Figure 6 A comparison of the validation loss curves for the UNet, VM-UNet, and TA-VMUNet models; Figure 7 This is a cough mel spectrum extraction diagram based on TAVM-UNet; Figure 8 Mel spectrum extraction images for two types of cough based on TAVM-UNet; Figure 9 Mel spectrum extraction diagrams for three types of cough based on TAVM-UNet; Figure 10 Mel spectrum extraction diagrams for four types of cough based on TAVM-UNet; Figure 11 The waveforms of four different types of aliased cough audio. Figure 12 The time-domain waveforms of each cough source in the mixed cough sound; Figure 13 Comparison of NMF reconstruction error curves for different λ values; Figure 14 The changes in the W and H matrices before and after iteration for the two types of cough sounds; Figure 15 The two reconstructed cough waveforms; Figure 16 The time-domain waveforms of each source cough in the three types of cough aliasing time-domain waveforms; Figure 17 The changes in the W and H matrices before and after iteration for the three types of cough sounds; Figure 18 The time-domain waveforms of the three types of cough sounds are shown in the reconstruction. Figure 19 The diagram shows the time-domain waveforms of four different cough sources and the reconstructed time-domain waveforms of the cough. Detailed Implementation
[0019] To explain in detail the technical content, structural features, objectives, and effects of the technical solution, the following description is provided in conjunction with specific embodiments and accompanying drawings.
[0020] The overall design process for separating and reconstructing pig cough sounds based on the TAVM-UNet model and sparse NMF algorithm is as follows: Figure 1 As shown.
[0021] Offline training of the TA-VMUNet model: Linearly aliasing of non-coughing and coughing pig sounds to form the sound of pig herding; then, extracting the Mel feature spectrograms of single / multiple cough audio in the aliased sound as feature input to the TAVM-UNet model, training the model to extract the Mel feature spectrograms of single / multiple pig cough audio.
[0022] Online separation of each sound in aliased coughs: The Mel spectrum of the aliased audio of group-raised pigs is input into the trained TAVM-UNet model to separate the aliased spectrograms of single-pig coughs / multi-pig coughs, and then converted into the time-domain waveform of the cough aliasing; combined with the NMF algorithm, the time-domain waveform of each cough sound in the aliased sound of multiple pigs is reconstructed.
[0023] A method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition includes the following steps: Step 1: Collect audio of pigs in different states, convert the audio time-domain waveform into a Mel spectrum, and obtain the Mel spectrum of mixed audio of group-raised pigs.
[0024] The audio data was collected at a pig farm in Anhui Province. Adult Landrace pigs were selected as the experimental subjects. To ensure low-noise audio recording, the recorder was placed directly above the pigpen fence to collect audio of the Landrace pigs in different states in a quiet environment. Intermittent sampling was conducted for 14 hours at a sampling frequency of 8kHz and a sampling bit depth of 16bit. The audio was saved in single-channel WAV format.
[0025] Mel spectrograms are a method for representing the spectrum of audio signals based on the Mel frequency scale. The flowchart for generating a Mel spectrogram is as follows: Figure 2 As shown.
[0026] The specific steps for converting a time-domain waveform to a Mel spectrum are as follows: Step 1.1, Preprocessing: Resample, frame, and window the pig sounds using a Hamming window. Window function values for each sample for: (1) Where L is the frame length.
[0027] Step 1.2, Short-Time Fourier Transform (STFT): Perform a short-time Fourier transform on each windowed signal to obtain the amplitude or power spectrum in the time-frequency domain. The short-time Fourier transform result of the m-th frame signal is shown below. for: (2) Among them, This is the frequency point index, corresponding to the frequency. The power spectrum can be obtained by squaring the amplitude spectrum. .
[0028] Step 1.3, Mel Filter Bank Mapping: Convert the linear spectrum to a Mel spectrum, and construct a triangular filter bank using a triangular window function. Filters ( The frequency response H h (k): (3) In the formula, Indicates the first STFT Each frequency point (Hz) is used. The STFT power spectrum is then multiplied with the Mel Filter Bank to obtain the Mel power spectrum: (4) in, Indicates the first Frame, First Energy in the Mel frequency band.
[0029] Step 1.4, Nonlinear Correction: Take the logarithm of the Mel power spectrum from the previous step and perform logarithmic compression to obtain the Mel dB spectrum: (5) In the formula, To avoid numerical overflow.
[0030] Step 2: Input the mixed audio Mel spectrogram of group-raised pigs into the trained TAVM-UNet model to separate the mixed spectrogram of single pig cough / multiple pig cough.
[0031] VM-UNet is an encoder and decoder structure that combines UNet. Its underlying framework, State Space Model (SSM), captures contextual information and establishes long-distance dependencies through Visual State Space (VSS) blocks, enabling the extraction of features at different levels. Figure 3 It is the VM-UNet network model structure.
[0032] The Patch Embedding layer divides the input spectrogram into 4×4 non-overlapping blocks, transforms the number of channels to C (C defaults to 96) to complete the initial encoding; the encoding layer performs spatial resolution downsampling, reducing the size and increasing the number of channels, and extracts features through VSS blocks; the decoding layer performs upsampling to restore the spectrogram size, reduces the number of channels, and the VSS blocks combined with skip connections gradually restore audio features; the Final Projection layer uses 1×1 convolution operations to restore the features output by the decoding layer to the input size and number of channels, completing the audio reconstruction; in order to preserve the original details of the audio in the restoration stage, skip connections are added to perform additive operations, thereby improving the model's ability to restore detailed features.
[0033] TAVM-UNet network model As the core module of VM-UNet, each VSS block includes a linear layer, a 2D state space, layer normalization, depthwise convolution, and residual connections. To better suit the characteristics of spectrograms, the model's scanning method is changed to a directional scan along the "time horizontal axis and frequency vertical axis," allowing the model to focus more on the temporal and frequency relationship of cough audio.
[0034] Because pig cough audio is characterized by short bursts and discontinuous distribution, the VSS block struggles to focus on this feature. To address this issue, a Temporal Attention Mechanism (TAM) is embedded after the Linear Layer and before Dw-Conv in the VSS block. Temporal attention generates temporal weights, enhancing the network's ability to extract cross-frame features from cough audio segments. The structure of the temporal attention module is as follows: Figure 4 As shown.
[0035] The temporal attention module takes a feature audio spectrogram as input, where T is the frame number, B is the batch size, C is the number of channels, and H and W are the spatial dimensions. The temporal attention unit reorganizes time and channels, which is processed in parallel within the TAU by intra-frame static attention and inter-frame dynamic attention. The improved VSS block structure is as follows: Figure 5 As shown.
[0036] Intra-frame static attention is achieved by performing convolution operations on each channel independently using DW Conv and depth-dilated convolutions: (6) Among them, Let c be the convolution kernel parameters for the c-th channel. Let (i+m,j+n) be the element value of the c-th channel of the input feature map at position (i+m,j+n).
[0037] (7)
[0038] In the formula, For convolution kernel parameters, Let S be the expansion rate. Then, perform a 1×1 convolution operation on the channels in each time period to obtain a tensor S with dimensions T×C×S×W.
[0039] Inter-frame dynamic attention focuses on the importance of different frames, thus generating temporal weights. Global average pooling is performed on each temporal frame to extract global channels. (8) In the formula, F t For the feature map in frame t The element value, and These are the height and width of the feature map. The result is obtained by global average pooling. Input to the fully connected layer to generate inter-frame channel weight vectors : (9) In the formula, For the parameter matrix, It is the ReLU activation function. The activation function is sigmoid. The attention weight tensor D is obtained by accumulating the channel weights across all frames. (10) Among them, The channel weight vector for each frame is generated by formula (9). Finally, the attention weights are obtained by element-wise multiplication of the static intra-frame attention and the inter-frame dynamic attention. .
[0040] The VSS block enhancement model enhances its ability to extract cross-frame features. Local features from the cough audio spectrogram obtained through deep convolution and activation functions are then used by the SS2D module to calculate attention scores, constructing the model's global features of the cough spectrogram. A linear layer convolves and fuses the SS2D output with the input normalized features, and finally, residual connections are added to the output features to prevent gradient vanishing during deep network training.
[20] .
[0041] To measure the accuracy of feature extraction, the mean squared error of MSELoss is used as the loss function, defined as follows: (11) In the formula, For the i-th real label, Let be the i-th predicted value, and N be the number of samples.
[0042] Step 3: Convert the aliased Mel spectrogram of single-pig cough / multi-pig cough into a time-domain waveform of cough aliasing.
[0043] The specific steps for converting a Mel spectrum into a time-domain waveform are as follows: Step 3.1, Inverse logarithmic operation: Restore the Mel dB spectrum to Mel power. Perform the inverse logarithmic operation: (12) In the formula, ref is the reference amplitude, Mel () represents the dB spectrum.
[0044] Step 3.2, Recover the linear power spectrum: Calculate the power spectrum inversely according to equation (4). That is, the following equation can be solved: P m (13) In the formula, Given the Mel filter bank matrix, the solution is obtained.
[0045] In formula (14), To obtain the linear power spectrum, the square root of the linear power spectrum is used to obtain the STFT amplitude spectrum. The complex spectrum is then calculated by combining the amplitude spectrum with the original phase. : (15) In the formula, The phase term is in complex exponential form. It is the imaginary unit.
[0047] Step 3.3, ISTFT: Reconstruct the time-domain waveform of the newborn pig's sound using inverse Fourier transform. : (16) In the formula, The frame length of the STFT. For frequency points, The number of time-domain sampling points. This is the restored time-domain signal of the m-th frame.
[0048] Step 4: Use the NMF algorithm to separate the time-domain waveforms of the cough aliasing and reconstruct the time-domain waveforms of each cough sound in the multi-pig cough aliasing sound.
[0049] Non-negative matrix factorization (NMF) is a matrix factorization algorithm that requires both the input and output matrix elements to be non-negative. The basic idea of the NMF algorithm is: given a non-negative matrix... Find two nonnegative matrix factors and To satisfy as much as possible: (17) Among them, As a basis matrix, For the coefficient matrix, the number of selected features k is typically much smaller than 1. and .
[0050] The algorithm steps are as follows: (1) Set the initialization iteration and matrix; (2) Select the objective function; (3) According to the multiplication iteration rule, the W and H matrices are continuously and alternately updated; (4) When the maximum number of iterations is reached, the cost function converges, that is, the algorithm decomposition ends.
[0051] For initialization and When dealing with matrices, most traditional NMF algorithms randomly generate non-negative initial basis matrices from uniform or Gaussian distributions. sum coefficient matrix To ensure the final iterative result of the algorithm and avoid convergence failure, the initial matrix is adjusted during random initialization, forcing most elements to be close to 0, so that its matrix product is close to the target matrix before the iteration begins. This accelerates convergence. The value estimated in formula (17) is used for calculation. and The approximation degree of the matrix is determined by selecting the normalized KL divergence reconstruction error as the objective function. : (18) In the formula Original matrix The Middle line, number Column elements, Normalization constant To separate the cough sounds of pigs, the audio of pig coughs exhibits certain sparsity characteristics, discontinuously distributed in the time-frequency domain. To improve separation accuracy and address the issues of feature overlap and redundancy between cough audio signals, the basis matrix is adjusted. sum coefficient matrix By adding sparsity constraints and continuously updating the sparsity in the iterative estimation matrix, the objective function becomes: (19) In the formula, For sparsity strength, the following is required Sparse regularization weights, , .
[0052] The optimization process of NMF is to find the optimal W and H to minimize the above objective function, solving the optimization problem with sparse constraints. Common optimization algorithms such as gradient descent are simple to implement, but their convergence speed is slow. In addition, to keep the results non-negative, this experiment adopts a multiplicative iterative update rule, as shown in the following formula: The formula is as follows: (20) (21) In the formula, Represents the coefficient matrix The Middle line, number List, The basis matrix W represents the first... line, number The elements of the column. The iterative update rule in the above formula is used to continuously adjust the elements alternately. and Matrix, reduce and The difference in these factors causes the objective function to eventually converge, at which point the output of the completed iteration can be obtained. and The matrix NMF decomposition is complete.
[0053] After the above operations, time-frequency masks are used to recover each cough signal, and then inverse Fourier transform is used to obtain the time-domain signal. The specific steps for reconstructing the source signal are as follows: (1) Calculate the spectrum of a single source: For the th source Each source (k=1, 2, ..., k) is used to reconstruct its time-frequency domain amplitude. : (22) In the formula, For the first Spectral basis vectors of each source. For the first Temporal activation vectors of each source.
[0054] (2) Generate mask: Calculate the proportion of the energy of the k-th source signal to the total energy of the mixed signal at each time frequency point: (23) of which The value range is [0,1].
[0055] (3) Separating the spectrum of complex numbers: using the mask obtained in the previous step Modify the complex time spectrum of the mixed audio When separating complex numbers, the spectrum This preserves the phase information of the original signal.
[0056] (4) Recovering the time-domain signal: Using ISTFT to extract the time-domain signal The signal is converted to a time-domain signal while ensuring that the parameters are completely consistent with the STFT to ensure that the time-domain signal is reconstructed.
[0057] Experimental environment The research hardware environment consisted of an NVIDIA A100-80G Tensor Core GPU and an Intel(R) Xeon(R) Gold6248R CPU. The software environment was an Ubuntu 20.04 operating system, using Python 3.8, with PyTorch version 2.1.1 and CUDA version 11.8 as the network model.
[0058] Offline training of TAVM-UNet model This embodiment extracts four types of pig state sounds: grunting, squealing, eating, and coughing, ensuring that each sample contains the corresponding state sound, and defining the three non-coughing sounds as noise.
[0059] The coughing sounds came from four pigs: pig number 1 (denoted as K1), pig number 2 (denoted as K2), pig number 3 (denoted as K3), and pig number 4 (denoted as K4). The sounds of pigs eating, grunting, and squealing came from the other six pigs.
[0060] The dataset is created by mixing cough sounds with non-cough sounds in the following manner: (1) Select K1 from the cough samples and perform linear aliasing on one sample from each of the other three non-cough sounds to construct a mixed sound 1 containing one cough sound. Then extract the Mel spectrum of the mixed sound 1 and the Mel spectrum of the corresponding K1, each 1189. (2) Select K1 and K2 from the cough samples, and perform linear aliasing on one sample from each of the other three non-cough sounds to construct a mixed sound 2 containing the two cough sounds. Then extract the Mel spectrum of the mixed sound 2 and the Mel spectrum of K2, each 1310. (3) Select K1, K2 and K3 from the cough samples, and perform linear aliasing on one sample from each of the other three non-cough sounds to construct a mixed sound 3 containing the three cough sounds. Then extract 1420 Mel spectra of the mixed sound 3 and 1420 Mel spectra of K3. (4) Select K1, K2, K3 and K4 from the cough samples, and select one sample from each of the other three non-cough sounds for linear aliasing to construct a mixed sound 4 containing the four cough sounds. Then extract 1527 Mel spectra of mixed sound 4 and 1527 Mel spectra of K4.
[0061] The dataset was divided into a training set (75%), a test set (15%), and a validation set (10%), with a learning rate set to 0.001. U-Net and VM-UNet were used as control models for TAVM-UNet, and trained for 80 epochs on the same training dataset. The loss curves of the UNet, VM-UNet, and TAVM-UNet models were compared as follows: Figure 6 As shown.
[0062] The loss curves from the model training show that UNet performed the worst, with a large initial loss value that fluctuated significantly between 10 and 40 epochs, exhibiting some oscillations in the later stages and showing a slight overfitting problem, eventually stabilizing at around 0.002. The VM-UNet model showed less fluctuation than U-Net, converging rapidly between 5 and 30 epochs. After 25 epochs, its overall loss value was lower than that of U-Net, but significant local peaks appeared around epochs 34 and 42, indicating that the model had not learned the characteristics of cough audio. After the peaks, the loss still decreased to its pre-fluctuation level, without affecting the overall network's ability to extract cough audio features, and the final loss value stabilized at 0.001. TAVM-UNet further improved its feature extraction capabilities, decreasing rapidly in the early training stages (0-10 epochs), then steadily decreasing in the mid-stages (10-40 epochs), and finally stabilizing at 0.0007 with smaller fluctuations in the later stages. The overall curve consistently decreased without abnormal peaks, indicating effective model convergence.
[0063] This embodiment selects Source Distortion Ratio (SDR), Signal-to-Noise Ratio (SNR), and SegSNR (SegSNR) as objective metrics for model feature extraction. They are defined as follows: In equation (24), The original signal, The extracted signal. SDR is the ratio of the power of the target source signal to the power of the introduced distortion, reflecting the separation effect between the target signal and the non-target signal.
[0064] (24) In the formula, For the nth original signal, Let N be the nth separated signal, and N be the total number of signal sampling points. SNR is the ratio of target signal power to noise power; a higher SNR indicates a smaller impact from noise.
[0065] (25) In the formula, M is the total number of frames, and L is the number of sampling points per frame. This represents the original signal of the m-th frame. The m-th frame is the segmented signal. SegSNR is calculated by dividing the entire signal into several frames, calculating the SNR value for each frame, and then averaging the results to reflect the local noise quality of the signal.
[0066] This embodiment introduces source distortion ratio (SDR), signal-to-noise ratio (SNR), and inter-source interference ratio (SIR).
[32] Mean Square Error (MSE) is a performance indicator for cough sound separation. The MSE calculation formula is shown in Equation (11). MSE measures the point-by-point error between the separated signal and the original signal. The lower the value, the higher the separation accuracy, i.e., the higher the separation quality. The definition of SIR is as follows: (26) In the formula To separate the energy of the target source in the signal, SIR represents the total energy of all other interference sources in the separated signal. SIR reflects the degree of interference from other source signals in the separated signal; a higher value indicates less interference between different sources and a "cleaner" separation.
[0067] Mel spectrum extraction of swine cough based on TAVM-UNet Figures 7-10 The images are Mel spectra extracted from the TA-VMUNet model containing one type of cough sound, and Mel spectra containing four types of cough sounds, respectively. Figure 7 In the image, (a) is mixed audio 1, and (b) is the extracted Mel spectrum containing a cough. Figure 8 In the image, (a) is the mixed audio 2, and (b) is the extracted Mel spectrum containing two types of coughs; Figure 9 (a) shows mixed audio 3, and (b) shows the extracted Mel spectrum containing three types of coughs; Figure 10 (a) shows mixed audio 4, and (b) shows the extracted Mel spectrum containing four types of coughs. Figure 7 In the spectrum diagram of (b), it can be found that the core frequency band for swine cough is between 500 and 2KHz in the low-to-mid frequency range, which has the characteristics of strong penetration and easy to induce swine irritability. Figure 7 (b) The spectrogram of the cough sound extracted retains the main features of the cough. The bright bands of the spectrogram are clear and the edges are neat, effectively separating the main features of cough sound 1. Figure 8 (b) The mixed spectrum of the two cough sounds extracted showed an added yellow bright band in the low frequency range of 0~0.5s, while the dark area was clearly colored and had clear boundaries in the range of 2~2.5s, thus extracting the main features of the two cough sounds. Figure 9 (b) is the extracted aliasing spectrogram containing three cough sounds. The yellow bright band is more concentrated in the 0-512Hz frequency band. Due to the fusion of the three cough sounds, the overall aliasing audio spectrogram becomes more blurred, and the boundary areas are smoother. This is consistent with... Figure 8 (b) Comparison of the two extracted aliased cough audio samples shows a more pronounced bright area between 2 and 2.5 seconds, indicating that TAVM-UNet can still extract the main cough features of cough 3. (Spectrum) Figure 10 (b) compared Figure 9(b) The yellow bright band in the 1024KHz high frequency band deepens within 1.5~2s, extracting more cough features. The model can effectively extract cough information.
[0068] The UNet, VM-UNet, and TAVM-UNet models were used to extract the Mel spectrum of 1 to 4 types of cough on the same dataset. The objective indicators of the Mel spectrum of 1 to 4 types of cough extracted from each model were averaged to obtain the objective indicators of the three models as shown in Table 1.
[0069] Table 1 Comparison of extraction performance of UNet, VM-UNet and TA-VMUNet models
[0070] As shown in Table 1, the TAVM-UNet model performs best in extracting the cough Mel spectrum. Compared with the VM-UNet model, the three evaluation metrics SDR, SNR, and SegSNR are improved by 2.11 dB, 1.88 dB, and 2.06 dB, respectively. Compared with the U-Net model, the three evaluation metrics SDR, SNR, and SegSNR are improved by 2.64, 2.52, and 2.61, respectively. The experimental results indicate that TAVM-UNet is the best for extracting the aliased cough Mel spectrum.
[0071] Separation and reconstruction of multi-pig cough aliased audio based on NMF
[0072] The TAVM-UNet model extracts the cough Mel spectrum from the mixed Mel spectrum containing cough, and then converts the extracted Mel spectrum into a time-domain waveform according to formulas (12) to (16). Figure 11 (a) to 11 (d) are respectively one type of cough sound waveform extracted by TAVM-UNet, two types of cough sound waveforms extracted by TAVM-UNet, three types of cough sound waveforms extracted by TAVM-UNet, and four types of cough sound waveforms extracted by TAVM-UNet. Figure 11 (a) ~ 11 (d) correspond to respectively Figure 7 (b) ~ Figure 10 (b) The converted time-domain waveform.
[0073] The multi-swine cough aliasing waves were separated using formulas (17) to (21) of the NMF algorithm, and then reconstructed using formulas (22) and (23).
[0074] (1) Separation and reconstruction of time-domain waves of two types of cough aliasing The time-domain waveforms of each cough source in the two cough aliasing waveforms are as follows: Figure 12 As shown. Figure 12 (a) and (b) are the waveforms of source cough sound 1 and source cough sound 2, respectively. From Figure 12 (a) and Figure 12 (b) From the source cough time-domain waveform, it can be seen that the source cough time-domain waveform 1 has high sparsity, with obvious silence periods and no obvious intermittency, showing an overall low sparsity state. To explore the convergence of the algorithm under different sparsity constraints, the difference between the objective function evaluation matrix and the original matrix V in formula (19) is used. The values are used for matrix iteration, with the iteration rounds set to 200. Different The error reconstruction value of the NMF algorithm is as follows: Figure 13 As shown, when When the value is 0.1, the overall error decreases the fastest, and the final value stabilizes at 0.0037 as the number of iterations increases. Therefore, this... The optimal sparsity strength value was set for subsequent experiments.
[0075] The W and H matrices are iteratively evolved using a multiplicative update rule. The dimensions of the base matrix W (m×k) and the activation matrix H (k×n) are 513×2 and 2×247, respectively. W(:,1) and W(:,2) correspond to the spectra of cough sources 1 and 2, respectively, and H(:,1) and H(:,2) correspond to the intensity changes of cough sources 1 and 2 over time, respectively. The spectra of each column of the initial and iterated W matrix and the time series of each row of the H matrix are output, as follows: Figure 14 Figures (a) to (d) show the following: W:,1 Spectrum diagrams before and after iteration H1,: Time series comparison chart before and after iteration W:,2 Spectrum diagrams before and after iteration H2,: Comparison of time series before and after iteration.
[0076] The W and H matrices generated after the above iterative update are used to calculate the time-frequency mask using formulas (22) and (23). The time-domain signal is recovered by ISTFT, and each cough time-domain wave in the cough aliasing time-domain wave is reconstructed. The two reconstructed cough time-domain waves are as follows: Figure 15 (a) and (b) show the reconstructed cough sound waveform 1 and reconstructed cough sound waveform 2, respectively. The evaluation metrics for the two reconstructed cough time-domain waveforms are shown in Table 2.
[0077] Table 2 Evaluation Indicators for Reconstructing Two Cough Time-Domain Waveforms
[0078] from Figure 15 (a) Figure 15 (b) and Table 2 show that the reconstructed cough 1 time-domain waveform has some noise in the 0.4–0.5 s period, but remains consistent with the waveform of the source cough 1 time-domain waveform in other time periods. The evaluation indices SDR, SNR, SIR, and MSE reach 5.30, 5.61, 5.47, and 0.010325, respectively. Figure 12(b) and Figure 15 (b) It can be seen that the reconstructed cough sound 2 time-domain waveform has a high overall similarity to the source cough sound 2 time-domain waveform, with evaluation indices SDR, SNR, SIR, and MSE of 5.72 dB, 6.19 dB, and 0.007, respectively. This demonstrates that the NMF method can effectively separate and reconstruct the time-domain waveforms of the two overlapping cough sounds.
[0079] (2) Separation and reconstruction of time-domain waves of three types of cough aliasing The time-domain waveforms of each source cough in the three types of cough aliasing are as follows: Figure 16 As shown, Figure 16 (a)-(c) are the waveforms of source cough sound 1, source cough sound 2, and source cough sound 3, respectively.
[0080] W :,1 , W :,2 , W :,3 The spectral changes for cough sources 1, 2, and 3 are shown respectively. H 1,: 、H 2,: H 3,: The activation intensity changes at each source time dimension are shown below. Based on the NMF multiplication update iteration rule and the optimal sparse strength constraint λ (λ=0.1), the spectrum of each column in the W matrix and the time series changes of each row in the H matrix before and after iteration are as follows: Figure 17 (a)- Figure 17 As shown in (f), (a) W :,1 Changes in the spectrum before and after iteration, (b) H 1,: Changes in the time series before and after the iteration, (c) W :,2 Changes in the spectrum before and after iteration, (d) H 2,: Changes in the time series before and after the iteration, (e) W :,3 Changes in the spectrum before and after iteration, (f) H 3,: Changes in the time series before and after the iteration.
[0081] The W and H matrices generated by the above iterations are used to calculate the time-frequency mask using formulas (22) and (23), and then the time-domain signal is recovered using ISTFT to reconstruct each cough sound waveform in the three cough aliasing waveforms, as shown in the figure. Figure 18As shown in (a), 18(b), and 18(c), these are the reconstructed time-domain waveforms of cough sound 1, cough sound 2, and cough sound 3, respectively. The evaluation indicators for the three reconstructed cough time domains are shown in Table 3.
[0082] Depend on Figure 18 (a) and Figure 16 (a) shows that the reconstructed cough time-domain waveform 1 has significant noise in the 3-3.5s segment, while other time segments are highly consistent with the original waveform; from Figure 18 (b) and Figure 16 (b) It can be seen that the reconstructed cough time-domain waveform 2 is completely intact compared to the source signal, but the amplitude is partially attenuated; in contrast... Figure 18 (c) and Figure 16 (c) It was found that the reconstructed cough time-domain waveform 3 had a small amplitude of signal reconstruction in the 3.5~4s range, while the other parts remained basically consistent.
[0083] Table 3 Evaluation indicators for reconstructing the three cough time-domain waveforms
[0084] The performance indicators of the reconstruction of the three cough aliasing time-domain waveforms are shown in Table 3. When separating and reconstructing the three cough aliasing time-domain waveforms, the interference is increased due to the aliasing of multiple cough sounds. The average SDR, SNR, SIR and MSE of the three cough time-domain waveforms are 5.41dB, 4.60dB, 5.50dB and 0.014 respectively. Compared with Table 2, the values are reduced by 0.10dB, 0.52dB, 0.33dB and 0.004 respectively for the same indicators. Table 3 shows that although the SIR index of the reconstructed cough 3 time-domain waveform is the worst, it is still 5.13dB, which is only 0.34dB worse than the SIR index of the reconstructed cough 2 in Table 2.
[0085] Overall, the separation and reconstruction quality of the three types of cough aliasing time-domain waveforms is slightly lower than that of the two types of cough aliasing time-domain waveforms.
[0086] (3) Separation and reconstruction of time-domain waves of four types of cough aliasing To further verify the NMF algorithm's ability to separate and reconstruct multi-source aliased cough time-domain waveforms, four types of cough mixed time-domain waveforms were separated and reconstructed. Optimal sparsity intensity constraints were then added. value( After (=0.1), the NMF algorithm is used to separate and reconstruct four cough time-domain waveforms from the four aliased cough waveforms, such as Figure 19 The evaluation indicators for the reconstruction (a)-(h) are shown in Table 4.
[0087] Table 4 Evaluation Indicators for Reconstructing Four Types of Cough Time-Domain Waveforms
[0088] Figure 19 (a), 19 (c), 19 (e), and 19 (g) are the time-domain waveforms of source cough 1, cough 2, cough 3, and cough 4, respectively; Figure 19 (b), 19 (d), 19 (f), and 19 (h) are examples of using the NMF algorithm from... Figure 11 (d) Time-domain waveforms of cough 1, cough 2, cough 3, and cough 4 reconstructed from the four types of cough aliasing time-domain waveforms. From Table 4 and Figure (19), it can be seen that: Figure 19 (a) and 19(b), Figure 19 (c) and Figure 19 (d) The waveforms are basically the same, and the SIRs of 19(c) and 19(d) are 5.23dB and 4.93dB, respectively. Figure 19 (f) The reconstructed time-domain waveform of cough 3 shows distortion, with an SNR of 3.52 dB. The isolated SDR of cough 4 is 2.65 dB, SNR is 2.93 dB, and MSE is 0.034. Figure 19 (h) Waveform distortion, the cough waveform 4 is affected by interference from other cough sources, and the SIR is 2.51dB.
[0089] This invention proposes a method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition, and the conclusions are as follows: (1) Regarding the extraction of the Mel spectrum from swine coughing, a TAVM-UNet model was designed. This model embeds a time attention mechanism into the VSS block of the VM-UNet model to remove the non-coughing portion of the mixed Mel spectrum of coughing and non-coughing, while retaining the coughing Mel spectrum. Compared with the VM-UNet model, the TAVM-UNet model improves the SDR, SNR, and SegSNR by 2.11 dB, 1.88 dB, and 2.06 dB, respectively. This provides a guarantee for the subsequent separation and reconstruction of mixed time-domain waveforms from multiple coughing samples.
[0090] (2) In terms of separation and reconstruction of time-domain waveforms with multiple coughing patterns. Considering the discontinuous characteristics of swine cough waveforms, and combining optimal sparsity constraints... ( The NMF algorithm with a resolution of 0.1 achieved the following results when separating and reconstructing two types of cough aliasing time-domain waveforms: SDR of 5.30–5.72 dB, SNR of 4.63–5.61 dB, SIR of 5.47–6.19 dB, and MSE below 0.01. When separating and reconstructing three types of cough aliasing time-domain waveforms, the SDR was 5.04–6.06 dB, SNR of 4.19–5.21 dB, SIR of 5.13–6.01 dB, and MSE around 0.012. The worst-performing target source had an SDR of 5.04 dB and an SIR of 5.13 dB. The SNR was 4.19 dB, and the reconstructed cough time-domain waveform still maintained high quality. When separating and reconstructing the four types of cough aliasing time-domain waveforms, the SDR of the four reconstructed cough time-domain waveforms was 2.65~5.12dB, the SNR was 2.93~4.20dB, and the SIR was 2.51~5.23dB.
[0091] In summary, as the number of separated cough aliasing time-domain waves increases, the reconstructed cough time-domain waves show signs of distortion, and the overall objective evaluation indicators show a slight downward trend.
[0092] 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 terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Unless otherwise specified, an element defined by the phrase "comprising..." or "including..." does not exclude the presence of additional elements in the process, method, article, or terminal device that includes said element. Additionally, in this document, "greater than," "less than," "exceeding," etc., are understood to exclude the stated number; "above," "below," "within," etc., are understood to include the stated number.
[0093] Although the above embodiments have been described, those skilled in the art, once they understand the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the above descriptions are merely embodiments of the present invention and do not limit the scope of patent protection of the present invention. Any equivalent structural or procedural transformations made using the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition, characterized in that, Includes the following steps: Step 1: Collect audio data of pigs in different states, convert the audio time-domain waveform into a Mel spectrogram, and obtain the Mel spectrogram of mixed audio data of group-raised pigs; Step 2: Input the mixed audio Mel spectrogram of group-raised pigs into the trained TAVM-UNet model to separate the mixed spectrogram of single pig cough / multiple pig cough. Step 3: Convert the Mel spectrogram of single-pig cough / multi-pig cough aliasing into a time-domain waveform of cough aliasing; Step 4: Use the NMF algorithm to separate the time-domain waveforms of the multiple pig coughs and reconstruct the time-domain waveforms of each cough sound in the multiple pig coughs.
2. The method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition as described in claim 1, characterized in that, The time-domain waveform is converted into a Mel spectrum, and the specific steps are as follows: Step 1.1, Preprocessing: Resample, frame, and window the pig sounds using a Hamming window. Window function values for each sample for: (1) Where L is the frame length; Step 1.2, Short-Time Fourier Transform: Perform a short-time Fourier transform on each windowed signal frame to obtain the amplitude or power spectrum in the time-frequency domain. The short-time Fourier transform result of the m-th frame signal is shown below. for: (2) Where k is the frequency point index, corresponding to the frequency. The power spectrum can be obtained by squaring the amplitude spectrum. ; Step 1.3, Mel filter bank mapping: Convert the linear spectrum to the Mel spectrum, construct a triangular filter bank using a triangular window function, and obtain the frequency response H of the h-th filter (1≤h≤K). h (k): (3) In the formula, f k Representing the k-th frequency point (Hz) of the STFT, the power spectrum of the STFT is multiplied by the Mel Filter Bank to obtain the Mel power spectrum: (4) in, Indicates the first Frame, First Energy in the Mel frequency band; Step 1.4, Nonlinear Correction: Take the logarithm of the Mel power spectrum from the previous step and perform logarithmic compression to obtain the Mel dB spectrum: (5) In the formula, To avoid numerical overflow.
3. The method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition as described in claim 1, characterized in that, The method for constructing the TAVM-UNet network model is as follows: The TAVM-UNet network consists of a Patch Embedding layer, an encoding layer, a decoding layer, and a Final Projection layer. The VSS block in the encoding layer is the core module of the VM-UNet network. Each VSS block includes a linear layer, a 2D state space, layer normalization, depthwise convolution, and residual connections. A temporal attention mechanism is embedded after the Linear Layer and before Dw-Conv in the VSS block. Temporal weights are generated through temporal attention to enhance the network's ability to extract cross-frame features of cough audio segments. The Patch Embedding layer divides the input spectrogram into 4×4 non-overlapping blocks and converts the number of channels to C to complete the initial encoding; the encoding layer implements spatial resolution downsampling, reduces the size, increases the number of channels, and extracts features through VSS blocks with added temporal attention mechanism; In the decoding layer stage, upsampling is performed to restore the spectrogram size, reduce the number of channels, and VSS blocks with time attention mechanism are added in combination with skip connections to gradually restore audio features; The final projection layer uses a 1×1 convolution operation to restore the features output by the decoding layer to the input size and number of channels, thus completing the audio reconstruction. The temporal attention module takes a feature audio spectrogram as input, where T is the number of frames, B is the batch size, C is the number of channels, and H and W are the spatial dimensions. The temporal attention unit recombines time and channels, and in TAU, it is processed in parallel by intra-frame static attention and inter-frame dynamic attention. Intra-frame static attention is achieved by performing convolution operations on each channel independently using DW Conv and depth-dilated convolutions: (6) in, Let be the convolution kernel parameters for the c-th channel. Let the element value of the c-th channel of the input feature map be at position (i+m,j+n). (7) In the formula, Let d be the convolution kernel parameter and d be the dilation rate. Then, perform a 1×1 convolution operation on the channels in each time period to obtain a tensor S with dimensions T×C×S×W. Perform global average pooling on each time frame to extract global channels: (8) In the formula, F t For the feature map in frame t The element values, h and w are the height and width of the feature map, obtained by global average pooling. Input to the fully connected layer to generate inter-frame channel weight vectors : (9) In the formula For parameter matrices, It is the ReLU activation function. Using the sigmoid activation function, the attention weight tensor D can be obtained by accumulating the channel weights of all frames: (10) in, The channel weight vector generated by formula (9) for each frame is finally obtained by multiplying the static intra-frame attention and inter-frame dynamic attention element-wise. ; The VSS block enhancement model's ability to extract cross-frame features is achieved by using local features of the cough audio spectrogram obtained from deep convolution and activation functions, then calculating attention scores using the SS2D module to construct global features of the cough spectrogram. The linear layer convolves and fuses the SS2D output with the input normalized features, and finally adds residual connections to output features. The loss function, defined as MSELoss mean squared error, is as follows: (11) In the formula, For the i-th real label, Let be the i-th predicted value, and N be the number of samples.
4. The method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition as described in claim 1, characterized in that, In step 3, the Mel spectrum is converted into a time-domain waveform. The specific steps are as follows: Step 3.1, Inverse logarithmic operation: Restore the Mel dB spectrum to Mel power. Perform the inverse logarithmic operation: (12) In the formula, ref is the reference amplitude, Mel () represents the dB spectrum; Step 3.2, Recover the linear power spectrum: Calculate the power spectrum inversely according to equation (4). That is, the following equation can be solved: (13) In the formula, Given the Mel filter bank matrix, the solution is obtained. : (14) In the formula, To obtain the linear power spectrum, the square root of the linear power spectrum is used to obtain the STFT amplitude spectrum. The complex spectrum is then calculated by combining the amplitude spectrum with the original phase. : (15) In the formula, The phase term is in complex exponential form, where j is the imaginary unit; Step 3.3, ISTFT: Reconstruct the time-domain waveform of the newborn pig's sound using inverse Fourier transform. : (16) In the formula, L is the frame length of the STFT, k is the number of frequency points, and n is the number of time-domain sampling points. This is the restored time-domain signal of the m-th frame.
5. The method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition as described in claim 1, characterized in that, Step 4, separating the cough aliasing time-domain waveform, includes: Non-negative matrix factorization (NMF) is a matrix factorization algorithm that requires both input and output matrix elements to be non-negative. The basic idea of the NMF algorithm is: given a non-negative matrix... Find two nonnegative matrix factors and To satisfy as much as possible: (17) Where W is the basis matrix and H is the coefficient matrix. For the number of selected features k, it is usually much smaller than m and n. The steps of the NMF algorithm are as follows: (1) Set the initialization iteration matrices W and H; (2) Select the objective function; (3) According to the multiplication iteration rule, the W and H matrices are continuously and alternately updated; (4) When the maximum number of iterations is reached, the cost function converges, that is, the algorithm decomposition ends; When initializing the W and H matrices, the initial matrices are adjusted during random initialization to force most elements close to 0, so that their matrix product is close to the target matrix V before the iteration begins, thus accelerating convergence. To calculate the approximation of the estimated WH and V matrices in formula (17), the normalized KL divergence reconstruction error is selected as the objective function. : (18) In the formula V ij Let be the element in the i-th row and j-th column of the original matrix V. Normalization constant To separate the cough sounds of pigs, given the sparsity of the pig cough audio signals and their discontinuous distribution in the time-frequency domain, sparsity constraints are added to the basis matrix W and the coefficient matrix H. The sparsity is continuously updated in the iterative estimation matrix, and the objective function becomes: (19) In the formula, λ is the sparsity strength, and λ≥0 is required as the sparsity regularization weight. , ; The optimization process of NMF involves finding the optimal W and H to minimize the objective function, solving the optimization problem with sparse constraints, and using a multiplicative iterative update rule, as shown in the following formula: (20) (21) In the formula, This represents the k-th row and j-th column of the coefficient matrix H. The basis matrix W represents the first... The elements in row and k-th column are used to continuously and alternately adjust the W and H matrices according to the iterative update rule in the above formula, reducing the difference between V and WH, so that the objective function eventually converges, and the W and H matrices after iteration are output, and the NMF decomposition ends.
6. The method for detecting respiratory diseases in group-raised pigs under conditions of balanced feed nutrition as described in claim 1, characterized in that, The time-domain waveforms of each cough sound in the superimposed sounds of multiple pig coughs in step 4 include: The recovery of each cough signal is accomplished using time-frequency masking, and then the time-domain signal is obtained through inverse Fourier transform. The specific steps for reconstructing the source signal are as follows: (1) Calculate the spectrum of a single source: For the k-th source (k=1,2,...,k), reconstruct its time-frequency domain amplitude. : (22) In the formula, Let be the spectral basis vector of the k-th source. Let k be the time activation vector of the k-th source; (2) Generate mask: Calculate the proportion of the energy of the k-th source signal to the total energy of the mixed signal at each time frequency point: (23) in The value range is [0,1]; (3) Separating the spectrum of complex numbers: using the mask obtained in the previous step Modify the complex time spectrum of the mixed audio When separating complex numbers, the spectrum This preserves the phase information of the original signal; (4) Recovering the time-domain signal: Using ISTFT to extract the time-domain signal The signal is converted to a time-domain signal while ensuring that the parameters are completely consistent with the STFT to ensure that the time-domain signal is reconstructed.
