Menu

[09bd5b]: / matlab / artificial_data2.m  Maximize  Restore  History

Download this file

187 lines (167 with data), 3.9 kB

  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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function [single_trials_noisy single_trials range rts real_rt erp] = ...
artificial_data(trials, srate, beta);
% function [single_trials_noisy single_trials range rts real_rt erp] = ...
% artificial_data(trials, srate, beta);
%clear all;
%close all;
real_rt = 800; % "real" (u) reaction time
sd_rt = 100;
%srate = 1000; % sampling rate (Hz)
% sets: 0.8/1000; 0/100; 2/5000
noisebeta= 0;
%noiseamp = 100;
%trials = 100;
plotit = 1;
rts = [];
rand('state',sum(100*clock))
step = 1000/srate;
if plotit,figure; end;
range = -500:step:1998; % in ms
% ERP - Spline interpolation
%fixp = [0 0; 100 10; 200 -10; 300 20; 500 0; 800 0;]
fixp1 = [
-500 0.8;
-450 -0.5;
-380 0.4;
-333 0.2;
-150 2;
0 0;
50 -3;
100 4.3;
200 -13;
250 -2;
300 -3;
500 15;
600 8;
700 10;
900 -2;
1000 0.5;
1200 -3;
1500 2;
1950 -2;
2000 0;
];
fixp2 = [
-500 0.8;
-450 0.5;
-380 0.4;
-333 0.2;
-150 2;
0 0;
80 3;
100 -4.3;
200 13;
250 2;
300 3;
400 10;
500 -15;
600 3;
6500 -10;
900 -2;
1000 10;
1200 -3;
1500 7;
1950 -2;
2000 10;
];
fixp=fixp2;
erp = spline(fixp(:,1), fixp(:,2), range);
noiseamp = max(erp)*100;
if plotit
subplot(3,2,1);
plot(range, erp);
title('Simulated "real" ERP');
xlim([range(1) range(end)]);
subplot(3,2,3);
end;
% generating the phi_i
% points in sampling notation
zero = closest(range, 0);
rresp = closest(range, real_rt);
single_trials = [];
for i = 1:trials
rt = real_rt + sd_rt*randn(1); % gaussian rt
rts = [rts rt];
k = 1;
trans = interp1([range(1) 0 real_rt range(end)],...
[range(1) 0 rt range(end)],...
range);
trans(zero:rresp-1) = get_monotonous_function([0 0],...
[real_rt rt], step);
terp = interp1(trans, erp, range)';
alpha = rand+0.5;
% alpha=abs(randn+1);
terp = alpha*terp;
if plotit
plot(range, terp, 'r');
if i==1
hold on
end;
end;
single_trials = [single_trials terp];
end;
[N p] = size(single_trials);
single_trials_noisy=[];
for i=1:p
% 1150 for beta=0
% 5000 for beta=0.5
% 15000 for beta=1
% 32000 for beta=1.5
% 55000 for beta=2.0
if beta==0
namp=1000;
elseif beta==0.5
namp=5000;
elseif beta==1.0
namp=15000;
elseif beta==1.5
namp=32000;
elseif beta==2.0
namp=55000;
else
disp('ERROR');
return;
end;
noise = (fBm(beta, N)).*namp;
single_trials_noisy(:,i) = single_trials(:,i)+noise;%30*randn(N,1);%noise;
end;
if ~plotit
plot(range, trans, 'b');
hold on;
plot(trans, range, 'r');
xlim([range(1) range(end)]);
hold off;
end;
if plotit
title(sprintf('Single trials, generated with gaussian rts with sd=%i', sd_rt));
xlim([range(1) range(end)]);
hold off;
subplot(3,2,2);
plot(range, trans, 'b');
hold on;
plot(trans, range, 'r');
title(sprintf('Sample phi_i and its inverse for rt=%3.2f', rt));
xlim([range(1) range(end)]);
hold off;
subplot(3,2,4);
plot(range, mean(single_trials, 2));
hold on
plot(range, mean(single_trials,2)-erp', 'k');
title('Mean of single trials (black curve is error)');
xlim([range(1) range(end)]);
hold off;
subplot(3, 2, 5);
[N p] = size(single_trials);
plot(range, single_trials_noisy(:,i));
title(sprintf('Sample Trial with 1/f noise added, beta=%.1f',noisebeta));
xlim([range(1) range(end)]);
hold off;
subplot(3, 2, 6);
[N p] = size(single_trials);
plot(range, mean(single_trials_noisy, 2));
hold on;
%plot(range, mean(single_trials_noisy,2)-erp', 'k');
title(sprintf('Mean of trials with 1/f noise added, beta=%.1f',noisebeta));
xlim([range(1) range(end)]);
hold off;
end;
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.