-
Notifications
You must be signed in to change notification settings - Fork 0
/
processing_2024_06_10.m
167 lines (155 loc) · 6.73 KB
/
processing_2024_06_10.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
%PROCESSING_2024_06_10 Processing associated with 2024-06-10 procedure.
close all force;
clc;
clear;
%% 1. Set parameters
% % % Recording-specific metadata parameters % % %
SUBJ = "Pilot_SCS_N_CEJ_04";
YYYY = 2024;
MM = 6;
DD = 10;
SWEEP = 70;
% RAW_DATA_ROOT = "C:/Data/SCS";
RAW_DATA_ROOT = parameters('raw_data_folder_root');
EXPORT_DATA_ROOT = parameters('local_export_folder');
% % % Parameters for response estimation % % %
DIG_IN_SYNC_CHANNEL_NUMBER = 2; % Index of DIG_IN connector used for stim onset sync signals
TLIM_SNIPPETS = [-0.002, 0.006]; % Seconds (for signal indexing, relative to each stim onset)
MUSCLE_RESPONSE_TIMES_FILE = "Muscle_Response_Times.xlsx";
[MUSCLE, CHANNEL_INDEX] = load_channel_map(sprintf('%s_Channel_Map.txt',SUBJ));
muscle = MUSCLE(CHANNEL_INDEX);
% % % Powerpoint Deck exporter % % %
pptx = exportToPPTX('', ...
'Dimensions',[10, 7.5], ...
'Title',sprintf("%s Recruitment Curves", SUBJ), ...
'Author','Max Murphy (MATLAB Auto-gen)', ...
'Subject',SUBJ, ...
'Comments',sprintf('Recruitment curves from Mouse SCS procedure %s.', SUBJ));
%% 2. Iterate over sweeps
iCount = 0;
for iSweep = SWEEP
iCount = iCount + 1;
[~,intanData,T] = loadData(SUBJ,YYYY,MM,DD,iSweep, ...
'LoadSAGA',false, ...
'RawDataRoot',RAW_DATA_ROOT);
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[4 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize', 10);
pptx.addTextbox(sprintf('SWEEP-%02d: CH-%d (%s)', iSweep, T.channel(1), T.return_channel{1}), ...
'Position',[0 3.5 10 1.5], ...
'FontName', 'Tahoma', ...
'HorizontalAlignment', 'center', ...
'FontSize', 36);
if T.is_monophasic(1)
pulse_type = "monophasic";
else
pulse_type = "biphasic";
end
if T.is_cathodal_leading(1)
pulse_pol = "cathodal";
else
pulse_pol = "anodal";
end
pptx.addTextbox(sprintf('%s-%s pulses', pulse_type, pulse_pol), ...
'Position',[0 5.5 10 1.5], ...
'FontName', 'Tahoma', ...
'HorizontalAlignment', 'center', ...
'Color', [0.65 0.65 0.65], ...
'FontSize', 18);
% 3. Index and filter data, estimate responses
[snips, t, response, blip, filtering, fdata] = ...
intan_amp_2_snips(intanData, ...
"TLim",TLIM_SNIPPETS, ...
"Muscle", MUSCLE, ... % Use one that does not have removals
"MuscleResponseTimesFile", MUSCLE_RESPONSE_TIMES_FILE, ...
"DigInSyncChannel", DIG_IN_SYNC_CHANNEL_NUMBER, ...
"Verbose", true, ...
'FilterParameters',{'ApplyFiltering', true});
% 4. Plot selected examples of response snippets
[snippetStackFigure, cdata] = plotResponseSnippets(t.*1e3, ...
snips, CHANNEL_INDEX, T, ...
'XLabel', 'Time (ms)', ...
'YOffset', 500, ...
'Muscle', muscle, ...
'Subject', SUBJ, 'Year', YYYY, 'Month', MM, 'Day', DD,'Sweep', iSweep);
for ii = 1:numel(snippetStackFigure)
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[4 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize', 10);
pptx.addTextbox(snippetStackFigure(ii).UserData.Title, ...
'Position',[0 0 10 1], ...
'FontName', 'Tahoma', ...
'FontSize', 24);
pptx.addTextbox(strrep(snippetStackFigure(ii).UserData.Subtitle,'\mu','μ'), ...
'Position',[0 0.75 10 1], ...
'FontName','Tahoma',...
'FontSize',16);
pptx.addPicture(snippetStackFigure(ii),'Position',[0 1.75 10 5.75]);
utils.save_figure(snippetStackFigure(ii),sprintf('%s/%s/Sweep-%02d/Snippets',EXPORT_DATA_ROOT,SUBJ,iSweep),sprintf('%s_Recruitment-Snippets_%d-Hz',SUBJ,snippetStackFigure(ii).UserData.Frequency));
end
blipFigure = plot_blips(muscle,blip,T,[],...
'CalibrationFile',MUSCLE_RESPONSE_TIMES_FILE, ...
'YOffset', 10);
for ii = 1:numel(blipFigure)
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[4 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize', 10);
pptx.addTextbox(blipFigure(ii).UserData.Title, ...
'Position',[0 0 10 1], ...
'FontName', 'Tahoma', ...
'FontSize', 24);
pptx.addTextbox(blipFigure(ii).UserData.Subtitle, ...
'Position',[0 1 10 0.75], ...
'FontName','Tahoma',...
'FontSize',16);
pptx.addPicture(blipFigure(ii),'Position',[0.5 1.75 9 5.25]);
utils.save_figure(blipFigure(ii),sprintf('%s/%s/Sweep-%02d/Blips',EXPORT_DATA_ROOT,SUBJ,iSweep),sprintf('%s_Blips_%d-Hz',SUBJ,blipFigure(ii).UserData.Frequency));
end
% 5. Plot response curves
for iCh = 1:numel(CHANNEL_INDEX)
recruitmentFigure = plotRecruitment(T, response, CHANNEL_INDEX(iCh), muscle(iCh), 'Color', cdata(iCh,:));
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[4 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize', 10);
pptx.addTextbox(muscle(iCh), ...
'Position',[0 3.5 10 1.5], ...
'FontName', 'Tahoma', ...
'HorizontalAlignment', 'center', ...
'FontSize', 36);
for ii = 1:numel(recruitmentFigure)
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[4 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize', 10);
pptx.addTextbox(strrep(recruitmentFigure(ii).UserData.Channel,'\mu','μ'), ...
'Position',[0 0 10 1], ...
'FontName', 'Tahoma', ...
'FontSize', 24);
pptx.addPicture(recruitmentFigure(ii),'Position',[0 1 10 6.5]);
utils.save_figure(recruitmentFigure(ii), sprintf('%s/%s/Sweep-%02d/Recruitment',EXPORT_DATA_ROOT,SUBJ,iSweep),sprintf('%s_%s_Recruitment-Curve_%d-Hz',SUBJ,muscle(iCh),recruitmentFigure(ii).UserData.Frequency));
end
end
end
%% 7. Save Powerpoint
if exist(fullfile(EXPORT_DATA_ROOT,SUBJ),'dir')==0
mkdir(fullfile(EXPORT_DATA_ROOT,SUBJ));
end
if isscalar(SWEEP)
pptx.save(sprintf('%s/%s/%s_Recruitment_%02d',EXPORT_DATA_ROOT,SUBJ,SUBJ,SWEEP));
else
pptx.save(sprintf('%s/%s/%s_Recruitment_All',EXPORT_DATA_ROOT,SUBJ,SUBJ));
end