废话不多说,来看看实例吧!
# -*- coding: utf-8 -*- import serial filename='yjy.txt' t = serial.Serial('COM5',57600) b=t.read(3) vaul=[] i=0 y=0 p=0 while b[0]!=170 or b[1]!=170 or b[2]!=4: b=t.read(3) print(b) if b[0]==b[1]==170 and b[2]==4: a=b+t.read(5) print(a) if a[0] == 170 and a[1]==170 and a[2]==4 and a[3]==128 and a[4]==2: while 1: i=i+1 # print(i) a=t.read(8) # print(a) sum=((0x80+0x02+a[5]+a[6])^0xffffffff)&0xff if a[0]==a[1]==170 and a[2]==32: y=1 else: y=0 if a[0] == 170 and a[1]==170 and a[2]==4 and a[3]==128 and a[4]==2: p=1 else: p=0 if sum!=a[7] and y!=1 and p!=1: print("wrroy1") b=t.read(3) c=b[0] d=b[1] e=b[2] print(b) while c!=170 or d!=170 or e!=4: c=d d=e e=t.read() print("c:") print(c) print("d:") print(d) print("e:") print(e) if c==(b'\xaa'or 170) and d==(b'\xaa'or 170) and e==b'\x04': g=t.read(5) print(g) if c == b'\xaa' and d==b'\xaa' and e==b'\x04' and g[0]==128 and g[1]==2: a=t.read(8) print(a) break # if a[0]==a[1]==170 and a[2]==4: # print(type(a)) if a[0] == 170 and a[1]==170 and a[2]==4 and a[3]==128 and a[4]==2: high=a[5] low=a[6] # print(a) rawdata=(high<<8)|low if rawdata>32768: rawdata=rawdata-65536 # vaul.append(rawdata) sum=((0x80+0x02+high+low)^0xffffffff)&0xff if sum==a[7]: vaul.append(rawdata) if sum!=a[7]: print("wrroy2") b=t.read(3) c=b[0] d=b[1] e=b[2] # print(b) while c!=170 or d!=170 or e!=4: c=d d=e e=t.read() if c==b'\xaa' and d==b'\xaa' and e==b'\x04': g=t.read(5) print(g) if c == b'\xaa' and d==b'\xaa' and e==b'\x04' and g[0]==128 and g[1]==2: a=t.read(8) print(a) break if a[0]==a[1]==170 and a[2]==32: c=a+t.read(28) print(vaul) print(len(vaul)) for v in vaul: w=0 if v<=102: w+=v q=w/len(vaul) q=str(q) with open(filename,'a') as file_object: file_object.write(q) file_object.write("\n") if 102<v<=204: w+=v q=w/len(vaul) q=str(q) with open(filename,'a') as file_object: file_object.write(q) file_object.write("\n") if 204<v<=306: w+=v q=w/len(vaul) q=str(q) with open(filename,'a') as file_object: file_object.write(q) file_object.write("\n") if 306<v<=408: w+=v q=w/len(vaul) q=str(q) with open(filename,'a') as file_object: file_object.write(q) file_object.write("\n") if 408<v<=510: w+=v q=w/len(vaul) q=str(q) with open(filename,'a') as file_object: file_object.write(q) file_object.write("\n") # print(c) vaul=[] # if i==250: # break # with open(filename,'a') as file_object: # file_object.write(q) # file_object.write("\n")
补充知识:Python处理脑电数据:PCA数据降维
pca.py
#!-coding:UTF-8- from numpy import * import numpy as np def loadDataSet(fileName, delim='\t'): fr = open(fileName) stringArr = [line.strip().split(delim) for line in fr.readlines()] datArr = [map(float,line) for line in stringArr] return mat(datArr) def percentage2n(eigVals,percentage): sortArray=np.sort(eigVals) #升序 sortArray=sortArray[-1::-1] #逆转,即降序 arraySum=sum(sortArray) tmpSum=0 num=0 for i in sortArray: tmpSum+=i num+=1 if tmpSum>=arraySum*percentage: return num def pca(dataMat, topNfeat=9999999): meanVals = mean(dataMat, axis=0) meanRemoved = dataMat - meanVals #remove mean covMat = cov(meanRemoved, rowvar=0) eigVals,eigVects = linalg.eig(mat(covMat)) eigValInd = argsort(eigVals) #sort, sort goes smallest to largest eigValInd = eigValInd[:-(topNfeat+1):-1] #cut off unwanted dimensions redEigVects = eigVects[:,eigValInd] #reorganize eig vects largest to smallest lowData_N = meanRemoved * redEigVects#transform data into new dimensions reconMat_N = (lowData_N * redEigVects.T) + meanVals return lowData_N,reconMat_N def pcaPerc(dataMat, percentage=1): meanVals = mean(dataMat, axis=0) meanRemoved = dataMat - meanVals #remove mean covMat = cov(meanRemoved, rowvar=0) eigVals,eigVects = linalg.eig(mat(covMat)) eigValInd = argsort(eigVals) #sort, sort goes smallest to largest n=percentage2n(eigVals,percentage) n_eigValIndice=eigValInd[-1:-(n+1):-1] n_eigVect=eigVects[:,n_eigValIndice] lowData_P=meanRemoved*n_eigVect reconMat_P = (lowData_P * n_eigVect.T) + meanVals return lowData_P,reconMat_P
readData.py
import matplotlib.pyplot as plt from pylab import * import numpy as np import scipy.io as sio def loadData(filename,mName): load_fn = filename load_data = sio.loadmat(load_fn) load_matrix = load_data[mName] #load_matrix_row = load_matrix[0] #figure(mName) #plot(load_matrix,'r-') #show() #print type(load_data) #print type(load_matrix) #print load_matrix_row return load_matrix
main.py
#!-coding:UTF-8 import matplotlib.pyplot as plt from pylab import * import numpy as np import scipy.io as sio import pca from numpy import mat,matrix import scipy as sp import readData import pca if __name__ == '__main__': A1=readData.loadData('6electrodes.mat','A1') lowData_N, reconMat_N= pca.pca(A1,30) lowData_P, reconMat_P = pca.pcaPerc(A1,0.95) #print lowDMat #print reconMat print shape(lowData_N) print shape(reconMat_N) print shape(lowData_P) print shape(reconMat_P)
以上这篇使用python接受tgam的脑波数据实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年11月24日
2024年11月24日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]