MATLAB编程之PTB:简单的P300脑电实验

为了验证设备的可靠性,编写了一个诱发脑电P300的odd-ball范式,因为采集信号的方式不同,可能打marker的方式也就不一样,所以我就把自己给串口发送trriger的代码省略了,有需要的话可以在下面的代码的基础上加上发送trriger的代码即可。

clear all;
clc;
fixation = imread('experiment2\cross.bmp');
blank = imread('experiment2\blank.bmp'); 
KbName('UnifyKeyNames');  
subinfo=getSubInfo;       %获取被试信息
if isempty(subinfo)
    return
end
firstKey=KbName('1');        %左边的按f,右边的按j
secondKey=KbName('2');
spaceKey = KbName('space');
wptr = Screen('OpenWindow',0,128);
s = double('同学您好,欢迎参加本次实验,接下来您将会看到两个符号,\n如果出现$时请按1,出现¥请按2,请您尽快作出反应');
oldtxcolor = Screen('TextColor',wptr);
DrawFormattedText(wptr,s,'center','center',0,15,[],[],2);
Screen('Flip',wptr);
Screen('TextColor',wptr,oldtxcolor);
while true
     [~,~,keycode]=KbCheck;
     if keycode(spaceKey)
        break;                            %等待按空格键
     end
end
sequence = [1,1,1,1,2];
for i = 1:500
    A = randperm(numel(sequence));
    flag = sequence(A(1));
    tex = Screen('MakeTexture',wptr,fixation);      %显示注视点
    Screen('DrawTexture',wptr,tex,[]);
    Screen('Flip', wptr);
    WaitSecs(0.1);
    [x,y]=WindowCenter(wptr);
    Screen('TextSize',wptr,55);
    if flag == 1
       stimulus = double('$');
       fwrite(com,40);
       DrawFormattedText(wptr,stimulus,x,y,[0,128,0]);
       Screen('Flip',wptr);
       Screen('TextColor',wptr,oldtxcolor);
       WaitSecs(0.25);
       DrawFormattedText(wptr,'',x,y);
       Screen('Flip',wptr);
       Screen('TextColor',wptr,oldtxcolor);
    end
    if flag == 2
       stimulus = double('¥');
       fwrite(com,50);
       DrawFormattedText(wptr,stimulus,x,y,[255,0,0]);
       Screen('Flip',wptr);
       Screen('TextColor',wptr,oldtxcolor);
       WaitSecs(0.25);
       DrawFormattedText(wptr,'',x,y);
       Screen('Flip',wptr);
       Screen('TextColor',wptr,oldtxcolor);
    end
      
    while true
            [~,~,keycode]=KbCheck;%获取被试反应后的时间                  
            if keycode(firstKey)
                break;
            end
            if keycode(secondKey)              
                break;
            end
    end
    KbWait;
    tex = Screen('MakeTexture',wptr,blank);         %显示空白图片
    Screen('DrawTexture',wptr,tex,[]);
    Screen('Flip', wptr);
    WaitSecs(0.5); 
end
sca;
disp('finish');

上面字符串使用double时为了解决编码问题,使得在某台机器上编写在其他机器上不会出现乱码问题。

  • 8
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值