从 ifft 信号中提取数据值
Extracting data values from the ifft signal
如何从Fourier transformation
中提取filtered signal
的values
?由于ifft
returns 一个复杂的数字,很难进一步计算。
我的python代码:
import numpy as np
# Create a simple signal with two frequencies
dt = 0.001
t = np.arange(0,1,dt)
f = np.sin(2*np.pi*50*t) + np.sin(2*np.pi*120*t) # Sum of 2 frequencies
f_clean = f
noise = 2.5*np.random.randn(len(t))
f = f + noise # Add some noise
## Compute the Fast Fourier Transform (FFT)
n = len(t)
fhat = np.fft.fft(f,n) # Compute the FFT
PSD = fhat * np.conj(fhat) / n # Power spectrum (power per freq)
freq = (1/(dt*n)) * np.arange(n) # Create x-axis of frequencies in Hz
L = np.arange(1,np.floor(n/2),dtype='int') # Only plot the first half of freqs
## Use the PSD to filter out noise
indices = PSD > 100 # Find all freqs with large power
PSDclean = PSD * indices # Zero out all others
fhat = indices * fhat # Zero out small Fourier coeffs. in Y
ffilt = np.fft.ifft(fhat) # Inverse FFT for filtered time signal
这里ffilt
是returns一个complex number
的滤波信号。我想用这个信号进行数学计算,但不确定提取值的过程。
下面您可以看到如何从复数中获取实数值,特别是它的实部和虚部,以及它的大小。
a = ffilt[10]
# (1.09200370931126+4.0997278010904346e-17j)
# Get real part
a.real
# 1.09200370931126
# Get imaginary part
a.imag
# 4.0997278010904346e-17
# Get magnitude
abs(a)
# 1.09200370931126
# (the imaginary part is close to zero, so the magnitude
# is almost equal to the real part)
您可以对整个数组执行上述操作。
ffilt.real
ffilt.imag
abs(ffilt)
# Bonus: phase
np.angle(ffilt)
我不知道你接下来的计算是什么,但你可能想要使用星等 (abs)。
如何从Fourier transformation
中提取filtered signal
的values
?由于ifft
returns 一个复杂的数字,很难进一步计算。
我的python代码:
import numpy as np
# Create a simple signal with two frequencies
dt = 0.001
t = np.arange(0,1,dt)
f = np.sin(2*np.pi*50*t) + np.sin(2*np.pi*120*t) # Sum of 2 frequencies
f_clean = f
noise = 2.5*np.random.randn(len(t))
f = f + noise # Add some noise
## Compute the Fast Fourier Transform (FFT)
n = len(t)
fhat = np.fft.fft(f,n) # Compute the FFT
PSD = fhat * np.conj(fhat) / n # Power spectrum (power per freq)
freq = (1/(dt*n)) * np.arange(n) # Create x-axis of frequencies in Hz
L = np.arange(1,np.floor(n/2),dtype='int') # Only plot the first half of freqs
## Use the PSD to filter out noise
indices = PSD > 100 # Find all freqs with large power
PSDclean = PSD * indices # Zero out all others
fhat = indices * fhat # Zero out small Fourier coeffs. in Y
ffilt = np.fft.ifft(fhat) # Inverse FFT for filtered time signal
这里ffilt
是returns一个complex number
的滤波信号。我想用这个信号进行数学计算,但不确定提取值的过程。
下面您可以看到如何从复数中获取实数值,特别是它的实部和虚部,以及它的大小。
a = ffilt[10]
# (1.09200370931126+4.0997278010904346e-17j)
# Get real part
a.real
# 1.09200370931126
# Get imaginary part
a.imag
# 4.0997278010904346e-17
# Get magnitude
abs(a)
# 1.09200370931126
# (the imaginary part is close to zero, so the magnitude
# is almost equal to the real part)
您可以对整个数组执行上述操作。
ffilt.real
ffilt.imag
abs(ffilt)
# Bonus: phase
np.angle(ffilt)
我不知道你接下来的计算是什么,但你可能想要使用星等 (abs)。