-
Notifications
You must be signed in to change notification settings - Fork 3
/
phaseonly_mdl_1.m
70 lines (46 loc) · 1.15 KB
/
phaseonly_mdl_1.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
clear all;clc;
close all;
fs = 1000;
Ts = 1/fs;
% ======= make stim =======
stim = zeros(200,1)';
ioilist = [100, 100, 100, 100, 100*6];% [200, 200, 300, 600, 250];
for i = 1:length(ioilist)
x = zeros(ioilist(i),1)';
x(1) = 2;
stim = [stim x];
end
% ======= init params =======
theta = 0;
mdl_freq = 4; % fs/samples << initial freq
freq = mdl_freq;
k = 1;
t = Ts;
wave = [];
phasek = [];
while 1
if stim(k) > 0 % if you see a stimulus (sound)
% check your phase
currpha = (t*(2*pi*freq)+theta);
end
% -------------- save timepoint info --------------
wave(k) = cos(t*(2*pi*freq)+theta);
phasek(k) = t*(2*pi*freq)+theta;
% increase time
t = t+Ts;
if k == length(stim)
break
end
k = k+1;
end
figure;
subplot(2,1,1)
hold on;
EK_xAxisMarker(find(stim>0), [0 0 1]);
plot(wave, 'linewidth', 2, 'color', 'm');
EK_plotlabels('time', 'cos()', 'wave',18);
subplot(2,1,2)
hold on;
EK_xAxisMarker(find(stim>0), [0 0 1]);
plot(phasek, 'linewidth', 2, 'color', 'm');
EK_plotlabels('time', 'phase', 'phase',18);