MATLAB Code for Oura

THis was useful:

COnvert from curl to matlab

 

 

function %% Web Access using Data Import and Export API

params = {

'start_date' '2022-09-01'

'end_date' '2022-10-19'

};

baseURI = 'https://api.ouraring.com/v2/usercollection/daily_activity';

uri = [baseURI '?' char(join(join(params, '='), '&'))];

options = weboptions('HeaderFields', {'Authorization' 'Bearer 74MH2HX4JEUCRBRH7O3VOAHG5RHUI3HN'});

DA = webread(uri, options);

baseURI = 'https://api.ouraring.com/v2/usercollection/hearrate';

uri = [baseURI '?' char(join(join(params, '='), '&'))];

options = weboptions('HeaderFields', {'Authorization' 'Bearer 74MH2HX4JEUCRBRH7O3VOAHG5RHUI3HN'});

HR = webread(uri, options);

N = length(HR.data);

for i = 1:N

t(i) = datetime( datenum8601( R.data(i).timestamp,'T') , 'ConvertFrom','datenum');

y_bpm(i) = HHHR.data(i).bpm;

bpm_source{i} = R.data(i).source;

end

baseURI = 'https://api.ouraring.com/v2/usercollection/sleep';

uri = [baseURI '?' char(join(join(params, '='), '&'))];

options = weboptions('HeaderFields', {'Authorization' 'Bearer 74MH2HX4JEUCRBRH7O3VOAHG5RHUI3HN'});

S = webread(uri, options);

num_days = length(S.data);

sleep = {};

f = figure;

t = tiledlayout(2,1);

ax(1) = nexttile(t);

title(ax(1),'Heart Rate (bpm)')

ax(2) = nexttile(t);

title(ax(2),'HRV')

for d = 1:num_days

sleep{d}.bedtime_start = datetime( datenum8601( S.data(d).bedtime_start,'T') , 'ConvertFrom','datenum');

sleep{d}.bedtime_end = datetime( datenum8601( S.data(d).bedtime_end,'T') , 'ConvertFrom','datenum');

num_hr = length(S.data(d).heart_rate.items);

% HR

tstart = datetime( datenum8601( S.data(d).heart_rate.timestamp,'T') , 'ConvertFrom','datenum');

tstep = duration(0,0,S.data(d).heart_rate.interval);

sleep{d}.hr = timetable(S.data(d).heart_rate.items,'StartTime',tstart,'TimeStep',tstep,...

'VariableNames',{'HR'});

plot(ax(1),sleep{d}.hr.Time,sleep{d}.hr.HR,'-o','MarkerSize',2)

if d == 1

hold(ax(1),'on')

end

% HRV

tstart = datetime( datenum8601( S.data(d).hrv.timestamp,'T') , 'ConvertFrom','datenum');

tstep = duration(0,0,S.data(d).hrv.interval);

sleep{d}.hrv = timetable(S.data(d).hrv.items,'StartTime',tstart,'TimeStep',tstep,...

'VariableNames',{'HRV'});

plot(ax(2),sleep{d}.hrv.Time,sleep{d}.hrv.HRV,'-o','MarkerSize',2)

if d == 1

hold(ax(2),'on')

end

end

end