-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp300_speller.m
463 lines (232 loc) · 8.35 KB
/
p300_speller.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
%%frame_rate (每次閃的時間)
%%trial (實驗刺激數)
%%sound :25 (聽到25個子母的其中五個)
function p300_speller()
clc
clear all
exp_alphabet
end
%顯示字母(黑底 先灰階再變白字(framerate)) %gui (調控實驗)
function exp_alphabet()
clear global all
global wptr wrect;
sti_sc=0.015;
iti_sc=0.05;
size_char=80;text_color_old=125;text_color_new=255;
[wptr,wrect]=Screen('OpenWindow',0,0);%numberofbuffer flip 暫存
x=300;y=0;
Screen('TextSize',wptr,size_char);
Screen('TextColor',wptr,text_color_old);
initial(wptr,x,y,size_char,text_color_old);
%Screen('TextBackgroundColor',wptr,[125,0,0,50]); 字的背景色
%Screen('Flip',wptr);%使用於前後台設定(換frame)
Screen('Flip',wptr);
a=shuffle();%row_column_stimulus
start=GetSecs;%精準時間stay 3 秒
WaitSecs('UntilTime',start+3);
rand_begin(wptr,x,y,size_char,text_color_old,text_color_new,a,sti_sc,iti_sc);
%Screen('Flip',wptr);
Screen('Close',wptr);
end
function a=shuffle()
for j=1:100
a(j)=j;
end
for i=1:100
tmp=a(i);
ans=rem(randi(65536),101-i)+1;
a(i)=a(ans);
a(ans)=tmp;
end
end
function rand_begin(wptr,x,y,size_char,text_color_old,text_color_new,a,sti_sc,iti_sc)%shuffl
for i=1:100
if rem(a(i),10) ==0
sti_row_1(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==1
sti_row_2(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==2
sti_row_3(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc); initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==3
sti_row_4(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==4
sti_row_5(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==5
column_1(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==6
column_2(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==7
column_3(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==8
column_4(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
elseif rem(a(i),10)==9
column_5(wptr,x,y,size_char,text_color_old,text_color_new);
Screen('Flip',wptr);
WaitSecs(sti_sc);
initial(wptr,x,y,size_char,text_color_old);
Screen('Flip',wptr);
WaitSecs(iti_sc);
end
end
end
function initial(wptr,x,y,size_char,text_color_old)
row_old_1(wptr,x,y,size_char,text_color_old);
row_old_2(wptr,x,y,size_char,text_color_old);
row_old_3(wptr,x,y,size_char,text_color_old);
row_old_4(wptr,x,y,size_char,text_color_old);
row_old_5(wptr,x,y,size_char,text_color_old);
end
function sti_row_1(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
row_old_1(wptr,x,y,size_char,text_color_new);
end
function sti_row_2(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
row_old_2(wptr,x,y,size_char,text_color_new);
end
function sti_row_3(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
row_old_3(wptr,x,y,size_char,text_color_new);
end
function sti_row_4(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
row_old_4(wptr,x,y,size_char,text_color_new);
end
function sti_row_5(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
row_old_5(wptr,x,y,size_char,text_color_new);
end
function column_1(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
Screen('DrawText',wptr,'A',x,y);
Screen('DrawText',wptr,'F',x,y+size_char*2);
Screen('DrawText',wptr,'K',x,y+size_char*4);
Screen('DrawText',wptr,'P',x,y+size_char*6);
Screen('DrawText',wptr,'U',x,y+size_char*8);
end
function column_2(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
Screen('DrawText',wptr,'B',x+size_char*2,y);
Screen('DrawText',wptr,'G',x+size_char2,y+size_char2);
Screen('DrawText',wptr,'L',x+size_char2,y+size_char4);
Screen('DrawText',wptr,'Q',x+size_char2,y+size_char6);
Screen('DrawText',wptr,'V',x+size_char2,y+size_char8);
end
function column_3(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
Screen('DrawText',wptr,'C',x+size_char*4,y);
Screen('DrawText',wptr,'H',x+size_char4,y+size_char2);
Screen('DrawText',wptr,'M',x+size_char4,y+size_char4);
Screen('DrawText',wptr,'R',x+size_char4,y+size_char6);
Screen('DrawText',wptr,'W',x+size_char4,y+size_char8);
end
function column_4(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
Screen('DrawText',wptr,'D',x+size_char*6,y);
Screen('DrawText',wptr,'I',x+size_char6,y+size_char2);
Screen('DrawText',wptr,'N',x+size_char6,y+size_char4);
Screen('DrawText',wptr,'S',x+size_char6,y+size_char6);
Screen('DrawText',wptr,'X',x+size_char6,y+size_char8);
end
function column_5(wptr,x,y,size_char,text_color_old,text_color_new)
initial(wptr,x,y,size_char,text_color_old);
Screen('TextColor',wptr,text_color_new);
Screen('DrawText',wptr,'E',x+size_char*8,y);
Screen('DrawText',wptr,'J',x+size_char8,y+size_char2);
Screen('DrawText',wptr,'O',x+size_char8,y+size_char4);
Screen('DrawText',wptr,'T',x+size_char8,y+size_char6);
Screen('DrawText',wptr,'Y',x+size_char8,y+size_char8);
end
function row_old_1(wptr,x,y,size_char,text_color_old)
Screen('TextColor',wptr,text_color_old);
Screen('DrawText',wptr,'A',x,y);
Screen('DrawText',wptr,'B',x+size_char*2,y);
Screen('DrawText',wptr,'C',x+size_char*4,y);
Screen('DrawText',wptr,'D',x+size_char*6,y);
Screen('DrawText',wptr,'E',x+size_char*8,y);
end
function row_old_2(wptr,x,y,size_char,text_color_old)
Screen('TextColor',wptr,text_color_old);
Screen('DrawText',wptr,'F',x,y+size_char*2);
Screen('DrawText',wptr,'G',x+size_char2,y+size_char2);
Screen('DrawText',wptr,'H',x+size_char4,y+size_char2);
Screen('DrawText',wptr,'I',x+size_char6,y+size_char2);
Screen('DrawText',wptr,'J',x+size_char8,y+size_char2);
end
function row_old_3(wptr,x,y,size_char,text_color_old)
Screen('TextColor',wptr,text_color_old);
Screen('DrawText',wptr,'K',x,y+size_char*4);
Screen('DrawText',wptr,'L',x+size_char2,y+size_char4);
Screen('DrawText',wptr,'M',x+size_char4,y+size_char4);
Screen('DrawText',wptr,'N',x+size_char6,y+size_char4);
Screen('DrawText',wptr,'O',x+size_char8,y+size_char4);
end
function row_old_4(wptr,x,y,size_char,text_color_old)
Screen('TextColor',wptr,text_color_old);
Screen('DrawText',wptr,'P',x,y+size_char*6);
Screen('DrawText',wptr,'Q',x+size_char2,y+size_char6);
Screen('DrawText',wptr,'R',x+size_char4,y+size_char6);
Screen('DrawText',wptr,'S',x+size_char6,y+size_char6);
Screen('DrawText',wptr,'T',x+size_char8,y+size_char6);
end
function row_old_5(wptr,x,y,size_char,text_color_old)
Screen('TextColor',wptr,text_color_old);
Screen('DrawText',wptr,'U',x,y+size_char*8);
Screen('DrawText',wptr,'V',x+size_char2,y+size_char8);
Screen('DrawText',wptr,'W',x+size_char4,y+size_char8);
Screen('DrawText',wptr,'X',x+size_char6,y+size_char8);
Screen('DrawText',wptr,'Y',x+size_char8,y+size_char8);
end