You are on page 1of 3

4/4/2016

MatlabcodetoreadMeditationusingMindwaveMobile

MatlabcodetoreadMeditationusingMindwavemobile

%ClearScreen
clc
%ClearVariables
clearall
%Closefigures
closeall

%Preallocatebuffer
data_med=zeros(1,256)

%ComportSelection
portnum1=7
%COMPort#
comPortName1=sprintf('\\\\.\\COM%d',portnum1)

%BaudrateforusewithTG_Connect()andTG_SetBaudrate().
TG_BAUD_115200=115200

%DataformatforusewithTG_Connect()andTG_SetDataFormat().
TG_STREAM_PACKETS=0
%DatatypethatcanberequestedfromTG_GetValue().

TG_DATA_MEDITATION=3

%loadthinkgeardll
loadlibrary('Thinkgear.dll')

%TodisplayinCommandWindow
fprintf('Thinkgear.dllloaded\n')

%getdllversion
dllVersion=calllib('Thinkgear','TG_GetDriverVersion')

%Todisplayincommandwindow
fprintf('ThinkGearDLLversion:%d\n',dllVersion)

%GetaconnectionIDhandletoThinkGear
connectionId1=calllib('Thinkgear','TG_GetNewConnectionId')
if(connectionId1<0)
https://www.pantechsolutions.net/matlabcodetoreadmeditationusingmindwavemobile

1/3

4/4/2016

MatlabcodetoreadMeditationusingMindwaveMobile

error(sprintf('ERROR:TG_GetNewConnectionId()returned%d.\n',connectionId1))
end

%AttempttoconnecttheconnectionIDhandletoserialport"COM3"

errCode

calllib('Thinkgear',

'TG_Connect',

connectionId1,comPortName1,TG_BAUD_115200,TG_STREAM_PACKETS)
if(errCode<0)
error(sprintf('ERROR:TG_Connect()returned%d.\n',errCode))
end

fprintf('Connected.ReadingPackets...\n')

i=0
j=0

%TodisplayinCommandWindow

disp('ReadingBrainwaves')

figure
whilei<20
if(calllib('Thinkgear','TG_ReadPackets',connectionId1,1)==1)%ifapacketwasread...
if(calllib('Thinkgear','TG_GetValueStatus',connectionId1,TG_DATA_MEDITATION)~=0)
j=j+1
i=i+1
%ReadattentionValusfromthinkgearpackets
data_med(j)=calllib('Thinkgear','TG_GetValue',connectionId1,TG_DATA_MEDITATION)
%TodisplayinCommandWindow
disp(data_med(j))
%PlotGraph
plot(data_med)

title('Meditation')
%Delaytodisplaygraph
pause(1)
end
end
end

%TodisplayinCommandWindow
disp('LoopCompleted')
https://www.pantechsolutions.net/matlabcodetoreadmeditationusingmindwavemobile

2/3

4/4/2016

MatlabcodetoreadMeditationusingMindwaveMobile

%Releasethecommport
calllib('Thinkgear','TG_FreeConnection',connectionId1)

https://www.pantechsolutions.net/matlabcodetoreadmeditationusingmindwavemobile

3/3

You might also like