了解快速傅立叶变换方法的输出 [英] Understanding the output from the fast Fourier transform method

查看:134
本文介绍了了解快速傅立叶变换方法的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清python FFT库产生的输出.

I'm trying to make sense of the output produced by the python FFT library.

我有一个sqlite数据库,其中记录了多个ADC值系列.每个系列包含1024个采样,采样频率为1毫秒.

I have a sqlite database where I have logged several series of ADC values. Each series consist of 1024 samples taken with a frequency of 1 ms.

导入数据系列后,我对其进行规范化并通过fft方法运行int.与FFT输出相比,我包括了一些原始信号图.

After importing a dataseries, I normalize it and run int through the fft method. I've included a few plots of the original signal compared to the FFT output.

import sqlite3
import struct
import numpy as np
from matplotlib import pyplot as plt
import time
import math

conn = sqlite3.connect(r"C:\my_test_data.sqlite")
c = conn.cursor()

c.execute('SELECT ID, time, data_blob FROM log_tbl')


for row in c:
    data_raw = bytes(row[2])
    data_raw_floats = struct.unpack('f'*1024, data_raw)
    data_np = np.asarray(data_raw_floats)

    data_normalized = (data_np - data_np.mean()) / (data_np.max() - data_np.min())

    fft = np.fft.fft(data_normalized)
    N = data_normalized .size

    plt.figure(1)
    plt.subplot(211)
    plt.plot(data_normalized )

    plt.subplot(212)
    plt.plot(np.abs(fft)[:N // 2] * 1 / N)
    plt.show()

    plt.clf()

信号明显包含一些频率,我希望它们在FFT输出中可见.

The signal clearly contains some frequencies, and I was expecting them to be visible from the FFT output.

我在做什么错了?

推荐答案

使用np.fft.fft时,您需要确保数据均匀分布,否则输出将不准确.如果它们的间距不均匀,则可以使用LS周期图,例如: http://docs.astropy.org/en/stable/stats/lombscargle.html . 或查找不均匀的fft.

You need to make sure that your data is evenly spaced when using np.fft.fft, otherwise the output will not be accurate. If they are not evenly spaced, you can use LS periodograms for example: http://docs.astropy.org/en/stable/stats/lombscargle.html. Or look up non-uniform fft.

关于情节: 我认为您做的事情显然不对.您的信号包含周期为100量级的信号,因此您可以期望在1/period=0.01附近出现强频率信号.这就是您的图表上可见的内容.时域信号不是正弦波,因此在频域中的峰值将变得模糊,如图所示.

About the plots: I don't think that you are doing something obviously wrong. Your signal consists a signal with period in the order of magnitude 100, so you can expect a strong frequency signal around 1/period=0.01. This is what is visible on your graphs. The time-domain signals are not that sinusoidal, so your peak in the frequency domain will be blurry, as seen on your graphs.

这篇关于了解快速傅立叶变换方法的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆