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') |