简体   繁体   English

Python 中的 FFT - 错误数据?

[英]FFT in Python - wrong data?

on my Raspberry PI 4, I have a xlsx file which I scan with: df = pd.read_excel('') This is a dataset of a pressure sensor with 146651 rows x 1 columns.在我的 Raspberry PI 4 上,我有一个 xlsx 文件,我用它扫描: df = pd.read_excel('')这是一个压力传感器的数据集,有 146651 行 x 1 列。 I want to perform a fft for this dataset, but if I plot the fft I get a curve exact the same to the time signal (moved on the x-axis???).我想对此数据集执行 fft,但如果我绘制 fft,我会得到一条与时间信号完全相同的曲线(在 x 轴上移动???)。 So what is the problem?那么问题是什么?

import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack
import pandas as pd


# Import csv file
df = pd.read_excel('/home/pi/Downloads/test_11.12.19_500_neuHz.xlsx', skiprows=1)


print(df)

sig_fft = fftpack.fft(df)
power = np.abs(sig_fft)
print (power)
sample_freq = fftpack.fftfreq(df.size, 0.02)
plt.figure(figsize=(6,5))
plt.plot(sample_freq, power)


plt.show()

graph图形

Your input data must be in a single row.您的输入数据必须在一行中。 Currently, your FFT is applied to all rows individually, which means the output for any given row is the mean of the single cell signal, therefore, your output is the same as your input.目前,您的 FFT 分别应用于所有行,这意味着任何给定行的输出都是单个细胞信号的平均值,因此,您的输出与输入相同。

#data is one column
df = pd.DataFrame([4,5,4])
df
fft = fftpack.fft(df)
fft
# output = input => wrong

#data as one row
df = pd.DataFrame({'0':[4],'1':[5],'2':[4]})
df
fft = fftpack.fft(df)
fft
# right

Now I am performing the fft in another way.现在我正在以另一种方式执行 fft。 But how can I scale the frequency and the magnitude axis.但是我怎样才能缩放频率和幅度轴。

import numpy as np
import matplotlib.pyplot as plt
import scipy
from scipy.fftpack import fft
import pandas as pd
import math
from tkinter import filedialog
from tkinter import *

#choose csv file
root = Tk()
root.filename = filedialog.askopenfilename ( initialdir = "/home/pi", title = "Datei auswählen", filetypes = (("Comma Seperated Values (CSV)", "*.csv"), ("Alle Dateien", "*.*")) )


# Import csv file
df = pd.read_csv(root.filename, delimiter = ';')
#convert Voltage to Bar
df_echt = df/0.01
#preparation for fft
df_neu = df.as_matrix()
time = df_neu[:,0]
voltage = df_neu[:,0]/df_neu[:,0].max()
df_tr = df_neu.T

#fft
amplitude = np.fft.rfft (voltage)
freq = np.fft.rfftfreq(len(time),np.diff(time)[0])

#plot time signal and fft
plt.plot( np.absolute(amplitude), lw = 0.5)
plt.figure (2)
plt.plot (df_echt)
plt.legend (df)
plt.show()

FFT graph FFT 图

So how do I scale the axises?那么我该如何缩放轴呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM