Skip to content

Instantly share code, notes, and snippets.

@amicuscertus
Created June 4, 2018 12:58
Show Gist options
  • Save amicuscertus/d9545a6f995b4b94c5de63b127c13dde to your computer and use it in GitHub Desktop.
Save amicuscertus/d9545a6f995b4b94c5de63b127c13dde to your computer and use it in GitHub Desktop.
import socket
import numpy as np
import matplotlib.pyplot as plt
CHUNK = 1000
NMAX = 20
x = range (CHUNK)
y = np.zeros(CHUNK)
xpnt = 0
n = 0
fig1 = plt.figure(1, figsize=(8, 8))
fig1.subplots_adjust(hspace=0.7, wspace=0.1)
ax1 = fig1.add_subplot(1,1,1)
ax1.set_xlim(0, CHUNK)
ax1.set_ylim(-30000, 30000)
ax1.grid(color='gray', linestyle='dashed', linewidth=1)
lines1, = plt.plot(x, y, color="green")
plt.title('input signal')
UDP_IP = "127.0.0.1"
UDP_PORT = 7355
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(512)
ldata = len(data)
for i in range(ldata//2):
d0 = data[0+2*i]
d1 = data[1+2*i]
d2 = d1*256 + d0
if d1 > 127:
d2 -= 65536
y[xpnt] = d2
xpnt += 1
if xpnt >= CHUNK:
xpnt = 0
n += 1
if n == NMAX:
lines1.set_data(x, y)
plt.pause(0.01)
n = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment