-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_threshold.m
153 lines (109 loc) · 3.39 KB
/
find_threshold.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
%Load ADRITOOLS
addpath(genpath('C:\Users\students\Documents\Swatantra\ADRITOOLS-master'))
%Load CorticoHippocampal
addpath(genpath('C:\Users\students\Documents\Swatantra\CorticoHippocampal'))
%Load RGS14 github
addpath(genpath('C:\Users\students\Documents\Swatantra\LFP_RGS14'))
ss=3;
%Rat 4
cd('C:\Users\students\Documents\plusmaze_toilet_data_correct\rat4')
G=getfolder();
for j=1:length(G) % Iterate across study days.
cd('C:\Users\students\Documents\plusmaze_toilet_data_correct\rat4')
cd(G{j})
prepost=getfolder();
for i=1: length(prepost)
cd('C:\Users\students\Documents\plusmaze_toilet_data_correct\rat4')
cd(G{j})
cd(prepost{i})
%Read brain areas and load states file.
%% HPC
HPC=dir(strcat('*','HPC','*.mat'));
HPC=HPC.name;
HPC=load(HPC);
HPC=getfield(HPC,'HPC_ripple');
Cortex=dir(strcat('*','PFC','*.mat'));
Cortex=Cortex.name;
Cortex=load(Cortex);
Cortex=getfield(Cortex,'PFC');
Cortex=Cortex.*(0.195);
%Load sleep scoring
A = dir('*states*.mat');
A={A.name};
if ~isempty(A)
cellfun(@load,A);
else
error('No Scoring found')
end
[sd_swr]=find_std(HPC,Cortex,states,ss);
Sd_Swr.sd5_hpc_co(j,i)=sd_swr.sd5_hpc_co;
Sd_Swr.sd5_pfc_co(j,i)=sd_swr.sd5_pfc_co;
end
end
thresholds_perday_hpc=mean(Sd_Swr.sd5_hpc_co,2);
thresholds_perday_cortex=mean(Sd_Swr.sd5_pfc_co,2);
tr(1)=mean(thresholds_perday_hpc);
tr(2)=mean(thresholds_perday_cortex);
offset1={'5'};
offset2={'5'};
%%
D1 = round(tr(1) + str2num(cell2mat(offset1)));
D2 = round(tr(2) + str2num(cell2mat(offset2)));
[swr_hpc,swr_pfc,s_hpc,s_pfc,V_hpc,V_pfc,signal2_hpc,signal2_pfc] = swr_check_thr(HPC,Cortex,states,ss,D1,D2);
['Found ' num2str(sum(s_hpc)) ' hippocampal ripples']
['Found ' num2str(sum(s_pfc)) ' cortical ripples']
%% Find epoch with most detections
max_length=cellfun(@length,swr_hpc(:,1));
N=max_length==max(max_length);
hpc=V_hpc{N};
pfc=V_pfc{N};
hpc2=signal2_hpc{N};
pfc2=signal2_pfc{N};
n=find(N);
if length(n)>1
'Multiple epochs with same number of events'
end
n=n(1);
%%
prompt = {'Select window length (msec):','Brain area:'};
dlgtitle = 'Input';
dims = [1 35];
definput = {'100','PFC'};
answer = inputdlg(prompt,dlgtitle,dims,definput);
win_len=str2num(answer{1});
BR=answer{2};
%%
close all
plot((1:length(hpc))./1000,5.*zscore(hpc)+100,'Color','black')
hold on
plot((1:length(pfc))./1000,5.*zscore(pfc)+150,'Color','black')
xlabel('Time (Seconds)')
plot((1:length(hpc2))./1000,5.*zscore(hpc2)+220,'Color','black')
plot((1:length(pfc2))./1000,5.*zscore(pfc2)+290,'Color','black')
yticks([100 150 220 290])
yticklabels({'HPC','PFC','HPC (Bandpassed)',['PFC' '(Bandpassed)']})
b=gca;
b.FontSize=12;
if strcmp(BR,'PFC')
sn=swr_pfc{n,3};
else
sn=swr_hpc{n,3};
end
if isempty(sn)
errordlg('No Events found','Error');
xo
end
prompt = {['Select event ID number. Max value:' num2str(length(sn))]};
dlgtitle = 'Input';
dims = [1 35];
definput = {'1'};
answer2 = inputdlg(prompt,dlgtitle,dims,definput);
answer2=str2num(answer2{1});
if ~ isempty(swr_hpc{n})
stem([swr_hpc{n,3}],ones(length([swr_hpc{n}]),1).*250,'Color','blue') %(HPC)
end
hold on
if ~ isempty(swr_pfc{n})
stem([swr_pfc{n,3}],ones(length([swr_pfc{n}]),1).*250,'Color','red')%Seconds (Cortex)
end
%xlim([sn(answer2)-win_len/1000 sn(answer2)+win_len/1000])