Skip to content

Commit

Permalink
starting to rehash for BIDS processing
Browse files Browse the repository at this point in the history
  • Loading branch information
DoraHermes committed May 31, 2021
1 parent 1304b8d commit db60bb2
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 19 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
BrainBeat
=========



Works on BIDS

- PPG physio files have to have the same name as teh recording with the _recording-PPG tag.
46 changes: 27 additions & 19 deletions physio/physioCreate.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
ppg = ppgInit;
p.ppg = ppg;

resp = respInit;
p.resp = resp;
% resp = respInit;
% p.resp = resp;

p.filename = 'filename';

Expand All @@ -50,8 +50,16 @@


elseif strcmp(varargin{1},'nifti')
ni=varargin{2};
p.filename=ni.fname;
ni = varargin{2};
p.filename = ni.fname;

physio_name = [extractBefore(p.filename,'_bold.nii') '_recording-PPG_physio.tsv.gz'];
if ~exist(physio_name)
error('ERROR: physio file %s does not exist',physio_name)
end
% LEFT OF HERE
% now read the physio file, see whether we need to add
% bids_matlab to path to read tsv.gz files...

% Should add physio file handling to niftiGet(ni,'physio ....');
[fPath,fName] = fileparts(ni.fname);
Expand Down Expand Up @@ -79,39 +87,39 @@

% This the Matlab structure we return.
physio_output = [];
for k=1:length(physioData)
if isequal(physioData(k).name(1:6),'PPGDat');
for kk = 1:length(physioData)
if isequal(physioData(kk).name(1:6),'PPGDat')
physio_output.ppg.name = 'PPG';
physio_output.ppg.srate = 100; % here, we are hardcoding the CNI sampling rate for ECG
physio_output.ppg.rawdata = load(fullfile(UnTarpPhysio_dir,physioData(k).name));
elseif isequal(physioData(k).name(1:6),'RESPDa')
physio_output.ppg.rawdata = load(fullfile(UnTarpPhysio_dir,physioData(kk).name));
elseif isequal(physioData(kk).name(1:6),'RESPDa')
physio_output.resp.name = 'RESP';
physio_output.resp.srate = 25; % here, we are hardcoding the CNI sampling rate for respiration
physio_output.resp.rawdata = load(fullfile(UnTarpPhysio_dir,physioData(k).name));
physio_output.resp.rawdata = load(fullfile(UnTarpPhysio_dir,physioData(kk).name));
end
end

% now we are going to time-lock it to the scan, and include a
% parameter for scan-onset
scan_duration=ni.dim(4)*ni.pixdim(4);% in sec
scan_duration = ni.dim(4)*ni.pixdim(4);% in sec
%%%% PPG:
% chop of the beginning
physio_output.ppg.data=physio_output.ppg.rawdata(end-round(scan_duration*physio_output.ppg.srate)+1:end);
physio_output.ppg.data = physio_output.ppg.rawdata(end-round(scan_duration*physio_output.ppg.srate)+1:end);
% add scan onset:
physio_output.ppg.scan_onset=zeros(size(physio_output.ppg.data));
for m=1:round(ni.dim(4))
physio_output.ppg.scan_onset(round(ni.pixdim(4)*(m-1)*physio_output.ppg.srate+1))=1;
physio_output.ppg.scan_onset = zeros(size(physio_output.ppg.data));
for mm = 1:round(ni.dim(4))
physio_output.ppg.scan_onset(round(ni.pixdim(4)*(mm-1)*physio_output.ppg.srate+1)) = 1;
end
%%%% RESP:
% chop of the beginning
physio_output.resp.data=physio_output.resp.rawdata(end-round(scan_duration*physio_output.resp.srate)+1:end);
physio_output.resp.data = physio_output.resp.rawdata(end-round(scan_duration*physio_output.resp.srate)+1:end);
% add scan onset:
physio_output.resp.scan_onset=zeros(size(physio_output.resp.data));
for m=1:round(ni.dim(4))
physio_output.resp.scan_onset(round(ni.pixdim(4)*(m-1)*physio_output.resp.srate+1))=1;
physio_output.resp.scan_onset = zeros(size(physio_output.resp.data));
for mm = 1:round(ni.dim(4))
physio_output.resp.scan_onset(round(ni.pixdim(4)*(mm-1)*physio_output.resp.srate+1))=1;
end

p=physio_output;
p = physio_output;

% make a figure of output as a check
if length(varargin)>2
Expand Down
Loading

0 comments on commit db60bb2

Please sign in to comment.