-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (68 loc) · 2.12 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import scipy.io as sio
import numpy as np
import pylab as pl
from ufun import *
from huffman import*
matfn = u'ECG.mat'
data1 = sio.loadmat(matfn)
RawECGData = data1['AA']
EcgData = RawECGData.reshape(1, RawECGData.size)[0]
matfn = u'HS.mat'
data2 = sio.loadmat(matfn)
RawHsData = data2['data']
HsData = RawHsData.reshape(1, RawHsData.size)[0]
HS = hs_spcm(HsData, 16)
fs = 4000
prdc = 10
R = 8
StartPer = 1
qbit = 10
tind = Rwave_detection(EcgData, fs)
tlen = np.diff(tind[StartPer:StartPer + R])
meanh = np.mean(HS[tind[StartPer]:tind[StartPer + R]])
HS[tind[StartPer]:tind[StartPer + R]] = HS[tind[StartPer]:tind[StartPer + R]] - meanh
indmax = np.argmax(tlen)
HStrain = HS[tind[StartPer + indmax - 1]:tind[StartPer + indmax]]
K = getKvalue(HStrain, prdc)
HSForTest = HS[tind[StartPer]:tind[StartPer + R]]
HSReTest = np.zeros(HS.size)
xlen = 0
ylen = 0
WS = np.zeros((R,K))
WL = np.zeros((R,5),dtype = int)
inforL = []
AllIndex = []
for ind in range(0,R):
HStemp = HS[tind[StartPer + ind]:tind[StartPer + ind +1]]
WaveC,WaveL = SingalToWaveArray(HStemp)
for i in range(len(WaveL)):
WL[ind,i] = WaveL[i]
inforL.append(WaveC.size)
WS[ind,:], tempI = chooseKmaxValue(WaveC, K)
for i in range(tempI.size):
AllIndex.append(tempI[i].tolist())
WE = np.reshape(WS,(R*K))
QWC = hs_spcm(WE,qbit)
code1, str1 = compress(QWC)
DWE = decompress(code1, str1)
RWS = np.reshape(DWE,(R,K))
WI = np.array(AllIndex, dtype = int)
QWI,first_s = runlength_encode(WI)
code2, str2 = compress(QWI)
DWI = decompress(code2, str2 )
RWI = runlength_decode(DWI.astype(np.int),first_s)
CR = HSForTest.size*16/(len(str2)+len(str1))
start = 0
for ind in range(0,R):
HStemp = HSReTest[tind[StartPer + ind]:tind[StartPer + ind +1]]
RWaveC = np.zeros(inforL[ind])
RWaveC[RWI[start:start+inforL[ind]]==1] = RWS[ind,:]
start += inforL[ind]
HSReTest[tind[StartPer + ind]:tind[StartPer + ind + 1]] = WaveArrayToSignal(RWaveC,WL[ind,:])[0:HStemp.size]
HSdetrain = HSReTest[tind[StartPer + indmax - 1]:tind[StartPer + indmax]]
pl.plot(HStrain)
pl.plot(HSdetrain,'r')
prd1 =hs_prd(HStrain, HSdetrain)
pl.show()
print(prd1)
print(CR)