Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update plot
#3
I am sorry, code here:

import serial
import struct
import matplotlib.pyplot as plt
import scipy.fft
import numpy as np
from scipy.fftpack import fft
 
ser = serial.Serial(port='COM4', baudrate=2000000)
SAMPLES=20000
s = struct.Struct('<' + str(SAMPLES) + 'f')
T = 1.0 / 20000.0
unpacked_data1 = []

def serial_read():
    ser.reset_input_buffer()
    ser.write("r".encode())
    serial_data = ser.read(SAMPLES*4)
    unpacked_data = s.unpack(serial_data)
    unpacked_data1[1:20000] = unpacked_data[1:20000]
    ser.close

serial_read()

plt.plot(unpacked_data1[1000:3000])
plt.show()

x = np.linspace(0.0, SAMPLES*T, SAMPLES)
y = unpacked_data1
yf = scipy.fftpack.fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), SAMPLES//2)
fig, ax = plt.subplots()
ax.plot(xf, 2.0/SAMPLES * np.abs(yf[:SAMPLES//2]))
plt.show()  
Reply


Messages In This Thread
Update plot - by frohr - Jan-27-2022, 06:40 PM
RE: Update plot - by deanhystad - Jan-27-2022, 07:06 PM
RE: Update plot - by frohr - Jan-27-2022, 07:20 PM
RE: Update plot - by deanhystad - Jan-27-2022, 07:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,740 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  How to plot intraday data of several days in one plot mistermister 3 2,988 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,968 Jun-12-2019, 03:31 PM
Last Post: SriMekala

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020