Diff for "MEGSynch" - CBU MRI facility Wiki
location: Diff for "MEGSynch"
Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2016-02-23 15:04:51
Size: 4399
Editor: TiborAuer
Comment:
Revision 6 as of 2016-02-23 15:16:36
Size: 4254
Editor: TiborAuer
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= ScannerSynch =
ScannerSynch provides an interface for National Instruments PCI 6503 card used to capture all pulses (scanner synch pulse and button pulses alike).
= 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.
Line 6: Line 6:
help ScannerSynchClass help MEGSynchClass
Line 17: Line 17:
== Obtain ScannerSynch == == Obtain MEGSynch ==
Line 19: Line 19:
 * ScannerSynch is available on all relevant PCs (StimPCs, "mimic" PC)  * MEGSynch is available on MEG PC
Line 21: Line 21:
 * You can also download it from [[attachment:ScannerSynchClass.m|here]] (right-click and "Save As...")  * You can also download it from [[attachment:MEGSynchClass.m|here]] (right-click and "Save As...")
Line 23: Line 23:
== Using ScannerSynch == == Using MEGSynch ==
Line 25: Line 25:
 * Default. Use only if device (scanner, pulse emulator) is connected (only in StimPCs and mimic PC)!  * Default. Use only in MEG lab!
Line 27: Line 27:
SSO = ScannerSynchClass; MEG = MEGSynchClass;
Line 29: Line 29:
 * Emulations:  . Default button mapping:
 . || 'LY' |||| 'S3' ||
Line 31: Line 32:
SSO = ScannerSynchClass(1); % emulate scanner synch pulse MEG = MEGSynchClass({'B1','S4';'B2','S5'}); % specify button names "B1" and "B2" and maps them to S4 and S5
Line 33: Line 34:
 * Emulation:
Line 34: Line 36:
SSO = ScannerSynchClass(0,1); % emulate button box
}}}
 . {{{#!highlight matlab numbers=off
SSO = ScannerSynchClass(1,1); % emulate scanner synch pulse and button box
MEG = MEGSynchClass(1); % full emulation
Line 41: Line 40:
!ScannerSynchClass 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: !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:
Line 43: Line 42:
SSO.delete; MEG.delete;

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 Tibor Auer.

Obtain MEGSynch

  • 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 here (right-click and "Save As...")

Using MEGSynch

Initialise

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

    'LY' |||| 'S3' ||

  • 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;
    

Capture scanner synch pulse

  • Simple case
  • SSO.SetSynchReadoutTime(0.5); % make sure that you do not detect the same pule twice
    SSO.TR = 2;                   % allows detecting missing pulses
    while SSO.SynchCount < 10     % polls 10 pulses
        SSO.WaitForSynch;
        fprintf('Pulse %d: %2.3f. Measured TR = %2.3fs\n',...
            SSO.SynchCount,...
            SSO.TimeOfLastPulse,...
            SSO.MeasuredTR);
    end
    
  • Chance for missing pulse
  • SSO.SetSynchReadoutTime(0.5);  % make sure that you do not detect the same pule twice
    SSO.TR = 2;                    % allows detecting missing pulses
    while SSO.SynchCount < 10      % until 10 pulses
        WaitSecs(Randi(100)/1000); % in every 0-100 ms ...
        if SSO.CheckSynch(0.01)    % ... waits for 10 ms for a pulse
            fprintf('Pulse %d: %2.3f. Measured TR = %2.3fs. %d synch pulses has/have been missed\n',...
                SSO.SynchCount,...
                SSO.TimeOfLastPulse,...
                SSO.MeasuredTR,...
                SSO.MissedSynch);
        end
    end
    

Capture button presses

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