numpy.fftn中的高频词有哪些?
which are the high frequency terms in numpy.fftn?
我在 numpy 中使用 fftn 生成 20 单元一维阵列和 20x20x20 3D 阵列的离散 FT,并希望抑制高频项,从最高频率开始并向较低频率延伸。我更熟悉连续 FT,并努力识别 DFT 中的高频项。我应该在哪里查看 fftn 生成的数组? (我计划在反向转换之前将这些值设置为零。)
根据numpy.fft.fftn
documentation
中的注释
The output, analogously to fft, contains the term for zero frequency in the low-order corner of all axes, the positive frequency terms in the first half of all axes, the term for the Nyquist frequency in the middle of all axes and the negative frequency terms in the second half of all axes, in order of decreasingly negative frequency.
但是请注意,对于奇数大小的阵列,奈奎斯特频率未表示。此外,假设您正在处理实值信号,离散傅立叶变换将具有厄米特对称性。每当您在频域中处理这些信号时,如果您希望信号在逆变换后保持实值,那么保持对称性很重要。在将频率分量归零的同时,这意味着您还应该将相应负频率处的频率分量归零。
这对于您的 20 单元一维阵列(比如阵列 x
)、L
最高频率区间(包括 L/2
正频率和 L/2
负频率)具体意味着什么频率)因此
lower = (len(x)-L)/2+1
upper = (len(x)+L)/2+1
x[lower:upper]
同样,对于您的 20x20x20 3D 阵列(比如阵列 y
),每个轴上的 L
最高频率区间为:
lower = [(d-L)/2+1 for d in y.shape]
upper = [(d+L)/2+1 for d in y.shape]
y[lower[0]:upper[0],:,:] # middle of axis 0
y[:,lower[1]:upper[1],:] # middle of axis 1
y[:,:,lower[2]:upper[2]] # middle of axis 2
现在假设 this post by hotpaw2 中描述的振铃效应对您的应用程序来说不是问题,然后您可以使用以下方法将这些 bin 归零:
import numpy as np;
L = 3 # number of bins to zero out along each axis (change this to fit your needs)
# should be odd for even length array, and even for odd length array
# Following assumes x is the 1D array
lower = (len(x)-L)/2+1
upper = (len(x)+L)/2+1
x[lower:upper] = 0 # zero-out in the middle
# Following assume y is the 3D array
lower = [(d-L)/2+1 for d in y.shape]
upper = [(d+L)/2+1 for d in y.shape]
y[lower[0]:upper[0],:,:] = 0 # zero-out in the middle of axis 0
y[:,lower[1]:upper[1],:] = 0 # zero-out in the middle of axis 1
y[:,:,lower[2]:upper[2]] = 0 # zero-out in the middle of axis 2
我在 numpy 中使用 fftn 生成 20 单元一维阵列和 20x20x20 3D 阵列的离散 FT,并希望抑制高频项,从最高频率开始并向较低频率延伸。我更熟悉连续 FT,并努力识别 DFT 中的高频项。我应该在哪里查看 fftn 生成的数组? (我计划在反向转换之前将这些值设置为零。)
根据numpy.fft.fftn
documentation
The output, analogously to fft, contains the term for zero frequency in the low-order corner of all axes, the positive frequency terms in the first half of all axes, the term for the Nyquist frequency in the middle of all axes and the negative frequency terms in the second half of all axes, in order of decreasingly negative frequency.
但是请注意,对于奇数大小的阵列,奈奎斯特频率未表示。此外,假设您正在处理实值信号,离散傅立叶变换将具有厄米特对称性。每当您在频域中处理这些信号时,如果您希望信号在逆变换后保持实值,那么保持对称性很重要。在将频率分量归零的同时,这意味着您还应该将相应负频率处的频率分量归零。
这对于您的 20 单元一维阵列(比如阵列 x
)、L
最高频率区间(包括 L/2
正频率和 L/2
负频率)具体意味着什么频率)因此
lower = (len(x)-L)/2+1
upper = (len(x)+L)/2+1
x[lower:upper]
同样,对于您的 20x20x20 3D 阵列(比如阵列 y
),每个轴上的 L
最高频率区间为:
lower = [(d-L)/2+1 for d in y.shape]
upper = [(d+L)/2+1 for d in y.shape]
y[lower[0]:upper[0],:,:] # middle of axis 0
y[:,lower[1]:upper[1],:] # middle of axis 1
y[:,:,lower[2]:upper[2]] # middle of axis 2
现在假设 this post by hotpaw2 中描述的振铃效应对您的应用程序来说不是问题,然后您可以使用以下方法将这些 bin 归零:
import numpy as np;
L = 3 # number of bins to zero out along each axis (change this to fit your needs)
# should be odd for even length array, and even for odd length array
# Following assumes x is the 1D array
lower = (len(x)-L)/2+1
upper = (len(x)+L)/2+1
x[lower:upper] = 0 # zero-out in the middle
# Following assume y is the 3D array
lower = [(d-L)/2+1 for d in y.shape]
upper = [(d+L)/2+1 for d in y.shape]
y[lower[0]:upper[0],:,:] = 0 # zero-out in the middle of axis 0
y[:,lower[1]:upper[1],:] = 0 # zero-out in the middle of axis 1
y[:,:,lower[2]:upper[2]] = 0 # zero-out in the middle of axis 2