Я хочу прочитать данные в реальном времени из моего 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
Писсериальный и ФФТ ⇐ Python
Программы на Python
1737833933
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()
Подробнее здесь: [url]https://stackoverflow.com/questions/79381261/pyserial-and-fft[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия