Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
becomeFeedback/createBecomeFeedback.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
102 lines (75 sloc)
3.56 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%---------------------------- | |
% SETUP | |
%---------------------------- | |
clear | |
close all | |
subName = 'FOK0217'; % change subject id here | |
userName = 'dorothee_poehlchen'; % change your name here | |
gitdir = fullfile('C:\Users\',userName,'Documents\GitHub\becomeFeedback'); | |
basedir = 'O:\Psychophys\Dreem'; | |
diarydir = fullfile(basedir, 'Actigraphy\Raw\Sleep Diaries'); | |
actidir = fullfile(basedir, 'Actigraphy\Raw\Clean Acti Data'); | |
ecgdir = fullfile(basedir, 'Actigraphy\Raw\ECG_RR'); | |
dreemdir = fullfile(basedir,'data\BeCOME' ); | |
outdir = fullfile(basedir,'data\BeCOME_feedback' ); | |
fundir = fullfile(gitdir, 'functions'); | |
libsdir = fullfile(gitdir, 'libs'); | |
addpath(genpath(fundir)); | |
addpath(genpath(libsdir)); | |
%---------------------------- | |
% SETUP | |
%---------------------------- | |
timeStep = minutes(10); % downsample data from 30s to 10m timesteps | |
missingDataThreshold = 6; % missing value if 6 timeSteps at least are 0 | |
timeCenteredMean = hours(24); % moving mean of 24 hours | |
sleepBoutThreshold = 3; % equals to 30 min | |
percTreshold = 15; % everyoriginal datapoint < 15% of moving mean = sleep | |
sleepGapLength = 3; % correlation gap (finds correlation peak) | |
centeredBoutMean = hours(4); % last step from correl data to only 1 onset and offset per night --> 4 hour moving mean | |
meanTreshold = 0.4; % for the moving mean on the binary sleep bouts to smooth them | |
color.sleepSmoothed = [240/255,128/255,128/255]; %salmon color = night sleep episodes | |
color.acti = [112/255,128/255,144/255]; % gray = actigraphy raw data | |
color.sleepCorr = [255/255,215/255,0/255]; % gold = sleep determined by correlation filter --> showing sleep fragmentation | |
color.ecg = [1/255,0/255,1/255]; %sea green = ecg bpm data | |
HRVparams = InitializeHRVparams('ActigraphyECG'); % HRV paraeters for calculation %%% | |
HRVparams.Fs = 500; % sampling frequency | |
HRVparams.windowlength = 300; % Default: 300, seconds | |
HRVparams.increment = 60; % 60 second increments | |
HRVparams.freq.method = 'fft'; % Default: 'lomb' | |
%---------------------------- | |
% Readout actigraphy and ecg | |
%---------------------------- | |
[diarySleepTable, acti, ecgData] = loadSubjectData(diarydir, actidir, ecgdir, subName); | |
if (isempty(ecgData.rr)) && (~isempty(ecgData.rawData)) | |
ecgData = convertToRR (ecgData, HRVparams, subName,ecgdir); % Convert ECG waveform in rr intervals (if its a new data set) | |
HRVMetrics = calcHRVvariables (ecgData.rr,ecgData.t,HRVparams,subName,ecgData.hdr,timeStep); | |
elseif (~isempty(ecgData.rr)) | |
HRVMetrics = calcHRVvariables (ecgData.rr,ecgData.t,HRVparams,subName,ecgData.hdr,timeStep); | |
else | |
HRVMetrics = []; | |
end | |
%---------------------------- | |
% Calculate sleep bouts from actigraphy | |
%---------------------------- | |
calcSleepFromActi | |
%---------------------------- | |
% Plot actigraphy and ecg figures | |
%---------------------------- | |
[figures, ecgFig, sleepECGAll] = ReportFigures(sleepECG,cleanedActi,HRVMetrics); | |
doublePlot = doubleAreaLinePlot(sleepECGAll); | |
%---------------------------- | |
% Get dreem data | |
%---------------------------- | |
[dreemHypno, dreemReport] = loadSubjectDataDreemSD(dreemdir, subName); % if there is no dreem data COMMENT THIS LINE OUT! | |
[allinonePhysSleep] = getPhysiologyDataDreem (dreemReport); | |
nightData = synchronize (dreemHypno,allinonePhysSleep,'first','previous'); | |
figuresNight = dreemNightFigures(nightData); | |
%---------------------------- | |
% Create the final report | |
%---------------------------- | |
createBecomeReport | |
%---------------------------- | |
% Save report and data | |
%---------------------------- | |
mkdir(fullfile(outdir,subName)) | |
save(fullfile(outdir,subName,[subName,'rpt']),'rpt') |