-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataplot.py
More file actions
49 lines (43 loc) · 1.45 KB
/
dataplot.py
File metadata and controls
49 lines (43 loc) · 1.45 KB
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
import socket
import sys
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import spline
from scipy import interpolate
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = ('localhost', 10000)
#print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)
data = 'llll DATA: 0,4.4,-4.3,0,0,6.8,-7,0,0,1.6,-1.6,0,0,6.3,-6.4,0'
while True:
#data, address = sock.recvfrom(4096)
if ('DATA:' not in data):
continue
else:
#data = data.decode
start = data.find("DATA:")
substring = data[start+5:]
vect = [x.strip() for x in substring.split(',')]
print (vect)
vect = [float(numeric_string) for numeric_string in vect]
xnew = np.linspace(1, 16, 200)
tck = interpolate.splrep(range(1,17), vect,k=2,s=0)
yder = interpolate.splev(xnew, tck, der=0)
plt.figure()
plt.plot(xnew, yder, '-')
# xnew = np.linspace(1,16,200)
# power_smooth = spline(range(1,17),vect,xnew)
# plt.plot(xnew,power_smooth)
font = {'family': 'serif',
'color': 'black',
'weight': 'normal',
'size': 14,
}
plt.scatter(range(1,17), vect)
plt.grid(axis='y')
plt.xlabel('Time (sec)', fontdict=font)
plt.ylabel('Amplitude', fontdict=font)
plt.show()
break