Functions |
| function | Calibrate_LRFB () daqreset |
| | delete (timerfindall) |
| if | ~isempty (findstr('nidaq', options.aidevice_name)) ai |
| | 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' |
| Filtered end | subplot (length(options.ai)+1, 1, length(options.ai)+1) h_key |
| | title ('Keypress') set(gcf |
| evt | ProcessKeyboard (h_obj, evt)) |
| | pause ()%does not work well in MATLAB 7.4 because of window focus problems%use this instead waiting |
| | while (waiting) drawnow end set(texthandle |
| id | quit () |
| | start (ai) running |
| while | isrunning (ai)&&running%get EMG data(this blocks until it gets the data it wants)[emg_data |
| handle any keypress if | ~exist ('draw_rms','var') draw_rms |
| | zeros (1, size(emg_data, 2))] |
sqrt(mean(emg_data(:,
1).^2)) sqrt(mean(emg_data(end
if | ~isempty (draw_y) draw_y |
| filter_alpha * | draw_y (end,:)+(1-filter_alpha)*(draw_rms(end |
| end end | stop (ai)%delete(texthandle) |
| | save (fullfile(path, file),'all_t','all_data','draw_t','draw_rms','draw_y','draw_keypress') |
| if | strmatch (evt.Key,'escape','exact') running=0 |
| end | if (waiting) waiting=0 |
Variables |
| clear | all |
| | options = paramSetup |
| timing definitions | sampleRate = 4000 |
| Hz | dataRate = 12 |
| Hz | filter_alpha = .95 |
| | actualRate = setverify(ai,'SampleRate',sampleRate) |
| ai | SamplesPerTrigger = Inf |
| | InputRange |
| else | return |
| end | h_fig = figure |
| for | i |
| hold | on |
| | RMS |
| | KeyPressFcn |
| | h_obj |
| | keypress = 0 |
| | all_length = 100*actualRate |
| | all_data = zeros(all_length,2) |
| | all_t = zeros(all_length,1) |
| | draw_length = 100*dataRate |
| | draw_t = zeros(draw_length,1) |
| | draw_rms = zeros(draw_length,2) |
| | draw_y = zeros(draw_length,2) |
| | draw_keypress = zeros(draw_length,1) |
| | texthandle = text(0,0,'Press any key to begin','HorizontalAlignment','center') |
| | String |
| | tic |
| now we start | t = 0 |
| while | emg_t = getdata(ai,actualRate/dataRate) |
| if you want to FAKE | emg_data = [.5 + .5*sin(emg_t) .5 + .5*cos(emg_t)] |
| | drawnow |
| | function [] |