How to get Timestamp data with heartrate sensor

Hi,
I'm working with a Polar OH1 heartrate monitor and trying to capture HR data. Trying to figure out if I can capture it and also get a timestamp on when it was captured.
This is what my code looks like:
blelist
belt = ble("Polar OH1 7C7B3E2E")
hr = characteristic(belt, "Heart Rate", "Heart Rate Measurement")
data = read(hr)
for loop = 1:3000
flag = uint8(data(1));
% Get the first bit of the flag, which indicates the format of the heart rate value
heartRateValueFormat = bitget(flag, 1);
if heartRateValueFormat == 0
% Heart rate format is uint8
heartRate = data(2);
else
% Heart rate format is uint16
heartRate = double(typecast(uint8(data(2:3)), 'uint16'));
end
fprintf('Heart rate measurement: %d(bpm)\n', heartRate);
end
If anyone can tell me how to get this to write continously to a csv file and also get the data timestamped, that would be extremely helpful!
Thanks!

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 12 日
編集済み: Walter Roberson 2021 年 2 月 12 日

0 投票

fopen() the output file at the top. Put in an onCleanup to close the file.
When you have data,
fprintf(fid, '%s,%d\n', datetime('now', 'Format', 'yyyy-MM-dd HH:mm:ss.SSS')), heartRate);
However you should consider fetching the datetime immediately after reading the data.
And reading the data should probably be done inside the loop.
Also, please sanity-check the uint16 case, as you might need to swap bytes.

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

製品

リリース

R2020b

質問済み:

2021 年 2 月 12 日

編集済み:

2021 年 2 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by