A sleep monitoring system and method with dynamic envelope filtering and pressure differential

CN123023866APending Publication Date: 2026-11-03HARBIN ENG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611349521.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-01
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

Existing sleep monitoring technologies suffer from privacy risks, a strong sense of constraint, a high rate of misjudgment, high resource consumption, and high bandwidth requirements, making it difficult to achieve accurate and seamless multi-parameter synchronous monitoring.

Method used

A posture recognition method combining dual-channel pressure differential and frame-level stabilization is adopted, along with adaptive ECG detection using dynamic envelope filtering. A multi-timescale scheduling architecture decouples high-frequency ECG and low-frequency posture tasks, enabling accurate identification of turning events and adaptive heart rate detection.

Benefits of technology

It improves the accuracy of posture judgment and the adaptability of heart rate detection, reduces resource consumption and bandwidth requirements, and ensures the real-time performance and reliability of monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123023866A_ABST
    Figure CN123023866A_ABST
Patent Text Reader

Abstract

The application discloses a sleep monitoring system and method based on dynamic envelope filtering and pressure difference, and belongs to the field of intelligent health monitoring and embedded signal processing. The system comprises piezoelectric film sensors symmetrically arranged on a mattress, a charge conversion circuit, an AD8232 electrocardio acquisition module, an STM32 microcontroller, a Wi-Fi module and an upper computer. The microcontroller adopts a multi-time scale scheduling architecture, and is driven by a 250Hz reference beat to perform electrocardio dynamic envelope tracking and adaptive R wave detection. In addition, posture recognition and turning over counting based on pressure difference are performed in a 100ms period generated by frequency division. Turning over is triggered by stable posture change, and is not counted when leaving the bed. After confirmation, cooling shielding is performed. The electrocardio R wave detection adopts a dynamic envelope and adaptive threshold mechanism, and can adapt to signal amplitude and baseline drift of different individuals without machine learning. The application realizes high robustness, low bandwidth and multi-parameter synchronous sleep monitoring on a resource-limited embedded platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent health monitoring and embedded signal processing technology, and in particular to a non-invasive sleep posture, turning frequency and heart rate monitoring system and method for piezoelectric thin film pressure sensing and electrocardiogram signal acquisition. Background Technology

[0002] Sleep quality is closely related to physiological parameters such as changes in posture, number of times one turns over, and heart rate during sleep. Accurate and imperceptible monitoring of these parameters is of practical significance for sleep assessment and health care.

[0003] Currently, sleep posture monitoring mainly relies on camera image analysis or wearable devices. Camera solutions pose privacy risks and are affected by ambient light; wearable solutions, due to their restrictive nature, can negatively impact sleep comfort with prolonged use. Regarding pressure detection, solutions exist that place piezoelectric films under the mattress, but most rely on fixed pressure thresholds to determine posture, easily misinterpreting momentary movements such as coughing or brief limb shifts as turning over, and lack effective anti-shake mechanisms.

[0004] In terms of ECG acquisition, common solutions directly upload the raw ECG waveform to a host computer for processing, which requires high wireless transmission bandwidth. Some solutions use fixed thresholds to detect R waves, which is difficult to adapt to differences in signal amplitude among different individuals and baseline drift during sleep. In addition, sleep monitoring requires the simultaneous acquisition of high-frequency ECG signals and low-frequency posture signals. If a single time reference is used, posture processing tasks may consume processor resources, leading to missed ECG features. Summary of the Invention

[0005] The purpose of this invention is to provide a sleep monitoring system and method based on dynamic envelope filtering and pressure differential. It achieves accurate identification of turning-over events by combining dual-channel pressure differential with frame-level anti-shake confirmation, adaptive detection of ECG R waves by dynamic envelope tracking, and decoupling of high-frequency ECG tasks and low-frequency posture tasks on the time axis by using a multi-timescale scheduling architecture. This enables highly robust, low-bandwidth, multi-parameter synchronous sleep monitoring on resource-constrained embedded platforms.

[0006] To achieve the above objectives, this invention provides a sleep monitoring system based on dynamic envelope filtering and pressure differential, comprising two identical detection branches for detecting human sleep posture. Each detection branch includes a piezoelectric thin-film sensor and a charge conversion circuit connected in sequence. The outputs of both detection branches are connected to a microcontroller. An electrocardiogram (ECG) acquisition module is provided to conform to the human body to collect ECG signals and output simulated ECG signals and lead detachment indication signals. The output of the ECG acquisition module is connected to the microcontroller. The ECG acquisition module adopts a three-lead configuration. The microcontroller is connected to a wireless communication module. A host computer communicates wirelessly with the wireless communication module, and the host computer receives and displays monitoring data through the wireless communication module.

[0007] Preferably, the piezoelectric film sensors of the two detection branches are respectively placed on the upper surface of the mattress corresponding to the left and right symmetrical areas of the upper body of the human body, and are used to convert body pressure into charge signals. The charge conversion circuit in the detection branch includes a charge amplifier and a voltage comparator. The charge amplifier is used to convert the charge signal output by the piezoelectric film sensor into an analog voltage signal and output it to the analog-to-digital conversion channel of the microcontroller. The voltage comparator is used to compare the analog voltage signal with a preset reference voltage to determine whether the pressure exceeds a set threshold, and outputs a high-level or low-level digital level signal to the general-purpose input / output port of the microcontroller. The charge amplifier adopts a high input impedance operational amplifier.

[0008] A sleep monitoring method based on dynamic envelope filtering and pressure differential, applied to the aforementioned system, includes the following steps: S1. Collect charge signals on the mattress corresponding to the left and right areas of the upper body of the human body through two piezoelectric film sensors, and convert them into analog voltage signals; S2. The microcontroller sets the first sampling frequency as the reference beat. In each reference beat, it performs analog-to-digital conversion on the two analog voltage signals and the analog ECG signal. After normalizing the raw ADC values, it obtains the left and right pressure values ​​L and R. It then performs digital filtering and dynamic envelope update on the converted digital ECG signal. S3. The first sampling frequency is downsampled by a frequency divider counter. When the count value reaches the preset frequency division ratio, a low-frequency task cycle is triggered. During the low-frequency task cycle, the difference between the average values ​​of the two analog voltage samples is calculated. The sleep posture is determined by comparing the difference with the preset lateral judgment threshold. The posture confirmed by anti-shake is taken as the stable posture. The stable posture includes three postures: left lateral, right lateral, and supine. When the stable posture changes to another stable posture, it is recorded as a turning over. The turning over is not counted when the person is out of bed. The turning over is counted when the person is supine. After the turning over is confirmed, the cooling timer is started. The lead detachment indication signal is read and software anti-shake processing is performed. After the lead detachment is determined, the envelope update is stopped, the heart rate is marked as invalid and the previous heart rate value is frozen. The envelope estimation during the lead detachment is retained and not reset. After recovery, the envelope value before the detachment is used to continue the calculation. S4. Perform digital power frequency notch filtering and baseline drift high-pass filtering on the converted digital ECG signal, dynamically track the ECG signal envelope and detect the R-wave peak based on an adaptive threshold, and obtain the output heart rate based on the interval between adjacent R waves after validity screening and median filtering. The signal-to-noise ratio of the output heart rate is not lower than the preset threshold. If the time elapsed since the last valid heartbeat exceeds the preset timeout during normal detection, the heart rate is marked as invalid and cleared to zero. S5. The data packet containing posture, number of turning over, heart rate, left and right pressure values ​​L and R, and lead dislodgement status is sent to the host computer for display via the wireless communication module.

[0009] Preferably, in step S3, the process of determining the current attitude is as follows: The average of the first and second analog voltage samples from the ADC are obtained respectively, and the difference D is calculated; Let the minimum effective threshold be... The lateral judgment threshold is First, determine whether the person has left the bed: if the average values ​​of both sampling paths are lower than [the specified value]... If the pressure is positive, it is determined to be out of bed; otherwise, it indicates that at least one sensor has detected effective pressure, and the sleep posture is determined based on the pressure difference D between the two sensors: if... If so, it is determined to be a left lateral decubitus position; if If so, it is determined to be a right lateral decubitus position; if If so, it is determined to be lying flat.

[0010] Preferably, in step S3, the anti-shake confirmation mechanism is as follows: when a change in attitude from one stable attitude to another is detected, candidate counting is initiated to accumulate the duration of the new stable attitude to distinguish between a true rollover and a transient disturbance; in each subsequent low-frequency task cycle, it is repeatedly checked whether the current attitude is still the stable attitude after the change: if the current attitude remains the stable attitude after the change and the duration lasts for one low-frequency task cycle, the candidate count is incremented once, indicating that the stable attitude has been stable for one confirmation cycle; if the current attitude reverts to the original stable attitude before the change, it indicates that the change was only a transient disturbance and not a true rollover, the candidate count is cleared, and the candidate is abandoned; if the current attitude changes to another different stable attitude, the candidate... The counter is reset to 1, and the changed stable posture is used as the new target to be confirmed, and the accumulation starts again. When the candidate count accumulates to a number of consecutive low-frequency task cycles, a valid rollover is confirmed, the total number of rollovers is incremented by one, and a cooldown timer is started. During the cooldown period of the cooldown timer, no posture change is responded to, and the rollover count is not updated to avoid the same rollover event being counted repeatedly. If the stable posture after the confirmed rollover is left lateral recumbent, the left rollover count is incremented by one; if it is right lateral recumbent, the right rollover count is incremented by one. If the stable posture change path is from left lateral recumbent to right lateral recumbent or from right lateral recumbent to left lateral recumbent, the stable posture change through the supine transition is counted as one rollover. The state of getting out of bed is not a stable posture that can be counted as a rollover and is not counted in the rollover count.

[0011] Preferably, in step S4, the dynamic envelope update method for the ECG signal is as follows: at each sampling point of the ECG signal, the filtered ECG signal value is compared with the currently maintained maximum value M and minimum value m. If it is greater than the maximum value M, the maximum value M is updated to the current filtered value; if it is less than the minimum value m, the minimum value m is updated to the current filtered value; if it is between the maximum value M and the minimum value m, a preset attenuation factor is used to perform attenuation regression on the maximum value M and the minimum value m respectively, so that the extreme value of the filtered value slowly falls back over time, avoiding the envelope from being locked at the historical extreme value for a long time due to slow signal changes. Here, the maximum value M represents the highest point of the currently tracked signal, and the minimum value m represents the lowest point of the currently tracked signal. The update formula for each sampling point is: ; In the above formula, This represents the filtered ECG signal value at the current sampling point. and These represent the maximum and minimum values ​​after the current sampling point has been updated. and These represent the maximum and minimum values ​​of the previous sampling point, respectively. 0.995 is the preset attenuation factor. max means taking the larger of the two values, and min means taking the smaller of the two values. The adaptive amplitude threshold is the sum of the current minimum value and a preset ratio of the current signal amplitude, corresponding to the formula: ; In the above formula, This represents the adaptive amplitude threshold for the current sampling point. This is the current minimum value. This is the current maximum value, and 0.6 is the preset scaling factor. When the filtered signal crosses the adaptive amplitude threshold from bottom to top and the interval between it and the previous effective heartbeat is greater than the preset physiological refractory period, it is determined to be an R-wave peak. Crossing from bottom to top means that the filtered signal value changes from below the adaptive amplitude threshold to above the adaptive amplitude threshold. The time interval between adjacent R waves is recorded as the instantaneous heartbeat interval. The instantaneous heartbeat interval is compared with the preset physiological range and outliers are discarded. The effective values ​​are stored in the first-in-first-out buffer. When the number of effective samples in the buffer reaches the preset minimum number of samples, the median is taken and outliers are removed. When the signal-to-noise ratio is not lower than the signal-to-noise ratio threshold, it is converted into heartbeats per minute as the output heart rate.

[0012] Preferably, in step S4, the second method for dynamically updating the ECG signal envelope is as follows: the envelope E is used as the moving average of the squared first-order difference of the filtered signal. The first-order difference refers to the difference between the filtered value at the current sampling point and the filtered value at the previous sampling point, used to measure the instantaneous rate of change of the signal. The squared first-order difference is used to convert the change into a positive number for subsequent moving average calculation. The moving average is the average of the most recent squared first-order difference values, used to smooth the signal envelope and eliminate the influence of instantaneous jumps. The filtered ECG signal is tracked for both signal level S and noise level N. The signal level S reflects the overall strength of the current ECG signal and is updated when a peak in the heartbeat envelope is detected. The noise level N reflects the background noise level in the current ECG signal and is updated when the envelope is lower than the signal level. By distinguishing between the signal level and the noise level, the signal-to-noise ratio adaptive threshold adjustment is achieved. The corresponding formula for the dynamic threshold is: The lower limit is not less than 1.0; In the above formula, This represents the dynamic threshold of the current sampling point. Indicates the noise level at the current sampling point. This indicates the signal level at the current sampling point. 0.35 is a preset scaling factor used to control the threshold position between the signal level and the noise level. During lead detachment, S and N are frozen and not updated, maintaining the values ​​from the last update before lead detachment. These values ​​will continue to be used after the lead is restored, without needing to be rebuilt from scratch.

[0013] Preferably, in step S4, the difference equation used by the 50Hz second-order IIR notch filter to filter out 50Hz power frequency interference is: ; in, Input the value for the current sampling point. Input the value for the previous sampling point. Input values ​​for the first two sampling points. Output value for the current sampling point. The output value of the previous sampling point. The values ​​are the output values ​​for the first two sampling points. 0.9229, -0.5704, and 0.8459 are the filter coefficients calculated based on the 250Hz sampling frequency and the 50Hz notch filter center frequency. The difference equation for a 0.5Hz first-order IIR high-pass filter used to remove low-frequency baseline drift in ECG signals is: ; in, Input the value for the current sampling point. Input the value for the previous sampling point. Output value for the current sampling point. The output value is the previous sampling point, and 0.9937 is the filter coefficient calculated based on the 250Hz sampling frequency and the 0.5Hz cutoff frequency. The difference equation for a 15Hz first-order IIR low-pass filter used to suppress electromyographic noise is: ; in, Input the value for the current sampling point. Output value for the current sampling point. The output value is the value of the previous sampling point, and 0.3 and 0.7 are the filter coefficients calculated based on the 250Hz sampling frequency and the 15Hz cutoff frequency. The microcontroller uses the real millisecond timestamp generated by the hardware timer as the time reference. The calculation of the low-frequency task cycle and the adjacent effective heartbeat interval are both based on the real time difference, directly calculating the timestamp difference between the two moments, rather than based on the cumulative assumption of the sampling interval.

[0014] Compared with the prior art, the beneficial effects of the present invention are as follows: (1) The attitude judgment adopts a dual-channel pressure differential algorithm, combined with frame-level anti-shake confirmation and cooling protection, which effectively distinguishes between real turning over and instantaneous actions, resulting in a low false alarm rate; the state of leaving the bed is not included in the turning over count, preventing the transition between getting on and off the bed from interfering with the turning over statistics.

[0015] (2) The heart rate detection adopts dynamic envelope tracking and adaptive threshold mechanism. The basic scheme updates the upper and lower limits of the envelope with extreme value decay, while the improved scheme tracks the signal level and noise level in dual channels. The threshold is automatically adjusted with amplitude and noise to adapt to different individuals and time periods. It also has a signal-to-noise ratio output threshold to eliminate low-quality detection.

[0016] (3) A multi-timescale scheduling architecture is adopted, and the high-frequency ECG task and the low-frequency attitude task are decoupled on the time axis to ensure the real-time performance of ECG feature extraction.

[0017] (4) Heart rate calculation is completed on the microcontroller side. The calculation results are packaged with attitude and pressure data into ASCII key-value pairs for reporting. The bandwidth requirement is low, and the frame delimiter is a newline character, which has the ability to recover from packet loss.

[0018] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0019] Figure 1 This is a block diagram of the overall structure of a sleep monitoring system based on dynamic envelope filtering and pressure differential according to the present invention. Figure 2 This is a schematic diagram of the charge conversion circuit in an embodiment of the present invention; Figure 3 This is a schematic diagram of the host computer display interface according to an embodiment of the present invention; Figure 4 This is a flowchart of the main program for multi-timescale task scheduling in an embodiment of the present invention; Figure 5 This is a flowchart of the pressure differential attitude recognition and rollover anti-shake state machine in an embodiment of the present invention; Figure 6 This is a flowchart of the signal processing for dynamic envelope filtering heart rate detection in an embodiment of the present invention. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Specific model specifications need to be selected and determined according to the actual specifications of the device, etc. The specific selection calculation method adopts existing technology in the art, and therefore will not be described in detail.

[0021] Example like Figures 1-6 As shown, the present invention provides a sleep monitoring system and method based on dynamic envelope filtering and pressure differential.

[0022] See Figure 1 The system comprises two detection branches, each including a piezoelectric thin-film sensor and a charge conversion circuit connected in sequence, to collect pressure signals from the left and right sides of the human body, respectively. The outputs of both detection branches are connected to a microcontroller. The piezoelectric thin-film sensor uses a polyvinylidene fluoride piezoelectric thin film, which outputs a charge signal after sensing body pressure.

[0023] The ECG acquisition module is used to collect ECG signals by fitting snugly against the human body and output simulated ECG signals and lead detachment indication signals. The output of the ECG acquisition module is connected to a microcontroller. The ECG acquisition module uses a three-lead configuration (RA, LA, RL). RA and LA form the ECG signal measurement channel, and RL serves as the right leg drive reference electrode to suppress common-mode interference. The microcontroller is connected to a wireless communication module. The host computer communicates wirelessly with the wireless communication module to receive and display monitoring data.

[0024] After sensing body pressure, the piezoelectric film outputs a charge signal, which is converted into an analog voltage by a charge amplifier. This analog voltage has two destinations: one is sent to a voltage comparator, which outputs a high level (approximately 2V) when the voltage exceeds 1.5V and a low level (approximately 0V) when it is below 1.5V, forming a digital level signal that is transmitted to the microcontroller's GPIO pin; the other is simultaneously sent to the microcontroller's ADC for 12-bit sampling (range 0~4095, reference voltage 3.3V).

[0025] The microcontroller normalizes the raw ADC value by dividing it by 10 to a range of 0–409, and then performs two stages of software filtering to obtain the left and right channel pressure values ​​L and R. The two stages of software filtering include a first-order infinite impulse response low-pass filter and a hysteresis-based level lockout. The low-pass filter eliminates high-frequency noise, and the level lockout determines the output as high when it is higher than a high level and latches it, and determines it as low when it is lower than a low level and latches it. During latching, intermediate transitions are ignored, stabilizing the output in high and low states to eliminate frequent transitions caused by power frequency noise.

[0026] See the structure of each charge conversion circuit. Figure 2The circuit consists of a charge amplification stage and a voltage comparator stage. The charge amplification stage is centered around a high-input-impedance operational amplifier. Its output and inverting input are connected in parallel by a feedback capacitor and a bias resistor, forming a feedback loop. The bias resistor, with a value in the tens of megaohms range, controls the low-frequency response of the charge amplifier, balancing signal bandwidth and noise suppression requirements. The feedback capacitor's value must balance gain and stability; the piezoelectric film output has a small charge, requiring high gain, but an excessively small capacitor value can lead to circuit instability. One voltage input is connected to the microcontroller's analog-to-digital converter (ADC) channel, and the other is connected to the comparator's non-inverting input. The comparator's inverting input is connected to a reference voltage of approximately 1.5V, generated by a voltage divider between the power supply and ground using two resistors connected in series. This reference voltage is determined based on the signal amplitude range and the microcontroller's ADC input range. The two analog outputs are connected to PC0 and PC2, respectively, and the digital outputs are connected to PC1 and PC3.

[0027] See the host computer interface. Figure 3 The ECG acquisition module uses a three-lead electrode configuration (RA, LA, RL), with the output connected to PA1. Lead detachment (LO+ and LO-) is connected to PA2 and PA3, respectively. The wireless communication module communicates with the microcontroller via USART3. The system is powered by a USB interface.

[0028] See Figure 4 The microcontroller operates with a first sampling frequency as the reference beat. In this embodiment, the first sampling frequency is 250Hz, corresponding to a 4ms reference beat. Within each beat, analog-to-digital conversion is performed sequentially on PC0, PC2, and PA1. Digital filtering and dynamic envelope updates are performed on the ECG signal, and the data frame is sent to the wireless communication module. Simultaneously, a frequency divider counter is maintained, incrementing by 1 every 4ms. When the counter value reaches a preset frequency division ratio, a low-frequency task cycle is triggered. In this embodiment, the preset frequency division ratio is 25, corresponding to a 100ms low-frequency task cycle. After performing posture recognition and rollover stabilization, the counter is reset to zero. The microcontroller uses a real millisecond timestamp generated by a hardware timer as the time reference. The calculation of the low-frequency task cycle and the interval between adjacent effective heartbeats is based on the real time difference, rather than the cumulative assumption of the reference beat.

[0029] See Figure 5 Every 100ms cycle, the average left and right pressure values ​​L and R (values ​​after analog-to-digital conversion, software filtering, and normalization, ranging from 0 to 409) are acquired, and the difference D = LR is calculated. The current attitude is determined within the range of 0 to 409 using the following criteria: lateral judgment threshold Ts (10 in this embodiment) and minimum effective threshold Tv (5 in this embodiment). First, it is determined whether the patient is off-bed: if both L and R are below Tv, it is determined to be off-bed and marked as off-bed state; otherwise, it indicates that at least one sensor has detected effective pressure. At this time, the current attitude is determined based on the pressure difference D between the two sensors: if... If so, it is determined to be a left lateral decubitus position; if If so, it is determined to be a right lateral decubitus position; if If so, it is determined to be lying flat.

[0030] Turning over is triggered by a change in stable posture. Stable postures include left lateral decubitus, right lateral decubitus, and supine positions; the state of being out of bed is not counted as a turning over. When a change in the current posture from one stable posture to another is detected, the anti-shake counter is activated, and the duration of the new stable posture is accumulated to distinguish between a genuine turning over and a momentary disturbance. In each subsequent low-frequency task cycle, it is repeatedly checked whether the current posture is still the stable posture after the change: if the current posture remains the stable posture after the change and the duration lasts for one low-frequency task cycle, the candidate count is incremented once, indicating that the stable posture has been stable for one confirmation cycle; if the current posture reverts to the original stable posture before the change, it indicates that this change was only a momentary disturbance and not a genuine turning over, the candidate count is reset to zero, and this candidate is discarded; if the current posture changes to another different stable posture, the anti-shake counter is reset to 1, and the changed stable posture is used as the new target to be confirmed, and the accumulation starts again. Maintaining the state after the change for five consecutive 100ms cycles confirms a turning over, the total count is incremented by one, and a 1000ms cooldown period begins. During the cooldown period, new transitions are not responded to. If the stable posture after turning over is confirmed to be left lateral decubitus, left turning over is counted as one; if it is right lateral decubitus, right turning over is counted as one. If the stable posture change path is from left lateral decubitus to right lateral decubitus via supine or from right lateral decubitus to left lateral decubitus via supine, the stable posture change via supine transition is counted as one turning over. The system continuously monitors during operation by default. The state of being out of bed is not considered a stable posture for turning over and is not included in the turning over count. When moving from being out of bed to returning to bed, the old stable posture is the state of being out of bed, and this transition is excluded, so returning to bed will not accidentally trigger turning over; when moving from other postures to being out of bed, the new posture is the state of being out of bed, and it is also not counted as turning over.

[0031] See Figure 6 The heart rate detection process is as follows: the raw ECG signal is filtered by a 50Hz notch filter, a 0.5Hz baseline high-pass filter, and a 15Hz low-pass filter. The 50Hz second-order IIR notch filter is used to filter out 50Hz power frequency interference; its difference equation is: ; A 0.5Hz first-order IIR high-pass filter is used to remove low-frequency baseline drift in ECG signals. Its difference equation is: ; A 15Hz first-order IIR low-pass filter is used to suppress electromyographic noise. Its difference equation is: ; At each sampling point, the filtered value is compared with the current extreme value. The update rule for each sampling point is as follows: if the current filtered value is greater than the maximum value M, then the maximum value M is updated to the current filtered value; if the current filtered value is less than the minimum value m, then the minimum value m is updated to the current filtered value; if the current filtered value is between the maximum value M and the minimum value m, then attenuation regression is performed on the maximum value M and the minimum value m respectively using a preset attenuation factor. In this embodiment, the preset attenuation factor is 0.995, and the update formula for each sampling point is: ; The dynamic threshold is calculated by adding the minimum value to a preset percentage of the amplitude. In this embodiment, the preset percentage is 60%, and the formula is as follows: ; The threshold is recalculated in real time based on the current envelope at each sampling point, not fixed once after the R wave. A heartbeat is determined when the signal crosses the threshold and meets the rising pattern, and the time since the last valid heartbeat is greater than the preset physiological refractory period. In this embodiment, the preset physiological refractory period is 300ms. The physiological refractory period refers to the physiological characteristic that the heart cannot be excited again for a short period of time after one excitation. It is used to prevent the T wave in the electrocardiogram signal from being misjudged as an R wave and to calculate the heartbeat interval. Intervals are filtered within a preset physiological range, which in this embodiment is 333ms to 1500ms. They are stored in a first-in-first-out (FIFO) buffer of length 5. The FIFO buffer is a storage area that stores data in the order it is stored. When new data is stored, if the buffer is full, the oldest data is discarded. Whenever a valid interval is stored, the median is recalculated to convert the heart rate. When the number of valid samples reaches the preset minimum number of samples (e.g., 2) and the signal-to-noise ratio is not lower than the preset threshold, the heart rate is output. In this embodiment, the signal-to-noise ratio threshold is 1.5. The signal-to-noise ratio is the ratio of signal to noise and is used to measure the quality of the electrocardiogram signal. When the number of valid samples reaches the preset outlier detection threshold (e.g., 3), the newly added intervals are outlier removed. If the deviation from the median exceeds a preset proportion (e.g., 35%), they are discarded.

[0032] The improved scheme uses a dual-channel approach for extreme value tracking, employing both signal level S and noise level N. It no longer maintains the maximum and minimum values ​​of the scalar, but instead uses the moving average of the squared first-order difference of the filtered signal as the envelope E. ; ; Update S during heartbeat: rest Update N: Dynamic threshold value: The lower limit of the dynamic threshold is no less than 1.0. If the calculated dynamic threshold is less than 1.0, then 1.0 is taken as the dynamic threshold to avoid noise being misjudged as a heartbeat due to an excessively low dynamic threshold. S and N only change during heartbeat or resting events. Although the threshold is recalculated point by point, it actually only changes when the event occurs.

[0033] Regarding lead detachment, 200ms of image stabilization is applied to PA2 and PA3. Upon confirmation of detachment, envelope updates are stopped, the heart rate is immediately marked as invalid, and the previous heart rate value is frozen. The envelope estimate is retained without resetting. After recovery, the calculation continues using the envelope value before detachment, without the need to rebuild the baseline, thus avoiding measurement delays caused by reinitialization. During normal testing, if more than 5 seconds have passed since the last valid heartbeat, the heart rate is marked as invalid and reset to zero.

[0034] For data communication, the microcontroller encapsulates the posture code, number of rolls, heart rate, left and right channel pressure values ​​(L and R), and lead detachment flags into ASCII key-value pairs, separated by commas and ending with a newline character, and sends them to the host computer via the wireless communication module. The host computer receives the data in TCP mode, performs a completeness check, and then pushes it into a 500-point circular buffer. An 80ms timer triggers waveform redrawing to display the pressure waveform and ECG waveform. Simultaneously, a label control displays the posture, number of rolls, and heart rate values.

[0035] The system is powered by a 5V USB interface, which is converted to the voltage required by each module by an onboard voltage regulator.

[0036] Therefore, the present invention adopts a dynamic envelope filtering and pressure differential sleep monitoring system and method as described above. By combining dual-channel pressure differential with frame-level anti-shake confirmation and cooling protection, it achieves accurate identification of turning-over events. Through dynamic envelope tracking, it achieves adaptive detection of ECG R waves. Through a multi-timescale scheduling architecture, it achieves decoupling of high-frequency ECG tasks and low-frequency posture tasks. Thus, it achieves highly robust, low-bandwidth, multi-parameter synchronous sleep monitoring on resource-constrained embedded platforms. It has high accuracy and reliability, and is low in cost and easy to promote.

[0037] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.

Claims

1. A sleep monitoring system based on dynamic envelope filtering and pressure differential, characterized in that: It includes two identical detection branches for detecting human sleep posture. Each detection branch includes a piezoelectric thin film sensor and a charge conversion circuit connected in sequence. The output of both detection branches is connected to a microcontroller. An ECG acquisition module is configured to fit the human body to collect ECG signals and output simulated ECG signals and lead detachment indication signals. The output of the ECG acquisition module is connected to a microcontroller. The ECG acquisition module adopts a three-lead configuration. The microcontroller is connected to a wireless communication module. A host computer is configured to communicate wirelessly with the wireless communication module, and the host computer receives and displays monitoring data through the wireless communication module.

2. The sleep monitoring system based on dynamic envelope filtering and pressure differential as described in claim 1, characterized in that: The piezoelectric thin-film sensors of the two detection branches are respectively placed on the upper surface of the mattress corresponding to the left and right symmetrical areas of the upper body of the human body, and are used to convert body pressure into charge signals. The charge conversion circuit in each detection branch includes a charge amplifier and a voltage comparator. The charge amplifier is used to convert the charge signal output by the piezoelectric thin-film sensor into an analog voltage signal and output it to the analog-to-digital conversion channel of the microcontroller. The voltage comparator is used to compare the analog voltage signal with a preset reference voltage to determine whether the pressure exceeds a set threshold, and outputs a high-level or low-level digital level signal to the general-purpose input / output port of the microcontroller. The charge amplifier adopts a high input impedance operational amplifier.

3. A sleep monitoring method based on dynamic envelope filtering and pressure difference, applied to the sleep monitoring system based on dynamic envelope filtering and pressure difference as described in any one of claims 1 to 2, characterized in that, Includes the following steps: S1. Collect charge signals on the mattress corresponding to the left and right areas of the upper body of the human body through two piezoelectric thin film sensors, and convert them into analog voltage signals; S2. The microcontroller sets the first sampling frequency as the reference beat. In each reference beat, it performs analog-to-digital conversion on the two analog voltage signals and the analog ECG signal. After normalizing the raw ADC values, it obtains the left and right pressure values ​​L and R. It then performs digital filtering and dynamic envelope update on the converted digital ECG signal. S3. The first sampling frequency is downsampled by a frequency divider counter. When the count value reaches the preset frequency division ratio, a low-frequency task cycle is triggered. During the low-frequency task cycle, the difference between the average values ​​of the two analog voltage samples is calculated. The sleep posture is determined by comparing the difference with the preset lateral judgment threshold. The posture confirmed by anti-shake is taken as the stable posture. The stable posture includes three postures: left lateral, right lateral, and supine. When the stable posture changes to another stable posture, it is recorded as a turning over. The turning over is not counted when the person is out of bed. The turning over is counted when the person is supine. After the turning over is confirmed, the cooling timer is started. The lead detachment indication signal is read and software anti-shake processing is performed. After the lead detachment is determined, the envelope update is stopped, the heart rate is marked as invalid and the previous heart rate value is frozen. The envelope estimation during the lead detachment is retained and not reset. After recovery, the envelope value before the detachment is used to continue the calculation. S4. Perform digital power frequency notch filtering and baseline drift high-pass filtering on the converted digital ECG signal, dynamically track the ECG signal envelope and detect the R-wave peak based on an adaptive threshold, and obtain the output heart rate based on the interval between adjacent R waves after validity screening and median filtering. The signal-to-noise ratio of the output heart rate is not lower than the preset threshold. During normal detection, if the time since the last valid heartbeat exceeds the preset timeout period, the heart rate is marked as invalid and cleared to zero. S5. The data packet containing posture, number of turning over, heart rate, left and right pressure values ​​L and R, and lead dislodgement status is sent to the host computer for display via the wireless communication module.

4. The sleep monitoring method based on dynamic envelope filtering and pressure difference according to claim 3, characterized in that: In step S3, the process of determining the current attitude is as follows: The average of the first and second analog voltage samples from the ADC are obtained respectively, and the difference D is calculated; Let the minimum effective threshold be... The lateral judgment threshold is First, determine whether the person has left the bed: if the average values ​​of both sampling paths are lower than [the specified value]... If the pressure is positive, it is determined to be out of bed; otherwise, it indicates that at least one sensor has detected effective pressure, and the sleep posture is determined based on the pressure difference D between the two sensors: if... If so, it is determined to be a left lateral decubitus position; if If so, it is determined to be a right lateral decubitus position; if If so, it is determined to be lying flat.

5. The sleep monitoring method based on dynamic envelope filtering and pressure difference according to claim 3, characterized in that: In step S3, the anti-shake confirmation mechanism is as follows: When a change in attitude from one stable attitude to another is detected, candidate counting is initiated to accumulate the duration of the new stable attitude to distinguish between a true rollover and a transient disturbance. In each subsequent low-frequency task cycle, it is repeatedly checked whether the current attitude is still the stable attitude after the change: if the current attitude remains the stable attitude after the change and the duration lasts for one low-frequency task cycle, the candidate count is incremented once, indicating that the stable attitude has been stable for one confirmation cycle; if the current attitude reverts to the original stable attitude before the change, it indicates that the change was only a transient disturbance and not a true rollover, the candidate count is cleared, and the candidate is discarded; if the current attitude changes to another different stable attitude, the candidate count... The counter is reset to 1, and the changed stable posture is used as the new target to be confirmed, and the accumulation starts again. When the candidate count accumulates to a number of consecutive low-frequency task cycles, a valid rollover is confirmed, the total number of rollovers is incremented by one, and a cooldown timer is started. During the cooldown period of the cooldown timer, no posture change is responded to, and the rollover count is not updated to avoid the same rollover event being counted repeatedly. If the stable posture after the confirmed rollover is left lateral recumbent, the left rollover count is incremented by one; if it is right lateral recumbent, the right rollover count is incremented by one. If the stable posture change path is from left lateral recumbent to right lateral recumbent or from right lateral recumbent to left lateral recumbent, the stable posture change through the supine transition is counted as one rollover. The state of getting out of bed is not a stable posture that can be counted as a rollover and is not counted in the rollover count.

6. The sleep monitoring method based on dynamic envelope filtering and pressure difference according to claim 3, characterized in that: In step S4, the dynamic envelope update method for the ECG signal is as follows: at each sampling point of the ECG signal, the filtered ECG signal value is compared with the currently maintained maximum value M and minimum value m respectively. If it is greater than the maximum value M, the maximum value M is updated to the current filtered value. If the value is less than the minimum value m, then the minimum value m is updated to the current filter value; if the value is between the maximum value M and the minimum value m, then a pre-defined attenuation factor is used to perform attenuation regression on the maximum value M and the minimum value m respectively, so that the extreme value of the filter value slowly falls back over time, avoiding the envelope from being locked at the historical extreme value for a long time due to slow signal changes. Here, the maximum value M represents the highest point of the currently tracked signal, and the minimum value m represents the lowest point of the currently tracked signal. The update formula for each sample point is: ; In the above formula, This represents the filtered ECG signal value at the current sampling point. and These represent the maximum and minimum values ​​after the current sampling point has been updated. and These represent the maximum and minimum values ​​of the previous sampling point, respectively, with 0.995 being the preset attenuation factor. This means taking the larger of the two values. This indicates taking the smaller of the two values; The adaptive amplitude threshold is the sum of the current minimum value and a preset ratio of the current signal amplitude, corresponding to the formula: ; In the above formula, This represents the adaptive amplitude threshold for the current sampling point. This is the current minimum value. This is the current maximum value, and 0.6 is the preset scaling factor. When the filtered signal crosses the adaptive amplitude threshold from bottom to top and the interval between it and the previous effective heartbeat is greater than the preset physiological refractory period, it is determined to be an R-wave peak. Crossing from bottom to top means that the filtered signal value changes from below the adaptive amplitude threshold to above the adaptive amplitude threshold. The time interval between adjacent R waves is recorded as the instantaneous heartbeat interval. The instantaneous heartbeat interval is compared with the preset physiological range and outliers are discarded. The effective values ​​are stored in the first-in-first-out buffer. When the number of effective samples in the buffer reaches the preset minimum number of samples, the median is taken and outliers are removed. When the signal-to-noise ratio is not lower than the signal-to-noise ratio threshold, it is converted into heartbeats per minute as the output heart rate.

7. The sleep monitoring method based on dynamic envelope filtering and pressure difference according to claim 6, characterized in that: In step S4, the second method for updating the dynamic envelope of the ECG signal is as follows: the moving average of the square of the first-order difference of the filtered signal is used as the envelope E. The first-order difference refers to the difference between the filtered value of the current sampling point and the filtered value of the previous sampling point, which is used to measure the instantaneous rate of change of the signal. The square of the first-order difference is used to convert the change into a positive number to facilitate the subsequent moving average calculation. The moving average is the average of the most recent square of the first-order difference, which is used to smooth the signal envelope to eliminate the influence of instantaneous jumps. The filtered ECG signal is tracked for both signal level S and noise level N. Signal level S reflects the overall strength of the current ECG signal and is updated when a peak in the heartbeat envelope is detected. Noise level N reflects the background noise level in the current ECG signal and is updated when the envelope is lower than the signal level. By distinguishing between signal and noise levels, an adaptive threshold adjustment for the signal-to-noise ratio is achieved. The formula for the dynamic threshold is: The lower limit is not less than 1.0; In the above formula, This represents the dynamic threshold of the current sampling point. Indicates the noise level at the current sampling point. This indicates the signal level at the current sampling point. 0.35 is a preset scaling factor used to control the threshold position between the signal level and the noise level. During lead detachment, S and N are frozen and not updated, maintaining the values ​​from the last update before lead detachment. These values ​​will continue to be used after the lead is restored, without needing to be rebuilt from scratch.

8. The sleep monitoring method based on dynamic envelope filtering and pressure difference according to claim 3, characterized in that: In step S4, the difference equation used by the 50Hz second-order IIR notch filter to filter out 50Hz power frequency interference is: ; in, Input the value for the current sampling point. Input the value for the previous sampling point. Input values ​​for the first two sampling points. Output value for the current sampling point. The output value of the previous sampling point. The values ​​are the output values ​​for the first two sampling points. 0.9229, -0.5704, and 0.8459 are the filter coefficients calculated based on the 250Hz sampling frequency and the 50Hz notch filter center frequency. The difference equation for a 0.5Hz first-order IIR high-pass filter used to remove low-frequency baseline drift in ECG signals is: ; in, Input the value for the current sampling point. Input the value for the previous sampling point. Output value for the current sampling point. The output value is the previous sampling point, and 0.9937 is the filter coefficient calculated based on the 250Hz sampling frequency and the 0.5Hz cutoff frequency. The difference equation for a 15Hz first-order IIR low-pass filter used to suppress electromyographic noise is: ; in, Input the value for the current sampling point. Output value for the current sampling point. The output value is the value of the previous sampling point, and 0.3 and 0.7 are the filter coefficients calculated based on the 250Hz sampling frequency and the 15Hz cutoff frequency. The microcontroller uses the real millisecond timestamp generated by the hardware timer as the time reference. The calculation of the low-frequency task cycle and the adjacent effective heartbeat interval are both based on the real time difference, directly calculating the timestamp difference between the two moments, rather than based on the cumulative assumption of the sampling interval.