Contributions:PAC: Difference between revisions
Wengelhardt (talk | contribs) No edit summary |
Wengelhardt (talk | contribs) No edit summary |
||
| Line 13: | Line 13: | ||
#*Numpy: <code>pip install numpy</code> | #*Numpy: <code>pip install numpy</code> | ||
#*SciPy: <code>pip install scipy</code> (only the stats package is required) | #*SciPy: <code>pip install scipy</code> (only the stats package is required) | ||
==Include in BCI2000== | |||
Update your svn to at least r7931 to include the PAC Filter. Re-run CMake (<code>BCI2000/build/Configure.sh.cmd</code>), making sure to include enable BUILD_CONTRIB flag. Once this is Configured and Generated, open your Visual Studio project and build the PAC project (<code>Contrib/SignalProcessing/PAC</code>). A default batch file is built into the batch folder (<code>PAC_SignalGenerator.bat</code>), along with the python scripts in (<code>batch/pac_visualizations</code>). | |||
<code>connectBCI2000Batch.py</code> 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. | |||
<code>runPAC-BCI2000.py</code>, 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 <code>initBCI2000</code> function by using the [[Programming Reference:BCI2000Remote Class|BCI2000Remote Class]]. | |||
<syntaxhighlight lang="python"> | |||
#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() | |||
</syntaxhighlight> | |||
By creating various files with different <code>initBCI2000</code> functions, this functionality can easily replace batch files. | |||
==Signal Processing Pipeline== | ==Signal Processing Pipeline== | ||
Revision as of 18:11, 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
- Python 3.7+ needs to be installed. [You can download the lastest version here].
- A couple additional packages are used in this visualization. Run the following segments using
pipin 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)
- PyQtGraph 0.13.3+:
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.
- 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.
- Spatial filter: Common Average Reference the data to isolate unique neural activity.
- IIR Bandpass: Bandpass the desired frequency range for your phase or amplitude signal
- Hilbert filter: Compute the Hilbert filter on the bandpassed data.
- PAC filter: Combines the data from the amplitude and phase and groups the output data by phase bins.
- 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.
- Data acquisition: Connects to the shared memory address and continually updates the local data when there is new data to be acquired.
- 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.
- 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.