【发布时间】:2017-08-17 05:26:24
【问题描述】:
我正在尝试对两个相同采样的数据块运行 Python STFT(也称为短时傅立叶变换)。
但是,由于我对数据的一项应用,我需要将其中的一些数据收集到.txt 文件中。
我很困惑为什么 STFT 会为来自 .csv 的数据工作,而不是为来自 .txt 文件的数据生成正确的输出。两者都是Panda.core.series.Series 数据类型,并且都具有相似大小的值。测试条件也相同。
我要排除故障的代码是标记为Code that isn't returning the expected output 的代码。任何见解或观察将不胜感激!
请注意,我有 result[::4] 行,因为我必须从每 4 个样本中删除 3 个样本,以匹配两种数据采集方法之间的采样率。
未返回预期输出的代码:
import json
result = []
with open("C:\\Users\\Desktop\\data.txt") as file:
for line in file:
result.append(json.loads(line)[-1])
result = result[::4]
result = pd.Series(result)
f, t, Zxx = scipy.signal.stft(result, fs=500, nperseg = 1000)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.pcolormesh(t, f, np.abs(Zxx), vmin=0, vmax=0.001)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()
正常运行的代码:
test = pd.read_csv("C:\\Users\\Documents\\data.csv")
test.head()
test.columns = ['TS', 'Col1', 'Col2', 'Col3', 'Col4']
f, t, Zxx = scipy.signal.stft(test['Col1'], fs=500, nperseg = 1000)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.pcolormesh(t, f, np.abs(Zxx), vmin=0, vmax=0.001)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()
【问题讨论】:
-
抽取前需要使用低通滤波器。 Decimation:“单独下采样会导致高频信号分量被数据的后续用户误解,这是一种称为混叠的失真形式。”
-
有道理。我应该如何确定为其创建低通滤波器的频率?
-
那么我将如何获取低通输出并将其重新插入我的 STFT?