-
Notifications
You must be signed in to change notification settings - Fork 0
/
LFP_MS.m
112 lines (112 loc) · 3.8 KB
/
LFP_MS.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
clear all; clear cache; clc
set.fname = 'ytu337c';
set.analysis = 'MorletWavelet'; % Options are 'MorletWavelet', 'GrangerCausality', 'CrossCorrelation'
set.CC_type = 'AllMotion'; % CrossCorrelation over either 'AllMotion' or 'SeperateMotion'
set.win = .4; %msec
set.offset = .1; %msec
set.shift = 0; %msec2
set.mode = 2;
if set.mode == 1
set.type = 'stim';
elseif set.mode == 2
set.type = 'fix';
else
error('What the fuck are you doing?')
end
set.motion_type = 3;
set.num_rept = 5;
set.ang = 8;
set.grid = 9;
% set.movingwin = [0.5 0.05];
% set.alpha = 0.05;
% set.l = [4 8 16 25 65];
% set.u = [8 12 24 55 95];
% params.Fs = 200;
% params.tapers = [3 5];
% params.pad = 0;
% params.fpass = [0 90];
% params.err = [2 0.05];
% set.maxlag = 0.1 * Fs;
% y = plt_raw_lfp('ytu337a');
fname = set(1).fname;
[taskTrials,PD,ts,Fs,flag,x,goodtrials,info,new_zero,flg] = importEss(fname);
% x = x(:,new_zero:end); % Cutting the LFPs from desired new starting point
% nch = size(x,1); % # of channels after clean up
nch = 64;
% Grouping trials
[params.comb] = trialIdx(info);
%% MUA
% get RD files
[xout params.flag params.Fsds params.thr params.thrmax] = array2matSignal(fname);
% chop into trials
xfs = zeros(nch,(set.win * params.Fsds * 2 + (set.offset * params.Fsds)),size(info,1));
% xfix = zeros(nch,(set.win * params.Fsds),size(info,1));
% xstim = xfix;
info(:,15) = ceil(info(:,13) * params.Fsds);
for j = 1:size(info,1)
xfs(:,:,j) = xout(:,info(j,15) - (set.win * params.Fsds) + 1:info(j,15) + (set.win * params.Fsds) + (set.offset * params.Fsds));
% xfix(:,:,j) = xout(:,info(j,15) - (set.win * params.Fsds) + 1:info(j,15));
% xstim(:,:,j) = xout(:,info(j,15) + 1:info(j,15) + (set.win * params.Fsds));
end
t = -.4:1/params.Fsds:0.5;
t(end) = [];
% Remove mean Fixation from Stim
% mxfix = mean(mean(xfix,3),2);
% xadj = xfs - mxfix;
% Extract Signals for each condition
xsorted = [];
for i = 1:size(params.comb.comb,2)
a = params.comb.comb(i).idx;
for j = 1:size(a,1)
xsorted(i).xfs(:,:,j) = xout(:,info(a(j),15) - (set.win * params.Fsds) + 1:info(a(j),15) + (set.win * params.Fsds) + (set.offset * params.Fsds));
% xsorted(i).xfix(:,:,j) = xout(:,info(a(j),15) - (set.win * params.Fsds) + 1:info(a(j),15));
% xsorted(i).xstim(:,:,j) = xout(:,info(a(j),15) + 1:info(a(j),15) + (set.win * params.Fsds));
end
end
save(['E:\MT_MST\Plexon\PLXfiles\' sprintf('%s.mat',fname)],'params','info','xsorted'); %sp
soundsc(rand(3000,1))
return
%% Creat NMS & MS based on file type
params.type = fname(end);
switch params.type
case 'a'
if size(unique(info(:,4)),1) == 2
NMS = [19,36;55,72;91,108;127,144];
MS = [1,18;37,54;73,90;109,126];
elseif size(unique(info(:,4)),1) == 3
NMS = [28,54;82,108;136,162;190,216];
MS = [1,27;55,81;109,135;163,189];
end
case 'b'
if size(unique(info(:,4)),1) == 2
NMS = [1,18;37,54;73,90;109,126];
MS = [19,36;55,72;91,108;127,144];
elseif size(unique(info(:,4)),1) == 3
NMS = [1,27;55,81;109,135;163,189];
MS = [28,54;82,108;136,162;190,216];
end
end
j = 1;
xhat = [];
for z = 1:size(NMS,1)
for i = NMS(z,1):NMS(z,2)
xhat(j).NMS(:,:,:) = xsorted(i).xfs(:,:,:);
j = j + 1;
end
end
j = 1;
for z = 1:size(MS,1)
for i = MS(z,1):MS(z,2)
xhat(j).MS(:,:,:) = xsorted(i).xfs(:,:,:);
j = j + 1;
end
end
%% Power Spectral Density using pwelch function
Pfix = [];
Pstim = [];
for i = 1:nch
[Pstim(i,:,:),F] = pwelch(squeeze(xstim(i,:,:)),10,[],128,Fs);
[Pfix(i,:,:),F] = pwelch(squeeze(xfix(i,:,:)),10,[],128,Fs);
Pstim(i,:,:) = Pstim(i,:,:) .* F';
Pfix(i,:,:) = Pfix(i,:,:) .* F';
end