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!

Antworten (1)

Walter Roberson
Walter Roberson am 12 Feb. 2021
Bearbeitet: Walter Roberson am 12 Feb. 2021

0 Stimmen

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.

Kategorien

Produkte

Version

R2020b

Gefragt:

am 12 Feb. 2021

Bearbeitet:

am 12 Feb. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by