Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
GanKunlu authored Dec 25, 2016
1 parent e6c13f7 commit 7d64fd5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
36 changes: 36 additions & 0 deletions feat_extract_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from tools.reader import *
from tools.featureExtract import FeatureExtractor
import os
import matplotlib.pyplot as plt
# load FilesReader and FeatureExtractor class
path = os.getcwd()+"\data"
print(path)
reader = FilesReader(8,path)
extractor = FeatureExtractor(reader.fileNumber, 60, 10)
# init Mat:
feats = np.array([])
labels = np.array([])

for classIndex, fileName in enumerate(reader.files):
# load file:
dataMat = reader.loadFile(fileName)
# gesture segmentation:
segMat = extractor.segmentation(dataMat, classIndex)
# init:
featMat = np.array([])
for segIndex, seg in enumerate(segMat):
# extract RMS, ZC, ARC features:
RMSfeat = extractor.RMSfeat(seg)
ZCfeat = extractor.ZCfeat(seg)
ARCfeat = extractor.ARCfeat(seg)
featVector = np.hstack((RMSfeat,ZCfeat,ARCfeat))
# feats splice:
featMat = extractor.dynamicSplice(featMat, featVector, segIndex)
# generate labels:
tempLabels = extractor.creatLabels(classIndex, len(featMat))
# feat array and label array splice:
feats = extractor.dynamicSplice(feats, featMat, classIndex)
labels = extractor.dynamicSplice(labels, tempLabels, classIndex, axis = 1)

print(feats[0])
print(labels[0])
45 changes: 45 additions & 0 deletions feat_plot_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: gbk -*-
from tools.reader import *
from tools.featureExtract import FeatureExtractor
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from tools.MyPlot import DataPlotter
import os
slice = [600,1400]
ChanList = ['Raw-c0','Raw-c1','Raw-c2','Raw-c3','Raw-c4','Raw-c5','Raw-c6','Raw-c7']
featList = ['RMS','ZC','ARC0','ARC1','ARC2','ARC3']
path = os.getcwd()+'/data'
channels = 8

reader = FilesReader(channels, path)
extractor = FeatureExtractor(reader.fileNumber, slice[1]-slice[0], 10, featRavel = False)
emg = reader.loadFile('1.txt')
print(reader.filesLength)
sliceData = emg[slice[0]:slice[1],:]
rawFrame = pd.DataFrame(sliceData, columns = ChanList)

RMSfeat = extractor.RMSfeat(sliceData)
ZCfeat = extractor.ZCfeat(sliceData)
ARCfeat = extractor.ARCfeat(sliceData, False)
zipfeat = [RMSfeat,ZCfeat]
zipfeat.extend(ARCfeat)
columns = extractor.creatFeatName(featList, 8)
featplot = DataPlotter(np.hstack(zipfeat), columns, 431)


selectFeat = ['RMS-c0', 'RMS-c5', 'RMS-c7',\
'ZC-c0', 'ZC-c5', 'ZC-c7',\
'ARC1-c0','ARC1-c5','ARC1-c7']
selectChan = ['Raw-c0','Raw-c5','Raw-c7']


for i in range(len(selectChan)):
featplot.newSubplot(431+i, rawFrame[selectChan[i]],xylabel=[u'²ÉÑùµã',selectChan[i]])
#plt.title('ÌâÄ¿',fontproperties='SimHei')

for j in range(len(selectFeat)):
featplot.subplot([4,3,4+j], [selectFeat[j]], xylabel=[u'²ÉÑùµã',selectFeat[j]])

plt.show()

0 comments on commit 7d64fd5

Please sign in to comment.