-
Notifications
You must be signed in to change notification settings - Fork 0
/
st_stastic.py
executable file
·125 lines (100 loc) · 3.41 KB
/
st_stastic.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import struct
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy import signal
from math import pi
from stockwell import st
import pywt
import struct
plt.rc('font',family='Times New Roman',size=10)
markers_freq = ['.','o','v','1','2','3','4','^','<','>','s','p','*','h','H','+','x','D','d','|','_',',']
fig = plt.figure(figsize=(5,3))
sgn = 1.0
interval = 5
dt = 0.0000001 * interval
fs = 10000000 / interval
result = []
pwd = os.getcwd()
result = []
#savepath = pwd + "//" + "wt_1.txt"
#fr = open(savepath, "w")
curvename = []
for dd in np.arange(60,141,10):
curvename.append(dd)
count = 0
record = []
while True:
filepath = pwd + "//" + "input_data" + "//" + "train1" + "//" + str(dd) + "//" + str(count)
if os.path.isfile(filepath) == False:
break
fb = open(filepath, "rb")
x = 0
data1 = []
data2 = []
while True:
data = fb.read(4)
if not data:
break
if x % interval == 0:
ch1, ch2 = struct.unpack('<HH', data)
ch1 = (float(ch1) - 8192) / 8192 * 2.5
ch2 = (float(ch2) - 8192) / 8192 * 2.5
ch1 = float(ch1)
ch2 = float(ch2)
data1.append(ch1)
data2.append(ch2)
x = x + 1
fb.close()
data1 = data1[int(250000 / interval):int(350000 / interval)]
data2 = data2[int(250000 / interval):int(350000 / interval)]
fa = [30000]#np.arange(300000, 400000 + 1, 10000)
cfs1 = []
cfs2 = []
for a in fa:
fmaxmin = int(a*(len(data1)*dt))
cfs1.append(st.st(data1, fmaxmin, fmaxmin)[0])
cfs2.append(st.st(data2, fmaxmin, fmaxmin)[0])
power1 = (abs(np.array(cfs1)))
power2 = (abs(np.array(cfs2)))
corr = []
for i in range(len(power1)):
mean1 = power1[i].mean()
power1[i] = power1[i] / mean1
mean2 = power2[i].mean()
power2[i] = power2[i] / mean2
temp = signal.correlate(power1[i],power2[i], mode='same',method='fft')
corr.append((np.where(temp == max(temp))[0][0]-len(temp) / 2 ) * dt * 1000)
print(corr)
record.append(corr[0])
## E=207 * pow(10,9) #203#207
## p=7.86 * 1000 #7.93#7.86
## o=0.27
## h=0.002
##
## freq = np.array(frequencies1)
## param = E * h * h * pi * pi / 3.0 / p / (1.0 - o * o)
## c = pow(param * pow(freq,2),0.25)
## time = sgn * (100.0 - dd) * 2.0 / 100.0 / c * 1000.0
##
## plt.plot(time,corr,'+')
## for i in range(len(freq)):
## fr.write(str(int(freq[i])) + " " + str(time[i]) + " " + str(corr[i]) + "\r\n")
count = count + 1
if count > 20:
break
result.append(record)
#fr.close()
#result = np.transpose(result)
#for index,item in enumerate(result):
# plt.plot(item,marker = markers_freq[index], label = str((axis_xf[index] + 1) * 20) + 'kHz')
for index,item in enumerate(result):
plt.plot(item,marker = markers_freq[index], label = str(curvename[index]) + 'cm')
plt.xlabel('order')
plt.ylabel('dt/ms')
ax = plt.gca()
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width, box.height])
plt.legend(loc='upper left',bbox_to_anchor=(1,1),markerscale=2)
plt.subplots_adjust(bottom = 0.2,left = 0.15,right=0.7)
plt.show()