-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultisite_spike_sandbox.m
More file actions
506 lines (387 loc) · 17.1 KB
/
Copy pathMultisite_spike_sandbox.m
File metadata and controls
506 lines (387 loc) · 17.1 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
% Multi-site spike sandbox
addpath(genpath('C:\Users\ecarm\Documents\GitHub\vandermeerlab\code-matlab\shared'));
addpath(genpath('C:\Users\ecarm\Documents\GitHub\EC_Multisite'))
ft_path = 'C:\Users\ecarm\Documents\GitHub\fieldtrip';
cd('M:\Multi_spike\Cat_Spikes')
% %% try to cut them.
% restoredefaultpath
% addpath(genpath('C:\Users\ecarm\Documents\GitHub\vandermeerlab\code-matlab\toolboxes\MClust-3.5'))
%
%
% %% try simple cut.
% restoredefaultpath
% addpath(genpath('C:\Users\ecarm\Documents\GitHub\simpleclust'))
% %% load the spikes
% cd('M:\Multi_spike\Cat_Spikes\R108-2017-08-01')
% addpath(genpath('/home/ecarmichael/Documents/GitHub/vandermeerlab/code-matlab/shared'));
%%
cd('M:\Multi_spike\Cat_Spikes\R123_2017_02_26\')
cfg = [] ;
cfg.fc = {};
cfg.getTTnumbers = 0;
S = LoadSpikes(cfg);
firstSpike(S);
fprintf('Total recording time in S: %0.0fs\n', lastSpike(S) - firstSpike(S));
plot(S)
Evt = LoadEvents([]);
Starts = MS_extract_TS(Evt, 'Starting Recording');
Stops = MS_extract_TS(Evt, 'Stopping Recording');
for ii = 1:1:8
disp((Stops.t{1}(ii)- Starts.t{1}(ii))/60)
end
%% JG data
Starts = ts({sort([Evt.t{1}, Evt.t{3}])});
Stops = ts({sort([Evt.t{2}, Evt.t{4}, Evt.t{5}(1)])});
for ii = 1:4
disp((Stops.t{1}(ii)- Starts.t{1}(ii))/60)
end
S_pre = restrict(S, Starts.t{1}(1), Stops.t{1}(1));
S_ipsi = restrict(S, Starts.t{1}(2), Stops.t{1}(2));
S_contra= restrict(S, Starts.t{1}(3), Stops.t{1}(3));
S_post = restrict(S, Starts.t{1}(4), Stops.t{1}(4));
%% [In reality this will be done to match the LFP data with a strict cut at 10mins] restrict to specific periods (need to grab cat events files for start/stops).
S_pre = restrict(S, Starts.t{1}(1), Stops.t{1}(1));
S_ipsi = restrict(S, Starts.t{1}(3), Stops.t{1}(3));
S_contra= restrict(S, Starts.t{1}(5), Stops.t{1}(5));
S_post = restrict(S, Starts.t{1}(7), Stops.t{1}(7));
%% get the mean firing rate and ISI
for iCell = length(S.t):-1:1
% ISI{iCell} = mean(diff(S.t{iCell}));
% Rate{iCell} = 1/mean(diff(S.t{iCell}));
% get mean ISI
nSpike_pre{iCell} = length(S_pre.t{iCell});
nSpike_ipsi{iCell} = length(S_ipsi.t{iCell});
nSpike_contra{iCell} = length(S_contra.t{iCell});
nSpike_post{iCell} = length(S_post.t{iCell});
ISI_pre{iCell} = median(diff(S_pre.t{iCell}));
ISI_ipsi{iCell} = median(diff(S_ipsi.t{iCell}));
ISI_contra{iCell} = median(diff(S_contra.t{iCell}));
ISI_post{iCell} = median(diff(S_post.t{iCell}));
% std
ISI_pre_sd{iCell} = std(diff(S_pre.t{iCell}));
ISI_ipsi_sd{iCell} = std(diff(S_ipsi.t{iCell}));
ISI_contra_sd{iCell} = std(diff(S_contra.t{iCell}));
ISI_post_sd{iCell} = std(diff(S_post.t{iCell}));
% % get firing rate.
Rate_pre{iCell} = 1./median(diff(S_pre.t{iCell}));
Rate_ipsi{iCell} = 1./median(diff(S_ipsi.t{iCell})); %(length(S_ipsi.t{iCell})) ./((lastSpike(S_ipsi) - firstSpike(S_ipsi)))
Rate_contra{iCell} = 1./median(diff(S_contra.t{iCell})); %(length(S_contra.t{iCell})) ./((lastSpike(S_contra) - firstSpike(S_contra)))
Rate_post{iCell} = 1./median(diff(S_post.t{iCell})); %(length(S_post.t{iCell})) ./((lastSpike(S_post) - firstSpike(S_post)))
% FR std
Rate_pre_sd{iCell} = 1./std(diff(S_pre.t{iCell}));
Rate_ipsi_sd{iCell} = 1./std(diff(S_ipsi.t{iCell})); %(length(S_ipsi.t{iCell})) ./((lastSpike(S_ipsi) - firstSpike(S_ipsi)))
Rate_contra_sd{iCell} = 1./std(diff(S_contra.t{iCell})); %(length(S_contra.t{iCell})) ./((lastSpike(S_contra) - firstSpike(S_contra)))
Rate_post_sd{iCell} = 1./std(diff(S_post.t{iCell})); %(length(S_post.t{iCell})) ./((lastSpike(S_post) - firstSpike(S_post)))
end
%% cross cor
figure(103)
c_ord = linspecer(4);
% gen subplot vals
sub_id = reshape(1:(length(S_pre.t)*4), 4, length(S_pre.t))';
cfg_ccf = [];
cfg_ccf.max_t = 0.2;
for iCell = 1:length(S_pre.t)
% figure(iCell)
% sgtitle(['Cell: ' S_pre.label{iCell}])
% subplot(4,3,3)
subplot(length(S_pre.t),4,sub_id(iCell, 1))
[ccf_val,tvec] = ccf(cfg_ccf,S_pre.t{iCell},S_pre.t{iCell});
plot(tvec, ccf_val, 'color', c_ord(1,:))
text(-.35, 0.1, strrep(S_pre.label{iCell}(end-7:end-2), '_', '-'));
text(-.2, 0.09, ['nSpikes: ' num2str(nSpike_pre{iCell},'%2.2f') ],'FontSize',8);
text(-.2, 0.06, ['Rate: ' num2str(Rate_pre{iCell},'%2.2f') 'Hz'],'FontSize',8);
text(-.2, 0.03, ['ISI: ' num2str(ISI_pre{iCell}*1000,'%2.0f') 'ms'],'FontSize',8);
% text(-.2, 0.06, ['Rate: ' num2str(Rate_pre{iCell},'%2.2f') '+/-' num2str(Rate_pre_sd{iCell},'%2.2f') 'Hz'],'FontSize',8);
% text(-.2, 0.03, ['ISI: ' num2str(ISI_pre{iCell}*1000,'%2.0f') '+/-' num2str(ISI_pre_sd{iCell}*1000,'%2.0f') 'ms'],'FontSize',8);
% xlabel('pre')
ylim([0 .1])
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
% subplot(4,3,6)
subplot(length(S_pre.t),4,sub_id(iCell, 2))
[ccf_val,tvec] = ccf(cfg_ccf,S_ipsi.t{iCell},S_ipsi.t{iCell});
plot(tvec, ccf_val, 'color', c_ord(2,:))
% xlabel('ipsi')
ylim([0 .1])
text(-.2, 0.09, ['nSpikes: ' num2str(nSpike_ipsi{iCell},'%2.2f') ],'FontSize',8);
text(-.2, 0.06, ['Rate: ' num2str(Rate_ipsi{iCell},'%2.2f') 'Hz'],'FontSize',8);
text(-.2, 0.03, ['ISI: ' num2str(ISI_ipsi{iCell}*1000,'%2.0f') 'ms'],'FontSize',8);
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
% subplot(4,3,9)
subplot(length(S_pre.t),4,sub_id(iCell, 3))
[ccf_val,tvec] = ccf(cfg_ccf,S_contra.t{iCell},S_contra.t{iCell});
plot(tvec, ccf_val, 'color', c_ord(3,:))
% xlabel('contra')
ylim([0 .1])
text(-.2, 0.09, ['nSpikes: ' num2str(nSpike_contra{iCell},'%2.0f') ],'FontSize',8);
text(-.2, 0.06, ['Rate: ' num2str(Rate_contra{iCell},'%2.2f') 'Hz'],'FontSize',8);
text(-.2, 0.03, ['ISI: ' num2str(ISI_contra{iCell}*1000,'%2.0f') 'ms'],'FontSize',8);
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
% subplot(4,3,12)
subplot(length(S_pre.t),4,sub_id(iCell, 4))
[ccf_val,tvec] = ccf(cfg_ccf,S_post.t{iCell},S_post.t{iCell});
plot(tvec, ccf_val, 'color', c_ord(4,:))
% xlabel('post')
ylim([0 .1])
text(-.2, 0.09, ['nSpikes: ' num2str(nSpike_post{iCell},'%2.0f') ],'FontSize',8);
text(-.2, 0.06, ['Rate: ' num2str(Rate_post{iCell},'%2.2f') 'Hz'],'FontSize',8);
text(-.2, 0.03, ['ISI: ' num2str(ISI_post{iCell}*1000,'%2.0f') 'ms'],'FontSize',8);
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
end
%% LFP for MS data
cfg.fc= {'CSC9_pre.ncs'};
csc_pre = MS_LoadCSC(cfg);
cfg.fc= {'CSC9_ipsi.ncs'};
csc_ipsi = MS_LoadCSC(cfg);
cfg.fc= {'CSC9_contra.ncs'};
csc_contra = MS_LoadCSC(cfg);
cfg.fc= {'CSC9_post.ncs'};
csc_post = MS_LoadCSC(cfg);
t_temp_pre = csc_pre.tvec - csc_pre.tvec(1);
t_temp_ipsi = csc_ipsi.tvec - csc_ipsi.tvec(1);
t_temp_contra = csc_contra.tvec - csc_contra.tvec(1);
t_temp_post = csc_post.tvec - csc_post.tvec(1);
csc_pre = restrict(csc_pre, Starts.t{1}(1), csc_pre.tvec(nearest_idx3(600,t_temp_pre)));
csc_ipsi = restrict(csc_ipsi, Starts.t{1}(3), csc_ipsi.tvec(nearest_idx3(600,t_temp_ipsi)));
csc_contra = restrict(csc_contra, Starts.t{1}(5), csc_contra.tvec(nearest_idx3(600,t_temp_contra)));
csc_post = restrict(csc_post, Starts.t{1}(7), csc_post.tvec(nearest_idx3(600,t_temp_post)));
% cfg_filt.type = 'cheby1'; %Cheby1 is sharper than butter
% cfg_filt.f = [30 90]; % broad, could use 150-200?
% cfg_filt.order = 5; %type filter order (fine for this f range)
% cfg_filt.display_filter = 0; % use this to see the fvtool
cfg_filt.type = 'fdesign'; %the type of filter I want to use via filterlfp
cfg_filt.f = [1 5];
cfg_filt.order = 8; %type filter order
csc_all = csc_pre;
if csc_ipsi.tvec(1) < csc_contra.tvec(1)
csc_all.data = [csc_pre.data, csc_ipsi.data, csc_contra.data, csc_post.data];
csc_all.tvec = [csc_pre.tvec; csc_ipsi.tvec; csc_contra.tvec; csc_post.tvec];
else
csc_all.data = [csc_pre.data, csc_contra.data, csc_ipsi.data, csc_post.data];
csc_all.tvec = [csc_pre.tvec; csc_contra.tvec; csc_ipsi.tvec; csc_post.tvec];
end
csc_lg = FilterLFP(cfg_filt, csc_all);
% check durations
disp(['pre ' num2str((csc_pre.tvec(end) - csc_pre.tvec(1))/60) 'min'])
disp(['ipsi ' num2str((csc_ipsi.tvec(end) - csc_ipsi.tvec(1))/60) 'min'])
disp(['contra ' num2str((csc_contra.tvec(end) - csc_contra.tvec(1))/60) 'min'])
disp(['post ' num2str((csc_post.tvec(end) - csc_post.tvec(1))/60) 'min'])
%% same thing but Spike-LFP on Jimmie data.
cfg.fc= {'R152-2018-06-03-CSC34.ncs'};
csc = MS_LoadCSC(cfg);
cfg_filt.type = 'cheby1'; %Cheby1 is sharper than butter
cfg_filt.f = [30 90]; % broad, could use 150-200?
cfg_filt.order = 5; %type filter order (fine for this f range)
cfg_filt.display_filter = 0; % use this to see the fvtool
csc_lg = FilterLFP(cfg_filt, csc);
csc_pre = restrict(csc, Starts.t{1}(1), Stops.t{1}(1));
csc_ipsi = restrict(csc, Starts.t{1}(2), Stops.t{1}(2));
csc_contra = restrict(csc, Starts.t{1}(3), Stops.t{1}(3));
csc_post = restrict(csc, Starts.t{1}(4), Stops.t{1}(4));
%% get STA using matlab only from vandermeerlab tutorials.
dt = 1/csc_pre.cfg.hdr{1}.SamplingFrequency;
w = [-.5 .5]; % time window to compute STA over
tvec = w(1):1/csc_pre.cfg.hdr{1}.SamplingFrequency:w(2); % time axis for STA
len = length(tvec);
for iC = length(S_pre.t):-1:1
% pre block
bin_edges = csc_pre.tvec+(dt/2);
Sr = restrict(S_pre,csc_pre.tvec(1)-w(1),csc_pre.tvec(end)-w(2));
spk_t = Sr.t{iC}+w(1); % times corresponding to start of window
[~,spk_bins] = histc(spk_t,bin_edges); % index into data for start of window
spk_bins2 = spk_bins(:,ones(len,1));
toadd = repmat(0:len-1,[length(spk_bins) 1]);
spk_bins3 = spk_bins2+toadd;
sta_pre{iC} = csc_pre.data(spk_bins3);
% ipsi block
bin_edges = csc_ipsi.tvec+(dt/2);
Sr = restrict(S_ipsi,csc_ipsi.tvec(1)-w(1),csc_ipsi.tvec(end)-w(2));
spk_t = Sr.t{iC}+w(1); % times corresponding to start of window
[~,spk_bins] = histc(spk_t,bin_edges); % index into data for start of window
spk_bins2 = spk_bins(:,ones(len,1));
toadd = repmat(0:len-1,[length(spk_bins) 1]);
spk_bins3 = spk_bins2+toadd;
sta_ipsi{iC} = csc_ipsi.data(spk_bins3);
% contra block
bin_edges = csc_contra.tvec+(dt/2);
Sr = restrict(S_contra,csc_contra.tvec(1)-w(1),csc_contra.tvec(end)-w(2));
spk_t = Sr.t{iC}+w(1); % times corresponding to start of window
[~,spk_bins] = histc(spk_t,bin_edges); % index into data for start of window
spk_bins2 = spk_bins(:,ones(len,1));
toadd = repmat(0:len-1,[length(spk_bins) 1]);
spk_bins3 = spk_bins2+toadd;
sta_contra{iC} = csc_contra.data(spk_bins3);
% post block
bin_edges = csc_post.tvec+(dt/2);
Sr = restrict(S_post,csc_post.tvec(1)-w(1),csc_post.tvec(end)-w(2));
spk_t = Sr.t{iC}+w(1); % times corresponding to start of window
[~,spk_bins] = histc(spk_t,bin_edges); % index into data for start of window
spk_bins2 = spk_bins(:,ones(len,1));
toadd = repmat(0:len-1,[length(spk_bins) 1]);
spk_bins3 = spk_bins2+toadd;
sta_post{iC} = csc_post.data(spk_bins3);
end
%% plot
figure(104)
% gen subplot vals
sub_id = reshape(1:(length(S_pre.t)*4), 4, length(S_pre.t))';
for iCell = 1:length(S_pre.t)
m_val = max([nanmean(sta_pre{iCell}), nanmean(sta_ipsi{iCell}),...
nanmean(sta_contra{iCell}), nanmean(sta_post{iCell})]);
min_val = min([nanmean(sta_pre{iCell}), nanmean(sta_ipsi{iCell}),...
nanmean(sta_contra{iCell}), nanmean(sta_post{iCell})]);
subplot(length(S_pre.t),4,sub_id(iCell, 1))
plot(tvec, nanmean(sta_pre{iCell}), 'color', c_ord(1,:))
xlim([tvec(1) tvec(end)])
text(-.8, mean(nanmean(sta_pre{iCell})), strrep(S_pre.label{iCell}(end-7:end-2), '_', '-'));
ylim([min_val m_val])
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
else
xlabel('time (s)')
end
% subplot(4,3,6)
subplot(length(S_pre.t),4,sub_id(iCell, 2))
plot(tvec, nanmean(sta_ipsi{iCell}), 'color', c_ord(2,:))
xlim([tvec(1) tvec(end)])
ylim([min_val m_val])
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
% subplot(4,3,9)
subplot(length(S_pre.t),4,sub_id(iCell, 3))
plot(tvec, nanmean(sta_contra{iCell}), 'color', c_ord(3,:))
xlim([tvec(1) tvec(end)])
ylim([min_val m_val])
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
% subplot(4,3,12)
subplot(length(S_pre.t),4,sub_id(iCell, 4))
plot(tvec, nanmean(sta_post{iCell}), 'color', c_ord(4,:))
xlim([tvec(1) tvec(end)])
ylim([min_val m_val])
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
end
%% spike gamma phase histogram
lg_phase = angle(hilbert(csc_lg.data));
lg_phase = rad2deg(lg_phase);
p_bins = rad2deg(-pi:pi/8:3*pi);
p_center = p_bins(1:end-1)+30/2;
for iCell = 1:length(S_pre.t)
spike_phase_idx = nearest_idx3(S_pre.t{iCell}, csc_lg.tvec);
stim_phase = lg_phase(spike_phase_idx);
phase_S_pre{iCell} = histc([stim_phase stim_phase+360], p_bins);
% ipsi
spike_phase_idx = nearest_idx3(S_ipsi.t{iCell}, csc_lg.tvec);
stim_phase = lg_phase(spike_phase_idx);
phase_S_ipsi{iCell} = histc([stim_phase stim_phase+360], p_bins);
% contra
spike_phase_idx = nearest_idx3(S_contra.t{iCell}, csc_lg.tvec);
stim_phase = lg_phase(spike_phase_idx);
phase_S_contra{iCell} = histc([stim_phase stim_phase+360], p_bins);
% post
spike_phase_idx = nearest_idx3(S_post.t{iCell}, csc_lg.tvec);
stim_phase = lg_phase(spike_phase_idx);
phase_S_post{iCell} = histc([stim_phase stim_phase+360], p_bins);
end
figure(105)
% gen subplot vals
sub_id = reshape(1:(length(S_pre.t)*4), 4, length(S_pre.t))';
c_ord = linspecer(4);
for iCell = 1:length(S_pre.t)
m_val = max( [phase_S_pre{iCell}(1:end-1)./length(S_pre.t{iCell}),...
phase_S_ipsi{iCell}(1:end-1)./length(S_ipsi.t{iCell}), ...
phase_S_contra{iCell}(1:end-1)./length(S_contra.t{iCell}), ...
phase_S_post{iCell}(1:end-1)./length(S_post.t{iCell})]);
m_val = m_val*1.25;
subplot(length(S_pre.t),4,sub_id(iCell, 1))
bar(p_center, phase_S_pre{iCell}(1:end-1)./length(S_pre.t{iCell}), 'FaceColor',c_ord(1,:),'EdgeColor',c_ord(1,:))
text(-400, mean(phase_S_pre{iCell}(1:end-1)./length(S_pre.t{iCell})), strrep(S_pre.label{iCell}(end-7:end-2), '_', '-'));
if iCell == 1
text(-180, m_val*.9, ['Filt: ' num2str(cfg_filt.f)],'FontSize',8)
text(-180, m_val*.8, ['id: ' strrep(csc_pre.cfg.SessionID, '_', '-')], 'FontSize',8)
end
ylim([0 m_val]);
set(gca, 'xtick', -180:180:540);
if iCell == length(S_pre.t)
xlabel('lg phase (deg)')
else
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
subplot(length(S_pre.t),4,sub_id(iCell, 2))
bar(p_center, phase_S_ipsi{iCell}(1:end-1)./length(S_ipsi.t{iCell}), 'FaceColor',c_ord(2,:),'EdgeColor',c_ord(2,:))
ylim([0 m_val]);
set(gca, 'xtick', -180:180:540);
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
subplot(length(S_pre.t),4,sub_id(iCell, 3))
bar(p_center, phase_S_contra{iCell}(1:end-1)./length(S_contra.t{iCell}), 'FaceColor',c_ord(3,:),'EdgeColor',c_ord(3,:))
ylim([0 m_val]);
set(gca, 'xtick', -180:180:540);
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
subplot(length(S_pre.t),4,sub_id(iCell, 4))
bar(p_center, phase_S_post{iCell}(1:end-1)./length(S_post.t{iCell}), 'FaceColor',c_ord(4,:),'EdgeColor',c_ord(4,:))
ylim([0 m_val]);
set(gca, 'xtick', -180:180:540);
if iCell ~= length(S_pre.t)
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
end
%% Ft method
addpath(ft_path)
ft_defaults
% load spikes
all_spike = [];
for iS = 1:length(S.label)
spike = ft_read_spike(S.label{iS}); % needs fixed read_mclust_t.m
all_spike = ft_appendspike([], all_spike, spike);
end
data = ft_read_neuralynx_interp(fc);
data_all = ft_appendspike([],data, spike);
%%
spk_t = Pre_S.t{1};
max_t = 1;
binsize = 0.01;
xbin_centers = -max_t-binsize:binsize:max_t+binsize; % first and last bins are to be deleted later
ac = zeros(size(xbin_centers));
for iSpk = 1:length(spk_t)
relative_spk_t = spk_t - spk_t(iSpk);
ac = ac + hist(relative_spk_t,xbin_centers); % note that hist() puts all spikes outside the bin centers in the first and last bins! delete later.
end
xbin = xbin_centers(2:end-1); % remove unwanted bins
ac = ac(2:end-1);
ac = ac./max(ac); % normalize
%%
spk_t = S.t{1}; % spike times
isi = diff(spk_t); % interspike intervals
dt = 0.001; % in s, because spike times are in s
isi_edges = 0:dt:0.25; % bin edges for ISI histogram
isi_centers = isi_edges(1:end-1)+dt/2; % for plotting
isih = histc(isi,isi_edges);
bar(isi_centers,isih(1:end-1)); % remember to ignore the last bin of histc() output
set(gca,'FontSize',20,'XLim',[0 0.25]); xlabel('ISI (s)'); ylabel('count'); grid on;