-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfnirsDataSync.m
25 lines (21 loc) · 1.54 KB
/
fnirsDataSync.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function [HbIdx, HbO_epoch_data, HbR_epoch_data, epoch_time] = fnirsDataSync(StartEndIndices, time_filtered, HbO_filtered, HbR_filtered, eventStruct, t0, delay)
% Authors: Ivy Hill & Iris Li -- rename fnirsTaskTimesSync
% Created July 9th, 2024 | Last editied July 19th, 2024
% Purpose: Finds start and end times of each trial, per task (modularized version of split_times section 2):
for i = 1:(length(StartEndIndices(:, 1))/2) %Iterates accross nav/arm/vs
for j = 1:length(StartEndIndices(1, :)) %Iterates by trial number
sidx = StartEndIndices(2*i - 1, j); % odd rows
eidx = StartEndIndices(2*i, j); % even rows
sampleTimes = eventStruct.time_stamps([sidx, eidx]) - t0 - delay; %Pulls the indices from the Unity sample times
%Essentially syncs Unity sample rate and fNIRS sample rate
HbIdx(i, j, :) = interp1(time_filtered,1:length(time_filtered),sampleTimes,'nearest'); %Interpolates the nearest fNIRS time to the Unity sample time
%Sorts values as a fourth dimentional cell array to combine
%vectors/matricies of varying sizes and to make easier to turn
%into a table in future
HbO_epoch_data(i, j, :, :) = {HbO_filtered(:, [HbIdx(i, j, 1):HbIdx(i, j, 2)])};
HbR_epoch_data(i, j, :, :) = {HbR_filtered(:, [HbIdx(i, j, 1):HbIdx(i, j, 2)])};
epoch_time(i, j, :) = {time_filtered(HbIdx(i, j, 1):HbIdx(i, j, 2))};
epoch_time{i, j, :} = epoch_time{i, j} - epoch_time{i, j}(1);
end
end
end