xamarin 如何计算ECG/PPG传感器(AFE 49 I30传感器)的心率计数?

pbpqsu0x  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(147)

我真的知道如何使用PPG/ECG传感器计算心率BPM,我正在尝试下面的代码,并在回答中给予一些新的更新。
我正尝试使用Xamarin表单应用程序使用PPG/ECG传感器***(我使用的是AFE 49 I30传感器)***计算我的心率。

  • 我有一个蓝牙设备和蓝牙设备连接到Xamarin形式的应用程序使用Plugin.BLE包。
  • 连接后,我得到的所有服务和服务的特点的蓝牙设备.
  • 在得到PPG/ECG的特征之后。我得到PPG/ECG的字节数组。现在,我可以做什么来从这个字节数组中得到心率计数?

下面显示了我的代码的一些截图,以获取我的心率的字节数组。

  • PPG使用以下代码获取字节数组数据:

public async void GetPPGLiveData()
        {
            if (App.device != null)
            {
                var temp = App.DeviceDetailsModel.FirstOrDefault(a => a.DeviceService.Id.StartsWith("00005c00"));
                var PPGservices = await App.device.GetServiceAsync(new Guid(temp.DeviceService.Id));

                if (PPGservices != null)
                {
                    var PPGcharacter = temp.DeviceServiceCharacs.FirstOrDefault(a => a.Id.StartsWith("00005c02"));
                    var PPGList = await PPGservices.GetCharacteristicAsync(new Guid(PPGcharacter.Id));

                    PPGList.ValueUpdated += (o, args) =>
                    {
                        var receivedBytes = args.Characteristic.Value;

                        Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(async () =>
                        {
                           //Need to write some Heart Rate calculation Logic.
                            
                        });
                    };
                    await PPGList.StartUpdatesAsync();
                }
            }
        }
  • 使用以下代码获取ECG字节数组数据:
public async void GetECGLiveData()
        {
            if (App.device != null)
            {
                var temp = App.DeviceDetailsModel.FirstOrDefault(a => a.DeviceService.Id.StartsWith("00005c00"));
                var ECGservices = await App.device.GetServiceAsync(new Guid(temp.DeviceService.Id));

                if (ECGservices != null)
                {
                    var ECGcharacter = temp.DeviceServiceCharacs.FirstOrDefault(a => a.Id.StartsWith("00005c01"));
                    var ECGList = await ECGservices.GetCharacteristicAsync(new Guid(ECGcharacter.Id));

                    ECGList.ValueUpdated += (o, args) =>
                    {
                        var receivedBytes = args.Characteristic.Value;

                        Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async () =>
                        {

                            //Need to Write Some calculation logic here.
                        });
                    };
                    await ECGList.StartUpdatesAsync();
                }
                
            }
        }

非常感谢您的关注和参与。

nle07wnf

nle07wnf1#

我已经尝试实现的R-R算法。我使用下面的逻辑代码。

internal static HeartRateReading ReadBuffer(byte[] buffer, int length)
    {
        if (length == 0) return null;

        var ms = new MemoryStream(buffer, 0, length);
        var flags = (HeartRateFlags)ms.ReadByte();
        var isshort = flags.HasFlag(HeartRateFlags.IsShort);
        var contactSensor = (ContactSensorStatus)(((int)flags >> 1) & 3);
        var hasEnergyExpended = flags.HasFlag(HeartRateFlags.HasEnergyExpended);
        var hasRRInterval = flags.HasFlag(HeartRateFlags.HasRRInterval);
        var minLength = isshort ? 3 : 2;

        if (buffer.Length < minLength) return null;

        var reading = new HeartRateReading
        {
            Flags = flags,
            Status = contactSensor,
            BeatsPerMinute = isshort ? ReadUInt16(ms) : ms.ReadByte()
        };

        if (hasEnergyExpended)
        {
            reading.EnergyExpended = ReadUInt16(ms);
        }

        if (hasRRInterval)
        {
            var rrvalueCount = (buffer.Length - ms.Position) / sizeof(ushort);
            var rrvalues = new int[rrvalueCount];
            for (var i = 0; i < rrvalueCount; ++i)
            {
                rrvalues[i] = ReadUInt16(ms);
            }

            reading.RRIntervals = rrvalues;
        }

        return reading;
    }
    public static ushort ReadUInt16(Stream stream)
    {
        return (ushort)(stream.ReadByte() | (stream.ReadByte() << 8));
    }

现在我使用上面的代码将R-R间隔作为Int[](Array)。
现在,如何使用R-R间期计算HeartRate BPM?
非常感谢您的关注和参与。

相关问题