Jump to content

Contributions:PAC: Difference between revisions

From BCI2000 Wiki
No edit summary
No edit summary
Line 61: Line 61:


==Parameters==
==Parameters==
The PAC Module contains many parameters from the various filters in the Signal Processing Pipeline. Refer to those pages' documentation for specific on the individual parameters. There are additionally a couple of parameters specific to the PAC filter itself.


{|
|'''AngleDecimation'''
|Number of degrees of resolution. This inversely specifies the number of bins that the phases are grouped into. Must be a denominator of 360 degrees, otherwise it will be rounded to one. For example, a value of 10 will create 36 bins.
|-
|style="border-bottom: solid 1px grey; border-top: solid 1px grey;"|'''SlidingWindow'''
|Amount of time to hold past data for. Set to 0 to hold for the whole run. Regardless of this parameter, when a New Trial occurs the data resets.
|-
|'''IncludeDeviation'''
|Enable to double the size of the output and include the standard deviation of the average amplitude for each phase bin. This will be the 2nd half of the output. If this is enabled, currently the Python script will have to be changed.
|}
Since we have a parallel filter chain with equivalent subchains, we will have two subchains with the same parameter names. These will be included under the tabs ''Filtering: Amplitude'' and ''Filtering: Phase''. In these two subchains, a few requirements must be met.
*Delay must be the same
*Filtering: Amplitude must have the Hilbert OutputSignal of Hilbert envelope.
*Filtering: Phase must have the OutputSignal of Hilbert phase.
*Downsample must be disabled (since the two subchains will likely have varying frequencies, downsampling will mismatch the number of samples)
==States==
==States==
{|
|'''PAC_TrialNumber'''
|Number that increments every time button New Trial is pressed. Changing this state resets all data.
|-
|'''PAC_TrialType'''
|Keeps track of the trial type.
|}





Revision as of 18:36, 14 March 2024

Synopsis

PAC, or phase-amplitude coupling, shows the entrainment of a certain frequency band to the power of another frequency band. In other words, the phase of one type of neural activity correlates with the amplitude of another. The dominant phase and the location of this entrainment can change for varying tasks. With this implementation, you can view the entrainment happening as the task is being completed, which can help you focus on the responsive electrodes for a certain task.

Versioning

Authors

Will Engelhardt (engelhardt@neurotechcenter.org)

Installation

  1. Python 3.7+ needs to be installed. [You can download the lastest version here].
  2. A couple additional packages are used in this visualization. Run the following segments using pip in the command line.
    • PyQtGraph 0.13.3+: pip install pyqtgraph
    • PyQt5: pip install PyQt5
    • Numpy: pip install numpy
    • SciPy: pip install scipy (only the stats package is required)

Include in BCI2000

Update your svn to at least r7931 to include the PAC Filter. Re-run CMake (BCI2000/build/Configure.sh.cmd), making sure to include enable BUILD_CONTRIB flag. Once this is Configured and Generated, open your Visual Studio project and build the PAC project (Contrib/SignalProcessing/PAC). A default batch file is built into the batch folder (PAC_SignalGenerator.bat), along with the python scripts in (batch/pac_visualizations).

connectBCI2000Batch.py is configured to let you start your own batch file (with PAC as the SignalProcessing module), and then execute this script to connect to the BCI2000 started with the batch file.

runPAC-BCI2000.py, by contrast, is configured to start its own BCI2000 instance along with the visualization. This file can be customized to fit your needs. You can change anything in the initBCI2000 function by using the BCI2000Remote Class.

    #configure to customize your BCI2000 instance
    def initBCI2000(self, bci):
        bci.WindowVisible = True
        bci.WindowTitle = 'BCI2000: Phase-Amplitude coupling'
        bci.SubjectID = 'test'
        bci.Connect()
        bci.Execute('cd ${BCI2000LAUNCHDIR}')
        #FilePlayback is helpful if you already have the data file
        #bci.StartupModules(('FilePlayback --PlaybackFileName=..\data\BJH041\ECOGS001R02.dat', 'PAC', 'DummyApplication'))
        bci.StartupModules(('SignalGenerator', 'PAC', 'DummyApplication'))
        bci.Execute('Wait for Connected')
        bci.LoadParametersRemote('../parms/PAC/pac_pipeline.prm')
        bci.Execute('SET PARAMETER SamplingRate 5000Hz')
        bci.Execute('SET PARAMETER SampleBlockSize 100')
        bci.Execute('SET PARAMETER AngleDecimation 6')
        #bci.Execute('SET PARAMETER TransmitChList 2-5') #can choose whatever channels you want
        bci.SetConfig()
        bci.Start()

By creating various files with different initBCI2000 functions, this functionality can easily replace batch files.


Signal Processing Pipeline

Below is the diagram showing how this is made possible.

BCI2000 Signal Processing Pipeline

Within the BCI2000 architecture, the figure depicts the Signal Processing pipeline with the PAC Filter.

  1. Decimation filter: Used to reduce the number of samples from the source module. This should be used if the sampling rate is too high to process a sample block size within the necessary time.
  2. Spatial filter: Common Average Reference the data to isolate unique neural activity.
  3. IIR Bandpass: Bandpass the desired frequency range for your phase or amplitude signal
  4. Hilbert filter: Compute the Hilbert filter on the bandpassed data.
  5. PAC filter: Combines the data from the amplitude and phase and groups the output data by phase bins.
  6. SignalSharingDemo: Enables an outside connection to the BCI2000 data by using shared memory. This is how we can see the data in Python.

Python

3 threads are running within the Python scripts.

  1. Data acquisition: Connects to the shared memory address and continually updates the local data when there is new data to be acquired.
  2. BCI2000 Connection: Using BCI2000Remote, we have a two-way connection between Python and BCI2000. This is used for updating and acquiring states and parameters. This can also be used to start a BCI2000 instance, instead of the common practice of using a batch file.
  3. Visualization: The main thread of the Python script creates an interactive visualization with PyQtGraph. When the visualization is interacted with, BCI2000 states are updated accordingly.

Parameters

The PAC Module contains many parameters from the various filters in the Signal Processing Pipeline. Refer to those pages' documentation for specific on the individual parameters. There are additionally a couple of parameters specific to the PAC filter itself.

AngleDecimation Number of degrees of resolution. This inversely specifies the number of bins that the phases are grouped into. Must be a denominator of 360 degrees, otherwise it will be rounded to one. For example, a value of 10 will create 36 bins.
SlidingWindow Amount of time to hold past data for. Set to 0 to hold for the whole run. Regardless of this parameter, when a New Trial occurs the data resets.
IncludeDeviation Enable to double the size of the output and include the standard deviation of the average amplitude for each phase bin. This will be the 2nd half of the output. If this is enabled, currently the Python script will have to be changed.

Since we have a parallel filter chain with equivalent subchains, we will have two subchains with the same parameter names. These will be included under the tabs Filtering: Amplitude and Filtering: Phase. In these two subchains, a few requirements must be met.

  • Delay must be the same
  • Filtering: Amplitude must have the Hilbert OutputSignal of Hilbert envelope.
  • Filtering: Phase must have the OutputSignal of Hilbert phase.
  • Downsample must be disabled (since the two subchains will likely have varying frequencies, downsampling will mismatch the number of samples)

States

PAC_TrialNumber Number that increments every time button New Trial is pressed. Changing this state resets all data.
PAC_TrialType Keeps track of the trial type.


See also

Contributions:SignalProcessing