第一步:运用眨眼的数据将脑波数据进行前处理

眨眼会对脑波和瞳孔数据造成干扰,所以要对原数据进行眨眼去除。

#brain_frequency_range.py

import pandas as pd
import numpy as np
import mne
from mne.io import concatenate_raws, read_raw_edf
import matplotlib.pyplot as plt
import datetime
from process_eeg import iir,processing
import os
from process_eye.eye_feature_extraction import eye_main
def mkdir(path_3):
    folder = os.path.exists(path_3)
    if not folder:  # 判断是否存在文件夹如果不存在则创建为文件夹
        os.makedirs(path_3)  # makedirs 创建文件时如果路径不存在会创建这个路径
        print("---  new folder...  ---")
        print("---  OK  ---")
    else:
        print("---  There is this folder!  ---")
def read_file(eeg_path):
    raw = mne.io.read_raw_edf(eeg_path, preload=True)
    raw.pick_types(meg=False, eeg=True, eog=False)
    eeg, times = raw[0:18]
    fs = raw.info['sfreq']
    ch_names = raw.info['ch_names'][0:18]
    return eeg, times, fs, ch_names

def csv_read():
    raw = read_raw_edf(eeg_path, preload=False)
    print(raw)
    data = pd.DataFrame(pd.read_csv(eeg_path, encoding="utf-8", engine='python'))
    Fp2= np.array(data['EEG Fp2-Cz'])  # data length : 60fps * time (video time)
    # print(len(Fp2))
def start_time(eeg_mid_path):
    eeg_time_filename = eeg_mid_path + '/eeg/read me.txt'
    for line in open(eeg_time_filename, encoding='utf-8').readlines():
        url = line.rstrip()  # 去掉末尾隐藏的\n,避免出现空行。
        data = url.split('\t')[0]
        startime = data.split('time:')[-1]
        start_eeg = datetime.datetime.strptime(startime, "%Y-%m-%d %H:%M:%S.%f")
        # print('startime:',startime)
        # print('start:',start_eeg)
        return start_eeg
def video_time(path,name_):
    mid_path = name_ + '/'
    filename = path + mid_path + name_ + '_video.txt'
    START = [];END = []; NAME = []
    for line in open(filename, encoding='utf-8').readlines():
        # url = line
        url = line.rstrip()  # 去掉末尾隐藏的\n,避免出现空行。
        startime = url.split('\t')[0]
        # print(startime)
        start = datetime.datetime.strptime(startime, "%Y-%m-%d %H:%M:%S.%f")
        video_name = url.split('\t')[1]
        name = video_name.split('.')[0]
        endtime = (start + datetime.timedelta(minutes=6)).strftime("%Y-%m-%d %H:%M:%S.%f")
        end = datetime.datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S.%f")
        START.append(start)
        END.append(end)
        NAME.append(name)
    return START, END, NAME

def resampling(eeg_Name,index, eeg_components):

    for b, eeg_com in enumerate(eeg_components):
        print(b)
        EEG_component = [];INDEX 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值