FFT实部/虚部/绝对部分解释 [英] FFT real/imaginary/abs parts interpretation

查看:2434
本文介绍了FFT实部/虚部/绝对部分解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习离散傅立叶变换,并且我正在与numpy一起玩以更好地理解它.

I'm currently learning about discret Fourier transform and I'm playing with numpy to understand it better.

我试图绘制"sin x sin x sin"信号,并获得了具有4个非零点的干净FFT.我天真地告诉自己:好吧,如果我绘制具有这些振幅和频率的正弦+罪恶+罪恶+正弦"信号,我应该获得相同的正弦x罪恶x正弦"信号,对吗?

I tried to plot a "sin x sin x sin" signal and obtained a clean FFT with 4 non-zero points. I naively told myself : "well, if I plot a "sin + sin + sin + sin" signal with these amplitudes and frequencies, I should obtain the same "sin x sin x sin" signal, right?

嗯...不完全是

(第一个是"x"信号,第二个是"+"信号)

(First is "x" signal, second is "+" signal)

尽管我看到它们具有一些相似性,但两者都具有相同的幅度/频率,但不是相同的信号.

Both share the same amplitudes/frequencies, but are not the same signals, even if I can see they have some similarities.

好吧,由于我只绘制了FFT的绝对值,所以我想我丢失了一些信息.

Ok, since I only plotted absolute values of FFT, I guess I lost some informations.

然后我绘制了两个信号的实部,虚部和绝对值:

Then I plotted real part, imaginary part and absolute values for both signals :

现在,我很困惑.这一切我该怎么办?我从数学的角度了解了DFT.我知道复杂的值来自单位圆.我什至不得不了解希尔伯特空间,以了解它是如何工作的(这很痛苦!而且我只是从头开始).我只想了解这些实部/虚部图在数学世界之外是否具有任何 concrete 含义:

Now, I'm confused. What do I do with all this? I read about DFT from a mathematical point of view. I understand that complex values come from the unit circle. I even had to learn about Hilbert space to understand how it works (and it was painful!...and I only scratched the surface). I only wish to understand if these real/imaginary plots have any concrete meaning outside mathematical world:

  • abs(fft):频率+幅度
  • real(fft):?
  • imaginary(fft):?

代码:

import numpy as np
import matplotlib.pyplot as plt
N = 512 # Sample count
fs = 128 # Sampling rate
st = 1.0 / fs # Sample time
t = np.arange(N) * st # Time vector

signal1 = \
1   *np.cos(2*np.pi * t) *\
2   *np.cos(2*np.pi * 4*t) *\
0.5 *np.cos(2*np.pi * 0.5*t)

signal2 = \
0.25*np.sin(2*np.pi * 2.5*t) +\
0.25*np.sin(2*np.pi * 3.5*t) +\
0.25*np.sin(2*np.pi * 4.5*t) +\
0.25*np.sin(2*np.pi * 5.5*t)



_, axes = plt.subplots(4, 2)

# Plot signal
axes[0][0].set_title("Signal 1 (multiply)")
axes[0][0].grid()
axes[0][0].plot(t, signal1, 'b-')

axes[0][1].set_title("Signal 2 (add)")
axes[0][1].grid()
axes[0][1].plot(t, signal2, 'r-')

# FFT + bins + normalization
bins = np.fft.fftfreq(N, st)    
fft  = [i / (N/2) for i in np.fft.fft(signal1)]
fft2 = [i / (N/2) for i in np.fft.fft(signal2)]

# Plot real
axes[1][0].set_title("FFT 1 (real)")
axes[1][0].grid()
axes[1][0].plot(bins[:N/2], np.real(fft[:N/2]), 'b-')

axes[1][1].set_title("FFT 2 (real)")
axes[1][1].grid()
axes[1][1].plot(bins[:N/2], np.real(fft2[:N/2]), 'r-')

# Plot imaginary
axes[2][0].set_title("FFT 1 (imaginary)")
axes[2][0].grid()
axes[2][0].plot(bins[:N/2], np.imag(fft[:N/2]), 'b-')

axes[2][1].set_title("FFT 2 (imaginary)")
axes[2][1].grid()
axes[2][1].plot(bins[:N/2], np.imag(fft2[:N/2]), 'r-')

# Plot abs
axes[3][0].set_title("FFT 1 (abs)")
axes[3][0].grid()
axes[3][0].plot(bins[:N/2], np.abs(fft[:N/2]), 'b-')

axes[3][1].set_title("FFT 2 (abs)")
axes[3][1].grid()
axes[3][1].plot(bins[:N/2], np.abs(fft2[:N/2]), 'r-')

plt.show()

推荐答案

对于每个频点,幅值 sqrt(re^2 + im^2)会告诉您组件在相应频率处的幅值. phase atan2(im, re)告诉您该组件的相对相位.除非您对数据窗口中心周围的对称属性(偶数与奇数)感兴趣,否则实部和虚部本身并不是特别有用.

For each frequency bin, the magnitude sqrt(re^2 + im^2) tells you the amplitude of the component at the corresponding frequency. The phase atan2(im, re) tells you the relative phase of that component. The real and imaginary parts, on their own, are not particularly useful, unless you are interested in symmetry properties around the data window's center (even vs. odd).

这篇关于FFT实部/虚部/绝对部分解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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