-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfitphase.m
108 lines (86 loc) · 2.8 KB
/
fitphase.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
function fitphase(a,pscale,doplot)
% Give it the frequency, the scale, and whether to plot or spit
% out numbers, and it will do so.
global piphase;
global pdata;
%rectify=get(findobj('Tag','RectifyBox'),'Value');
%rlevel=get(findobj('Tag','EditLevel'),'String');
%rlevel=str2num(rlevel);
rectify=1;
rlevel=-0.9;
if ~piphase
piphase=0;
end
if a==1
freq=0.5;
elseif a==2
freq=1;
elseif a==3
freq=1.5;
elseif a==4
freq=2;
elseif a==5
freq=3;
elseif a==6
freq=4;
elseif a==7
freq=6;
elseif a==8
freq=8;
end
if plot==1;
resolution=500;
p=freq*5; % we want 5 modulations of the centre,so multiply by 5 to get outer mods
time=linspace(0, 2.5, resolution);
o=linspace(0, p*pi, resolution);
outer=sin(o-piphase); %work out outer with phase shift
if rectify==1
x=find(outer<=rlevel);
outer(x)=rlevel;
outer=outer-rlevel;
outer=outer/max(outer);
end
i=linspace(0, 10*pi, resolution); %2pi * 5 modulations
inner=sin(i-piphase); %work out inner with phase shift
if rectify==1
x=find(inner<=rlevel);
inner(x)=rlevel;
inner=inner-rlevel; %rectify so above 0
inner=inner/max(inner); %normalise to 1
end
interaction=inner-outer;
if max(interaction)>0; interaction= interaction / max(interaction); end %normalized to 1
interaction=interaction*pscale; %scale for the PSTH size
inner=inner*pscale;
%whos time inner interaction
%hold on
plot(time,inner,'g--',time,interaction,'r-');
xlabel(num2str(freq));
%hold off
else
%-------------------------------------------------------------
% We will now recompute to allow the PSTH ratio routine
% to use them as an index
%-------------------------------------------------------------
resolution=length(pdata.psth{2}(:,3)); %find out how long the raw psth is
p=freq*5; % we want 5 modulations of the centre,so multiply by 5 to get outer mods
time=linspace(0, 2.5, resolution);
o=linspace(0, p*pi, resolution);
outer=sin(o-piphase); %work out outer with phase shift
x=find(outer<=rlevel);
outer(x)=rlevel;
outer=outer-rlevel;
outer=outer/max(outer);
i=linspace(0, 10*pi, resolution); %2pi * 5 modulations
inner=sin(i-piphase); %work out inner with phase shift
x=find(inner<=rlevel);
inner(x)=rlevel;
inner=inner-rlevel; %rectify so above 0
inner=inner/max(inner); %normalise to 1
interaction=inner-outer;
if max(interaction)>0; interaction= interaction / max(interaction); end%normalized to 1
interaction=interaction*pscale; %scale for the PSTH size
inner=inner*pscale;
pdata.interaction{a}=interaction';
pdata.inner{a}=inner';
end