-
Notifications
You must be signed in to change notification settings - Fork 0
/
MUA_d.m
85 lines (83 loc) · 2.26 KB
/
MUA_d.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
clear all; clear cache; close all; clc
cd E:\MT_MST\Plexon\PLXfiles
%% Merge a & b + create spikewaveforms
a = load('ytu310c.mat');
Fs = a.params.Fsds;
allcomb = a.params.comb.allcomb;
Xa = {a.xsorted.xfs}';
spkt = [];
for i = 1:size(Xa,1)
spkt(i).NMS = Xa{i};
end
%% Covering missing trials with zeros
for i = 1:size(spkt,2)
if size(spkt(i).NMS,3) ~= 4
missC = 4 - size(spkt(i).NMS,3);
spkt(i).NMS(:,:,end + missC) = zeros;
end
end
%% Creating a 6D matrix ch * npoints * dir * motion * position * repetition
NMS = [];
NMScell = {spkt.NMS}';
i = 1;
for j = 1:8 % #direction
for z = 1:size(unique(allcomb(:,2)),1) % #motion
for w = 1:size(unique(allcomb(:,3)),1) % #position
NMS(j,z,w,:,:,:) = double(NMScell{i,1});
i = i + 1;
end
end
end
NMS = permute(NMS,[4 5 1 2 3 6]);
%% remove microstim artifact
lbthr = 0.0005;
zeroSize = 0.03 * Fs; % 30 msec
blackoutNMS = findblackout(NMS,lbthr,zeroSize);
%% Threshold for spike sorting
stdmin = 3; % min threshold for detection
stdmax = 10; % max threshold for detection
[thrnms thrmaxnms] = findthreshold(NMS,stdmin,stdmax);
%% Generate spike trains
spktNMS = [];
nrept = 4;
spktNMS = findspkt(NMS,nrept,thrnms,thrmaxnms);%thrnms
%% Firing Rate and Discarding blackouts
[frbl frst prCorrect fr_bl] = FireRate_bin(spktNMS,blackoutNMS,Fs);
%% Plot Tuning Curves
dir = [0:45:315];
for i = 51:59
tcplotMUA(dir,frst,2,3,3,frbl,i,prCorrect)
% tcplotMUA(dir,frst,2,3,3,frbl,i,prCorrect)
end
return
%% T-Test to find good cell
clc
for ch = 1:10
stim = squeeze(frst(ch,:,:,:));
baseline = squeeze(fr_bl(ch,:,:,:));
[h,p] = ttest(baseline(:),stim(:));
if p <= 0.05
disp('Yo! You got a Cell!')
elseif p > 0.05
warning('Not a Cell, Life Sucks!')
end
end
%%
ch = 51;
mo = 2;
pos = 1;
tr = 4;
figure
for i = 1:8
subplot(4,2,i)
if blackoutNMS(ch,i,mo,pos,tr) == 1
ctl = 'fail';
plot((NMS(ch,:,i,mo,pos,tr)),'r')
% plot(spktNMS(ch,:,i,mo,pos,tr),'r')
elseif blackoutNMS(ch,i,mo,pos,tr) == 0
ctl = 'pass';
plot((NMS(ch,:,i,mo,pos,tr)),'b')
% plot(spktNMS(ch,:,i,mo,pos,tr),'b')
end
title(sprintf('%s',ctl))
end