Писсериальный и ФФТPython

Программы на Python
Ответить
Anonymous
 Писсериальный и ФФТ

Сообщение Anonymous »

Я хочу прочитать данные в реальном времени из моего Arduibo, построить их во временной области, а затем сделать FFT этих данных и построить это (частотная домен), но я понятия не имею, как это сделать. < /p>
не может передавать массив данных, которые я получаю от последовательного порта в FFT

Функция, вероятно, бессмысленна, так как я понятия не имею, как это сделать < /p>
def timedoamin(i, dataList, ser):
ser.write(b'g') # Transmit the char 'g' to receive the Arduino data point
arduinoData_string = ser.readline().decode('ascii') # Decode receive Arduino data as a formatted string
# print(i) # 'i' is a incrementing variable based upon frames = x argument

try:
arduinoData_float = float(arduinoData_string) # Convert to float
dataList.append(arduinoData_float) # Add to the list holding the fixed number of points to animate

except: # Pass if data point is bad
pass

dataList = dataList[-50:] # Fix the list size so that the animation plot 'window' is x number of points

ax.clear() # Clear last data frame
ax.plot(dataList) # Plot new data frame

ax.set_ylim([0, 2000]) # Set Y axis limit of plot
ax.set_title("Time Domain") # Set title of figure
ax.set_ylabel("Value") # Set title of y axis

def freqdomain(i,dataList1,ser):
ser.write(b'g')
arduinoData_string1 = ser.readline().decode('ascii') # Decode receive Arduino data as a formatted string
# print(i) # 'i' is a incrementing variable based upon frames = x argument

try:
arduinoData_float1 = float(arduinoData_string1) # Convert to float
dataList1.append(arduinoData_float1) # Add to the list holding the fixed number of points to animate
y=np.sin(2*np.pi*dataList1*t)
freqdom = fft.fft(y)

freqdom_real=np.fft.fftshift(np.real(freqdom))

except: # Pass if data point is bad
pass

dataList1 = dataList1[-50:] # Fix the list size so that the animation plot 'window' is x number of points

ax2.clear() # Clear last data frame
ax2.plot(dataList1) # Plot new data frame

ax2.set_ylim([0, 2000]) # Set Y axis limit of plot
ax2.set_title("Frequency domain") # Set title of figure
ax2.set_ylabel("Value") # Set title of y axis

dataList = [] # Create empty list variable for later use
dataList1 = []
freqdom = []
freqdom_real = []

fig1 = plt.figure(1) # Create Matplotlib plots fig is the 'higher level' plot window
fig2 = plt.figure(2)
ax = fig1.add_subplot(111) # Add subplot to main fig window
ax2 = fig2.add_subplot(111)
ser = serial.Serial("COM3", 9600) # Establish Serial object with COM port and BAUD rate to match Arduino Port/rate
time.sleep(2) # Time delay for Arduino Serial initialization
# Matplotlib Animation Fuction that takes takes care of real time plot.
# Note that 'fargs' parameter is where we pass in our dataList and Serial object.
ani1 = animation.FuncAnimation(fig1, timedoamin, frames=100, fargs=(dataList, ser), interval=100)
plt.show() # Keep Matplotlib plot persistent on screen until it is closed
ani2 = animation.FuncAnimation(fig2 ,freqdomain, frames=100, fargs=(freqdom_real, ser), interval=100)
plt.show()

sleep(10)

figure(3)
plt.plot(freqdom_real)
plt.show()

ser.close()


Подробнее здесь: https://stackoverflow.com/questions/793 ... al-and-fft
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»