Functions | Variables

unlock/bci/decode/old/LRFB_3.m File Reference

Functions

function LRFB_3()%Version 3 delete (timerfindall)
interface with nidaq or winsound (guessing) if~isempty(findstr('nidaq'
 addchannel (ai, options.ai)
 set (ai,'InputType','SingleEnded')
 set (ai,'LoggingMode','Memory') setverify(ai.Channel
elseif ~isempty (findstr('winsound', options.aidevice_name)) ai
 h_rms (i)
 h_filt (i)
 h_text (i)
 title (['Channel ', num2str(options.ai(i))])%legend('Raw data'
id bkg_color ()
calculates threshold from
average of best calibrations 
load (sprintf('LRFBcalibration_%s%d_%d.mat', cohort, subject_id, calibration1))
 load (sprintf('LRFBcalibration_%s%d_%d.mat', cohort, subject_id, calibration2))
 Screen ('TextSize', wPtr, 72)
 DrawFormattedText (wPtr,'Start','center','center', wait_color)
 Screen (wPtr,'Flip')
end Screen ('FillRect', wPtr, bkg_color)

Variables

clear all
 options = paramSetupLRFB
pulls up GUI CHANGE EACH TIME subject_id = options.subject_ID
 calibration1 = options.calibration1
 calibration2 = options.calibration2
 block = options.block
 cohort = 'CY'
timing definitions sampleRate = 4000
Hz dataRate = 12
Hz filter_alpha = .95
interface with nidaq or
options aidevice_name 
ai = analoginput('nidaq','Dev1')
 actualRate = setverify(ai,'SampleRate',sampleRate)
ai SamplesPerTrigger = Inf
 InputRange
else return
end for loop to plot data
end for loop to plot RMF
end for loop to plot filter
for each channel 
h_fig = figure
for i
hold on
 RMS
Filtered end commands = {'Left','Right','Forward','Backward'}
 nTrials = 12
should be divisible by nListReps = ceil(nTrials/length(commands))
 command_list = repmat(commands',nListReps,1)
randomizes reorder_idx = randperm(size(command_list,1))
 win = 1
is default dims = [0 0 500 500]
 wait_color = 255
 go_color = [0 150 0]
 l_threshold = max(draw_rms(:,1))
 r_threshold = max(draw_rms(:,2))
 f_threshold = max(draw_rms(:,3))
 wink_threshold = max(draw_rms(:,4))
for bit calculations later nChoices = length(commands)
 nCorrect = 0
 total_t = 0
 STARTING [wPtr, rect] = Screen('OpenWindow',win,bkg_color,dims)
 tic
while toc< 2endfor i=1:nTrials all_data=zeros(1, 4);all_t=[];draw_t=[];draw_rms=zeros(1, 4);draw_y=[];Screen('TextSize', wPtr, 72);DrawFormattedText(wPtr, char(command_list(i)),'center','center', wait_color);Screen(wPtr,'Flip');tic;while toc< 2 end Screen('TextSize', wPtr, 72);DrawFormattedText(wPtr, char(command_list(i)),'center','center', go_color);t_start=Screen(wPtr,'Flip');tic;start(ai);t=0;while isrunning(ai)&&max(draw_rms(:, 4))< wink_threshold[emg_data, emg_t]=getdata(ai, actualRate/dataRate);t=toc;%concatenate all data all_data=[all_data;emg_data];all_t=[all_t;emg_t];draw_t=[draw_t;t];if~exist('draw_rms','var') draw_rms=[];end draw_rms=[draw_rms;zeros(1, size(emg_data, 2))];for j=1:length(options.ai) draw_rms(end, j)=sqrt(mean(emg_data(:, j).^2));%draw_rms=[draw_rms;sqrt(mean(emg_data(:, 1).^2)) sqrt(mean(emg_data(:, 2).^2))];end if~isempty(draw_y) draw_y=[draw_y;filter_alpha *draw_y(end,:)+(1-filter_alpha)*(draw_rms(end,:))];else draw_y=draw_rms(end,:);end end given_command=command_list(i);stop(ai);nSamples=length(draw_rms);window_idx=floor(nSamples *.20);if window_idx==0 window_idx=1;end window=draw_rms(window_idx:end,:);%classifier if((max(window(:, 1)))> l_threshold)&&((max(window(:, 2)))< r_threshold)&&((max(window(:, 3)))< f_threshold) movement= 'Left';elseif(max(window(:, 1))< l_threshold)&&(max(window(:, 2))> r_threshold)&&(max(window(:, 3))< f_threshold) movement= 'Right';elseif(max(window(:, 1))> l_threshold)&&(max(window(:, 2))>r_threshold)&&(max(window(:, 3))> f_threshold) movement= 'Forward';elseif(max(window(:, 1))> l_threshold)&&(max(window(:, 2))> r_threshold & max )(window(:, 3))< f_threshold) movement = 'Backward'
else movement = 'Unknown'
 t_end = Screen(wPtr,'Flip')

Function Documentation

addchannel ( ai  ,
options.  ai 
)
id bkg_color (  )  [virtual]
function LRFB_3 () % Version 3 delete ( timerfindall   ) 
DrawFormattedText ( wPtr  ,
'Start'  ,
'center'  ,
'center'  ,
wait_color   
)
h_filt ( i   ) 
h_rms ( i   ) 
h_text ( i   ) 
load ( sprintf('LRFBcalibration_%s%d_%d.mat', cohort, subject_id, calibration2  ) 
calculates threshold from average of best calibrations load ( sprintf('LRFBcalibration_%s%d_%d.mat', cohort, subject_id, calibration1  ) 
Screen ( wPtr  ,
'Flip'   
)
end Screen ( 'FillRect'  ,
wPtr  ,
bkg_color   
)
Screen ( 'TextSize'  ,
wPtr  ,
72   
)
set ( ai  ,
'InputType'  ,
'SingleEnded'   
)
set ( ai  ,
'LoggingMode'  ,
'Memory'   
)
title (  ) 
interface with nidaq or winsound ( guessing   ) 
elseif ~isempty ( findstr('winsound', options.aidevice_name)   ) 

Variable Documentation

actualRate = setverify(ai,'SampleRate',sampleRate)
interface with nidaq or options aidevice_name ai = analoginput('nidaq','Dev1')
close all
cohort = 'CY'
Filtered end commands = {'Left','Right','Forward','Backward'}
end for loop to plot data
Hz dataRate = 12
is default dims = [0 0 500 500]
Hz filter_alpha = .95
go_color = [0 150 0]
end for loop to plot filter for each channel h_fig = figure
for i
Initial value:
1:length(options.ai)
%     subplot(length(options.ai),1,i)
%     h_raw(i) = plot(0,0,'b')
while toc< 2endfor i = 1:nTrials all_data = zeros(1,4); all_t = []; draw_t = []; draw_rms = zeros(1,4); draw_y = []; Screen('TextSize',wPtr, 72); DrawFormattedText(wPtr,char(command_list(i)),'center','center',wait_color); Screen(wPtr,'Flip'); tic; while toc < 2 end Screen('TextSize',wPtr, 72); DrawFormattedText(wPtr,char(command_list(i)),'center','center',go_color); t_start = Screen(wPtr,'Flip'); tic; start(ai); t = 0; while isrunning(ai) && max(draw_rms(:,4)) < wink_threshold [emg_data,emg_t] = getdata(ai,actualRate/dataRate); t = toc; %concatenate all data all_data = [all_data; emg_data]; all_t = [all_t; emg_t]; draw_t = [draw_t; t]; if ~exist('draw_rms','var') draw_rms = []; end draw_rms = [draw_rms; zeros(1,size(emg_data,2))]; for j=1:length(options.ai) draw_rms(end,j) = sqrt(mean(emg_data(:,j).^2)); % draw_rms = [draw_rms; sqrt(mean(emg_data(:,1).^2)) sqrt(mean(emg_data(:,2).^2))]; end if ~isempty(draw_y) draw_y = [draw_y; filter_alpha*draw_y(end,:) + (1-filter_alpha)*(draw_rms(end,:))]; else draw_y = draw_rms(end,:); end end given_command = command_list(i); stop(ai); nSamples = length(draw_rms); window_idx = floor(nSamples*.20); if window_idx == 0 window_idx = 1; end window = draw_rms(window_idx:end,:); % classifier if ((max(window(:,1)))> l_threshold) && ((max(window(:,2)))< r_threshold) && ((max(window(:,3)))< f_threshold) movement = 'Left'; elseif (max(window(:,1))< l_threshold) && (max(window(:,2))> r_threshold)&&(max(window(:,3))< f_threshold) movement = 'Right'; elseif (max(window(:,1))> l_threshold) && (max(window(:,2))>r_threshold) && (max(window(:,3))> f_threshold) movement = 'Forward'; elseif (max(window(:,1))> l_threshold) && (max(window(:,2))> r_threshold& max)(window(:, 3))< f_threshold) movement = 'Backward'
else movement = 'Unknown'
for bit calculations later nChoices = length(commands)
nCorrect = 0
should be divisible by nListReps = ceil(nTrials/length(commands))
nTrials = 12
hold on
options = paramSetupLRFB
randomizes reorder_idx = randperm(size(command_list,1))
else return
end for loop to plot RMF
RMS
timing definitions sampleRate = 4000
STARTING[wPtr, rect] = Screen('OpenWindow',win,bkg_color,dims)
pulls up GUI CHANGE EACH TIME subject_id = options.subject_ID
t_end = Screen(wPtr,'Flip')
tic
total_t = 0
wait_color = 255
win = 1