-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_single_cross_wave.py
63 lines (53 loc) · 1.62 KB
/
draw_single_cross_wave.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
import struct
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy import signal
from math import pi,sin,cos
plt.rc('font',family='Times New Roman',size=10)
markers_freq = ['.','o','v','1','2','3','4','^','<','>','s','p','*','h','H','+','x','D','d','|','_']
dd = 102
sgn = 1.0
dt = 0.0000001
fs = 10000000.0
pwd = os.getcwd()
fb = open(pwd + "//" + "5" + "//" + str(dd) + "//" + "30", "rb")
x = 0
datax = []
datay1 = []
datay2 = []
while True:
data = fb.read(4)
if not data:
break
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)
x = x + 1
datax.append(x * dt)
datay1.append(ch1)
datay2.append(ch2)
datay1 = np.array(datay1[250000:350000])
datay2 = np.array(datay2[250000:350000])
datax = np.array(datax[250000:350000])
plt.subplot(2,1,1)
plt.ylabel('original signal/V')
plt.plot(datax,datay2,color='b',label = 'ch2')
plt.plot(datax,datay1,color='g',label = 'ch1')
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.subplot(2,1,2)
corr = signal.correlate(datay1,datay2, mode='same',method='fft')
corr_x = (np.array(range(len(corr))) - len(corr) / 2) * dt
plt.plot(corr_x,corr,color='r',label = 'cross correlate')
plt.xlabel('time/s')
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.8)
plt.show()