-
Notifications
You must be signed in to change notification settings - Fork 3
/
makeToy.m
47 lines (47 loc) · 1.03 KB
/
makeToy.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
% makeToy:
load waveforms
[P,K]=size(waveforms);
%% Generate a background signal from a correlated noise model
% Note that there are better ways to do this:
ar1=.7;
numSeconds=60;
sampleRate=10000;
totalSamples=sampleRate*numSeconds;
xbackground=randn(totalSamples,1)*sqrt(1-ar1^2);
for t=2:totalSamples
xbackground(t)=xbackground(t-1)*(ar1)+xbackground(t);
end
%%
x=xbackground;
scale=7;
for k=1:K
waveforms(:,k)=waveforms(:,k)./(max(abs(waveforms(:,k)))./scale);
end
%% spike times:
sptimes=cell(K,1);
rate=5;
for k=1:K
numspikes=poissrnd(numSeconds*rate);
tmp=randi(totalSamples,numspikes,1);
tmp=sort(tmp);
dtmp=tmp(2:end)-tmp(1:end-1);
for t=numspikes-1:-1:1
if dtmp(t)<50;
tmp(t)=[];
end
end
tmp(tmp>totalSamples-P)=[];
sptimes{k}=tmp;
end
%% Add to X:
% first pass, just the exact waveform, no variability:
for k=1:K
for t=1:numel(sptimes{k})
tim=sptimes{k}(t);
q=tim:tim+P-1;
x(q)=x(q)+waveforms(:,k);
end
end
%%
X=x;
save toy X sampleRate sptimes