= Tutorial 5: Review continuous files =
''Authors: Francois Tadel, Elizabeth Bock, John C Mosher, Sylvain Baillet''

<<TableOfContents(2,2)>>

== Presentation of the experiment ==
A full description of this dataset is available on this page:  [[http://neuroimage.usc.edu/brainstorm/DatasetAuditory|MEG auditory dataset]].

==== Experiment ====
 * One subject, two acquisition runs of 6 minutes each
 * Subject stimulated binaurally with intra-aural earphones (air tubes+transducers)
 * Each run contains:
  * 200 regular beeps (440Hz)
  * 40 easy deviant beeps (554.4Hz, 4 semitones higher)
 * Random inter-stimulus interval: between 0.7s and 1.7s seconds, uniformly distributed
 * The subject presses a button when detecting a deviant
 * Auditory stimuli generated with the Matlab Psychophysics toolbox

==== MEG acquisition ====
 * Acquisition at '''2400Hz''', with a '''CTF 275''' system at the MNI, subject in seating position
 * Online 600Hz low-pass filter, files saved with the 3rd order gradient
 * Recorded channels (340):
  * 1 Stim channel indicating the presentation times of the audio stimuli: UDIO001 (#1)
  * 1 Audio signal sent to the subject: UADC001 (#316)
  * 1 Response channel recordings the finger taps in response to the deviants: UPPT001 (#2)
  * 26 MEG reference sensors (#5-#30)
  * 274 MEG axial gradiometers (#31-#304)
  * 2 EEG electrodes: Cz, Pz (#305 and #306)
  * 1 ECG bipolar (#307)
  * 2 EOG bipolar (vertical #308, horizontal #309)
  * 12 Head tracking channels: Nasion XYZ, Left XYZ, Right XYZ, Error N/L/R (#317-#328)
  * 20 Unused channels (#3, #4, #310-#315, #329-340)
 * 3 datasets:
  * '''S01_AEF_20131218_01.ds''': Run #1, 360s, 200 standard + 40 deviants
  * '''S01_AEF_20131218_02.ds''':  Run #2, 360s, 200 standard + 40 deviants
  * '''S01_Noise_20131218_01.ds''': Empty room recordings, 30s long
  * File name: S01=Subject01, AEF=Auditory evoked field, 20131218=date(Dec 18 2013), 01=run
 * Use of the .ds, not the AUX (standard at the MNI) because they are easier to manipulate in FieldTrip

==== Head shape and fiducial points ====
 * 3D digitization using a Polhemus Fastrak device driven by Brainstorm ('''S01_20131218_*.pos''') More information: [[http://neuroimage.usc.edu/brainstorm/Tutorials/TutDigitize|Digitize EEG electrodes and head shape]]
 * The output file is copied to each .ds folder and contains the following entries:
  * The position of the center of CTF coils
  * The position of the anatomical references we use in Brainstorm:
  Nasion and connections tragus/helix, as illustrated [[http://neuroimage.usc.edu/brainstorm/CoordinateSystems#Pre-auricular_points_.28LPA.2C_RPA.29|here]].
 * Around 150 head points distributed on the hard parts of the head (no soft tissues)

= From Continuous =
== Review the recordings ==
=== Open the file ===
Right-click on the data file > MEG (all) > Display time series.

{{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawViewer?action=AttachFile&do=get&target=displayTsMenu.gif|displayTsMenu.gif|class="attachment"}}

You can see new information in the tab "Record" and a figure showing the recordings.

{{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawViewer?action=AttachFile&do=get&target=rawPanel.gif|rawPanel.gif|class="attachment"}}

=== Navigate in time ===
As described  in the basic tutorials, you can set the current time by using either  the time panel (buttons and text field), or the figure (click on the  white or grey areas of the figure). But you can notice that only a few  seconds are visible in the figure, while the time panel (top left of the  previous figure), indicates that we have 360s of recordings. Only a  small block of the continuous file has been loaded in memory. This small  time window can be configured with the tab '''Record/Page settings''', with the text boxes '''Start''' and '''Duration'''.

The  time series figure is similar to the ones that were presented in the  previous tutorials, with a few new elements. The navigation bar at the  bottom represents the time of the entire raw file, where the events are  also represented by dots. The '''<<<''' and '''>>>'''  buttons are the same as the ones in the time panel, and jump to the  previous/next segment in the file. Clicking on the bar or dragging the  red cursor change the current time window as well.

== Channel selection and bad channels ==
If you click on the lines instead of the white area: select channels.

=== Sensor selection ===
Let's switch  to a nicer representation of the recordings time series: click on the  "Display mode" button in the toolbar of the Record tab.

{{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawViewer?action=AttachFile&do=get&target=tsColumn.gif|tsColumn.gif|class="attachment"}}

Now  the traces are displayed in columns, but all the channels are displayed  in the same figure, which makes it unreadable. Select a subset of  channels by right-clicking on the figure > '''Montages''', with the drop-down menu in the Record tab or with a keyboard shortcut ('''Shift+A, B, C'''...).  Default groups of sensors are available for some MEG systems, but you  can also create your own groups of sensors with the menu "Edit  montages". The montage editor is described in the next tutorial.

{{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawViewer?action=AttachFile&do=get&target=tsChannelSelection.gif|tsChannelSelection.gif|class="attachment"}}

=== Amplitude scale ===
In this display mode, the amplitude scale is represented on the right of the figure. You can adjust this vertical scale:

 * Use the buttons "'''^'''" and "'''v'''"  on the right side of the figure. The shortcuts for those buttons are  indicated in the tooltips (leave the mouse for a short while over a  button)
 * Hold the '''Shift key''' and move the mouse wheel, or use the keys "'''+'''" and "'''-'''".
 * Use the button "'''...'''" on the right side of the figure ("Set scale manually") to set the scale to a precise level.

When  scrolling in time to a different page, the amplitude scale is by  default kept. You can change this behavior to re-evaluate automatically  an optimal scale each time you change the current time window. This  option is called "Auto-scale amplitude" and is disabled by default. To  activate it: click on the "'''AS'''" button on the right of the figure, or check the menu "'''Display > Auto-scale amplitude'''" in the Record tab.

=== Display options ===
 . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawViewer?action=AttachFile&do=get&target=displayOptions.gif|displayOptions.gif|class="attachment"}}

 * '''Remove DC offset''':  Button [DC] in the Record tab. When selected, for each channel, the  average value over the  entire current time window is subtracted from  the channel values. This means that if you change the length of  the  time window, the value that is removed from each channel may change.  It  doesn't make much sense to disable this option for unprocessed MEG  recordings.

 * '''Apply CTF compensation''':  Button [CTF] in the Record tab. Enable/disable the CTF noise correction   based on the reference sensors, when it is not already applied in the   file. In the current file, the CTF 3rd order gradient compensation is   already applied, therefore this option is not available.
 * '''Flip +/-''': Button in the right part of the time series figure. Exchange the direction of the Y axis, useful mostly for clinical EEG.
 * '''Set scale manually''': Button [...] in the figure. Forces a defined amplitude scaling.
 * '''Auto-scale amplitude''':  Button [AS] in the figure. When  selected, the vertical scale is  adapted to the maximum value over the time window when the time window  changes. When  not selected: the vertical scales keeps its last value  when you jump to  another part of the file.

=== Online filter ===
With  the  Filter tab, you can apply a band-pass  filter to the recordings, or  remove a set of specific frequencies  (example: the 50Hz or 60Hz power  lines contamination and their harmonics). The filters are applied only  to the time window that is currently loaded; hence if the segment is too  short for the required filters, the results could be inaccurate.

The option "'''Mirror signal before filtering'''"  triples artificially the length of the signal with a mirror symmetry on  each side, to avoid the strong edge effects that those filters can  generate. Those online filters are not very accurate, they just provide a  quick estimate for visualization only, the results are not saved  anywhere. To filter properly the continuous files, please use the  Process1 tab.

After  testing the high-pass, low-pass and notch filters, uncheck them. If not  you will probably forget about them, and they will stay on until you  restart Brainstorm.

{{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawViewer?action=AttachFile&do=get&target=onlineFilter.gif|onlineFilter.gif|class="attachment"}}

== Shortcut summary ==
=== Keyboard shortcuts ===
 * '''Left / right arrows''':
  * No other key: Change current time, sample by sample
  * With '''Control '''key: Jump to previous/next time segment (same as the "<<<" and ">>>" buttons)
  * With '''Shift '''key: Jump to next event of the selected group
  * On  MacOS, these shortcuts are different: please read the tooltips from the  buttons ">", ">>", and ">>>" in the time panel to get  the appropriate shortcuts.
 * '''Page-up / page-down''':
  * Same as left/right arrows, but faster (10 samples at a time)
  * If epochs are defined in the file: '''Control + page-up/page-down''' jumps to the next/previous epoch.
 * '''F3/Shift+F3''': Jump to the next/previous epoch or page
 * '''F4/Shift+F4''': Jump to the next/previous half-page
 * '''Plus / minus''': Adjust the vertical scale of the time series
 * '''Control + E''': Add / delete event occurrence
 * '''Control + T''': Open a 2D topography window at the current time
 * '''Shift + Letter''':  Changes the set of electrodes currently displayed in the figure (list  available by right-clicking on the figure > Display setup > ...)
 * '''Enter''': Display the selected channels in a separate figure (selected channels = lines on which you clicked, that are shown in red)
 * '''Escape''': Unselect all the selected channels
 * '''Delete''': Mark the selected channels as bad

=== Mouse shortcuts ===
 * '''Mouse click on a channel''': Select the channel
 * '''Mouse click''': Change current time
 * '''Mouse click + Shift''': For the selection of the current time (do not select any sensor, even when clicking on a line)

 * '''Mouse click + move''': Select time range
 * '''Mouse wheel''': Zoom around current time
 * '''Control + mouse wheel''': Zoom vertically
 * '''Shift + mouse wheel''': Adjust the vertical scale of the time series
 * '''Right-click''': Display popup menu
 * '''Right-click + move''': Move in a zoomed figure
 * '''Double click''': Restore initial zoom settings (but do not restore the vertical scale of the time series)

= From CTF =
== Time selection ==
Go back to  the previous view mode ("butterfly view") and in the Record tab, select  the menu "All channels" again. Keep this selection for the rest of the  tutorial.

 * Left-click  somewhere on the white part of the time series figure, hold  the mouse  button, and drag your mouse left or right: A transparent blue  rectangle  appears to represent the time selection.
 * Now  right-click on the figure to see the functions you can apply on this  time window. The selected time window and its duration are shown at the  bottom of the figure.
  . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutExploreRecodings?action=AttachFile&do=get&target=timeSelection.gif|timeSelection.gif|class="attachment"}}

 * '''Set current time''':  Just sets the time cursor when the right-click occurred. The shortcut  Shift+Click can be useful when trying to move in time on dense displays  in columns view.

 * '''Set selection manually''': Select a time window by giving the bounds in ms.

 * '''Average over time''': Average over the selected time window, saved as a new file in the database.

 * '''Export to database''': Extract the recordings and save them in a new file in database.
  * If some sensors are selected, only their values are extracted, all the others are set to zero.

 * '''Export to file''': Same, but in a user-defined file (not in the database)

 * '''Export to Matlab''': Same, but export as a Matlab variable in the current workspace.

== Bad channels ==
If you find  out that a sensor has unexpected values, that are not coherent with the  other surrounding sensors, you can choose to ignore it in the displays  and in the source estimation process. In the channel file, each channel  has a flag which indicates if it is good or bad. You may also import  recordings files that already have some bad channels defined.

 * Select  a few channels with one of the method described above: click on the  time series, click on the sensors dots, right-click and move to select a  group of sensors. Then right-click in one of the figures and check out  the '''Channels''' sub-menu:
  . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutExploreRecodings?action=AttachFile&do=get&target=channelMenu.gif|channelMenu.gif|class="attachment"}}
  * '''View selected''': Show the time series of the selected sensors

  * '''Mark selected as bad''': Remove sensors from the display and all the further computations

  * '''Mark non-selected as bad''': Keep only the selected channels

  * '''Reset selection''': Unselect all the selected sensors

  * '''Mark all channels as good''': Brings back all the channels to display

  * '''Edit good/bad channels''':  Opens an interface that looks like the channel editor, but with one  extra column to edit the status (good or bad) of each channel.

 * '''Mark channels as bad''': Right-click > ''Channels > Mark selected as bad'', or press ''Delete ''key.  The sensors should disappear in all figures, and the topography view  (2D sensors cap) is updated so that the interpolation on the 2D surface  now ignores the bad channels.
  . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutExploreRecodings?action=AttachFile&do=get&target=channelSetBad.gif|channelSetBad.gif|class="attachment"}}

 * '''Get the channels back''': two options
  * Right-click on figure > ''Channels > Mark all channels as good<<BR>> ''

  * Right-click on figure ''> Channels > Edit good/bad channels...''  : this menu open a window very similar to the Channel Editor window  introduced in previous tutorials, but without the annoying location and  orientation values, and with green and red dots. Click on the dots to  mark a channel as good or bad.
 ''' {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutExploreRecodings?action=AttachFile&do=get&target=channelEditGoodBad.gif|channelEditGoodBad.gif|class="attachment"}} '''
  * Note  that if you click on a row in this window, it will select the  corresponding channel in the time series and topography figures.
  * Close this window to save the changes.

 * '''Batching this from the database explorer''':
  * You will find a "Channels" menu for any node in the tree that contains recordings.
  * If  you do this on the level of a node, the operation will be applied  recursively to all the recordings contained in the node. This way, you  can quickly set that the channel 63 is always bad, or that electrode 43  is not working for subject #12, without having to visualize all the  recordings one after the other.
  * The'' View all bad channels'' command displays the list of all the bad channels in all the files in the ''Messages ''tab, in main Brainstorm window. {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutExploreRecodings?action=AttachFile&do=get&target=channelTreePopup.gif|channelTreePopup.gif|class="attachment"}}

 * '''Important notes''':
  * The good/bad channel flags are stored in the recordings files, not in the channel files. So if you marked some channels as ''bad ''in the ''ERF ''data file, there are still considered as ''good ''in the ''Std ''data file.

<<EmbedContent("http://neuroimage.usc.edu/bst/get_prevnext.php?prev=Tutorials/ChannelFile&next=Tutorials/MontageEditor")>>

<<EmbedContent(http://neuroimage.usc.edu/bst/get_feedback.php?Tutorials/ReviewRaw)>>