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 the example code I was able to use to capture the data. https://www.mathworks.com/help/matlab/import_export/collect-data-from-fitness-monitoring-devices.html
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
2021년 2월 12일
편집: Walter Roberson
2021년 2월 12일
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 Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!