Diff for "MEGSynch" - Meg Wiki
location: Diff for "MEGSynch"
Differences between revisions 1 and 2
Revision 1 as of 2016-04-06 15:41:26
Size: 3599
Editor: TiborAuer
Comment:
Revision 2 as of 2017-08-08 15:47:51
Size: 3799
Editor: JohanCarlin
Comment: replace attachment with github link
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
Line 8: Line 9:
Line 12: Line 12:

Any problems, report them to [[http://imaging.mrc-cbu.cam.ac.uk/imaging/TiborAuer|Tibor Auer]].
Any problems, report them to [[http://imaging.mrc-cbu.cam.ac.uk/imaging/JohanCarlin|Johan Carlin]].
Line 18: Line 17:

 * MEGSynch is available on MEG PC
 * From your desktop PC (Windows), you can also have a copy from `\\cbsu\data\Group\Imaging-Local\cbu\matlab`
 * You can also download it from [[attachment:MEGSynchClass.m|here]] (right-click and "Save As...")
 MEGSynch is already available on MEG PC. You can check out a personal copy from [[https://github.com/MRC-CBU/megsync|our github repo]].
Line 25: Line 21:
 * Default. Use only in MEG lab!   * Default. Use only in MEG lab!
Line 29: Line 25:
 . Default button mapping:
 || '''Button''' |||| '''Button name in MATLAB''' |||| '''Channel''' ||
 || 'Left Yellow' |||| 'LY' |||| 'S3' ||
 || 'Right Blue' |||| 'RB' |||| 'S4' ||
 || 'Right Yellow' |||| 'RY' |||| 'S5' ||
 || 'Right Green' |||| 'RG' |||| 'S6' ||
 || 'Right Red' |||| 'RR' |||| 'S7' ||
 Default button mapping:
 ||'''Button''' ||||<style="text-align:center">'''Button name in MATLAB''' ||||<style="text-align:center">'''Channel''' ||
 ||'Left Yellow' ||||<style="text-align:center">'LY' ||||<style="text-align:center">'S3' ||
 ||'Right Blue' ||||<style="text-align:center">'RB' ||||<style="text-align:center">'S4' ||
 ||'Right Yellow' ||||<style="text-align:center">'RY' ||||<style="text-align:center">'S5' ||
 ||'Right Green' ||||<style="text-align:center">'RG' ||||<style="text-align:center">'S6' ||
 ||'Right Red' ||||<style="text-align:center">'RR' ||||<style="text-align:center">'S7' ||

Line 47: Line 45:
Line 62: Line 61:
% MEG.SetButtonBoxReadoutTime(0.5); % block the whole buttonbox for 0.5s after button press  % MEG.SetButtonBoxReadoutTime(0.5); % block the whole buttonbox for 0.5s after button press
Line 68: Line 67:
while n ~= 10 rButtonRelease; % Wait for any button to be released while n ~= 10 rButtonRelease; % Wait for any button to be   released

MEGSynch

MEGSynch provides an interface for National Instruments PCI 6503 card used to capture all pulses (scanner synch pulse and button pulses alike) when using MATLAB.

For more information, type in MATLAB

help MEGSynchClass

N.B.: National Instruments PCI 6503 card does not monitor pulses in the background, so you have to make sure that you wait for any pulse before it comes!

Any problems, report them to Johan Carlin.

Obtain MEGSynch

  • MEGSynch is already available on MEG PC. You can check out a personal copy from our github repo.

Using MEGSynch

Initialise

  • Default. Use only in MEG lab!
  • MEG = MEGSynchClass;
    
    Default button mapping:

    Button

    Button name in MATLAB

    Channel

    'Left Yellow'

    'LY'

    'S3'

    'Right Blue'

    'RB'

    'S4'

    'Right Yellow'

    'RY'

    'S5'

    'Right Green'

    'RG'

    'S6'

    'Right Red'

    'RR'

    'S7'

  • To change button mapping:
  • MEG = MEGSynchClass({'B1','S4';'B2','S5'}); % specify button names "B1" and "B2" and maps them to S4 and S5
    
  • Emulation:
  • MEG = MEGSynchClass(1);   % full emulation
    

Close

MEGSynchClass has a destructor, which is automatically triggered if the object is deleted (e.g. clear, returning function). If you use a script, however, it does not perform any auto-clear, so you have to destroy the object manually:

  • MEG.delete;
    

Send trigger

  • for v = 0:255  % send triggers 0 to 255 ...
        pause(0.1) % ... in every 100ms
        MEG.SendTrigger(v)
    end
    

Capture button presses

  • MEG.SetButtonReadoutTime(0.5);      % block individual buttons for 0.5s after button press so we will not detect the same button press twice
    % MEG.SetButtonBoxReadoutTime(0.5); % block the whole buttonbox for 0.5s after button press
    % MEG.Keys = {'f1','f2','f3','f4'}; % emulation Buttons #1-#4 with F1-F4
    n = 0;
    % MEG.BBoxTimeout = 1.5;            % Wait for button press for 1.5s
    % MEG.BBoxTimeout = -1.5;           % Wait for button press for 1.5s even in case of response
    MEG.ResetClock;
    while n ~= 10 rButtonRelease;     % Wait for any button to be   released
        % MEG.WaitFo                      % polls 10 button presses
        MEG.WaitForButtonPress;         % Wait for any button to be pressed
        % MEG.WaitForButtonPress([],2); % Wait for Button #2
        % MEG.WaitForButtonPress(2);    % Wait for any button for 2s (overrides MEG.BBoxTimeout only for this event)
        % MEG.WaitForButtonPress(-2);   % Wait for any button for 2s even in case of response (overrides MEG.BBoxTimeout only for this event)
        % MEG.WaitForButtonPress(2,2);  % Wait for Button #2 for 2s (overrides MEG.BBoxTimeout only for this event)
        % MEG.WaitForButtonPress(-2,2); % Wait for Button #2 for 2s even in case of response (overrides MEG.BBoxTimeout only for this event)
        n = n + 1;
        fprintf('At %2.3fs, ',MEG.Clock);
        fprintf('Button %d ',MEG.LastButtonPress);
        fprintf('pressed: %2.3fs\n',MEG.TimeOfLastButtonPress);
    end
    

CbuMeg: MEGSynch (last edited 2017-08-08 15:48:21 by JohanCarlin)