先安装ant的eego驱动,然后使用指定的python版本进行读取EEG数据,
根据不同通道数的放大器来选择模板,并进行采集
示例代码如下:
#!/usr/bin/python3
# coding:utf8
"""
@Create date: 2024/3/29
@Author: Tesda
"""
import time
import eego_sdk
import numpy as np
from pyedflib import highlevel
save_time_interval = 10 # 采集时长
column_list = []
def sampling_data():
global running, column_list
start_time = time.time()
eeg_stream = amp.OpenEegStream(500, 1.0, 1.5) # 采样率
channel_count = eeg_stream.getChannelList()
ref_channel_list = [True if _.getType().name == "ref" else False for _ in eeg_stream.getChannelList()]
while time.time() - start_time < save_time_interval:
try:
eeg_data = eeg_stream.getData()
print(eeg_data.getSampleCount())
for s in range(eeg_data.getSampleCount()):
row_list = []
d_count = eeg_data.getChannelCount()
# print(d_count)
for c, b in enumerate(ref_channel_list):
if not b:
continue
d = eeg_data.getSample(c, s)
row_list.append(d)
row_list.append(eeg_data.getSample(d_count - 2, s))
row_list.append(eeg_data.getSample(d_count - 1, s))
column_list.append(row_list)
except Exception as e:
print(e)
return ref_channel_list.count(True) + 2
if __name__ == '__main__':
running = True
factory = eego_sdk.factory()
print(factory.getAmplifiers())
amp = factory.getAmplifiers()[0]
save_path = "./test{}.edf".format(time.strftime("%Y%m%d", time.localtime()))
column_list = []
c_count = sampling_data()
ch_names = [str(_) for _ in range(c_count)] # 通道模板,长度为:通道数+2
signal_headers = highlevel.make_signal_headers(ch_names, dimension='uV', sample_frequency=500,
physical_min=-250000 * 4, physical_max=250000 * 4)
header = highlevel.make_header(patientname="", gender="")
raw_np = np.array(column_list).T
print(raw_np.shape, raw_np)
print(len(signal_headers))
print(len(raw_np))
highlevel.write_edf(save_path, raw_np, signal_headers, header)
print("保存edf文件结束:{}".format(save_path))