Is this the right code for real-time data acquisition using the Brainflow library?
Is this the right code for real-time data acquisition using the Brainflow library?
import argparse
import time
import numpy as np
from brainflow.board_shim import BoardIds, BoardShim, BrainFlowInputParams
from brainflow.data_filter import DataFilter, FilterTypes, NoiseTypes
def main():
BoardShim.enable_dev_board_logger()
parser = argparse.ArgumentParser()
# use docs to check which parameters are required for specific board, e.g. for Cyton - set serial port
parser.add_argument('--timeout', type=int, help='timeout for device discovery or connection', required=False,
default=0)
parser.add_argument('--ip-port', type=int, help='ip port', required=False, default=0)
parser.add_argument('--ip-protocol', type=int, help='ip protocol, check IpProtocolType enum', required=False,
default=0)
parser.add_argument('--ip-address', type=str, help='ip address', required=False, default='')
parser.add_argument('--serial-port', type=str, help='serial port', required=False, default='')
parser.add_argument('--mac-address', type=str, help='mac address', required=False, default='')
parser.add_argument('--other-info', type=str, help='other info', required=False, default='')
parser.add_argument('--serial-number', type=str, help='serial number', required=False, default='')
parser.add_argument('--board-id', type=int, help='board id, check docs to get a list of supported boards',
required=True)
parser.add_argument('--file', type=str, help='file', required=False, default='')
parser.add_argument('--master-board', type=int, help='master board id for streaming and playback boards',
required=False, default=BoardIds.NO_BOARD)
args = parser.parse_args()
params = BrainFlowInputParams()
params.ip_port = args.ip_port
params.serial_port = "COM5"
params.mac_address = args.mac_address
params.other_info = args.other_info
params.serial_number = args.serial_number
params.ip_address = args.ip_address
params.ip_protocol = args.ip_protocol
params.timeout = args.timeout
params.file = args.file
params.master_board = args.master_board
board_id = BoardIds.SYNTHETIC_BOARD.value
board = BoardShim(0, params)
board_data_sum = np.arange(16)
board_data_sum = board_data_sum[np.newaxis, :]
i = 0
while 185 >= i:
board.prepare_session()
board.start_stream()
time.sleep(2)
# data = board.get_current_board_data (256) # get latest 256 packages or less, doesnt remove them from internal buffer
data = board.get_board_data() # get all data and remove it from internal buffer
board.stop_stream()
board.release_session()
eeg_channels = BoardShim.get_eeg_channels(board_id)
print(np.transpose(data)[0:125, eeg_channels[0]:eeg_channels[-1] + 1].shape)
print(eeg_channels)
for _, channel in enumerate(eeg_channels):
DataFilter.perform_bandpass(data[channel], BoardShim.get_sampling_rate(board_id), 7.5, 35.0, 4,
FilterTypes.BESSEL.value, 0)
DataFilter.remove_environmental_noise(data[channel], BoardShim.get_sampling_rate(board_id),
NoiseTypes.FIFTY.value)
board_data_sum = np.append(board_data_sum, np.transpose(data[eeg_channels, :]) ,axis=0)
print(i)
i += 1
np.savetxt('./np_savecsv.csv', board_data_sum)
if __name__ == "__main__":
main()
I want to use the Brainflow library to display in real time the EEG signals that can be acquired from openBCI's Cyton. However, when I plot the acquired data in python, the data is not shaped like an EEG signal and I cannot get the data properly.
I have thrown this into the Brainflow slack and am having trouble getting an answer.
Comments
Is there not a real-time plot example, directly at the docs site??
https://brainflow.readthedocs.io/en/stable/Examples.html#python-real-time-plot