python - numpy.fftn 中哪些是高频项?

标签 python arrays numpy fft

我正在 numpy 中使用 fftn 来生成 20 个单元的 1D 数组和 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 中描述的振铃效应对于您的应用程序来说不是问题,您可以使用以下方法将这些垃圾箱清零:

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

关于python - numpy.fftn 中哪些是高频项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35589725/

相关文章:

python - 如何在 Pycharm 的调试 session 中断期间向 python 类/对象添加方法?

python - 如何更改 Pandas 系列的索引值

java - 为什么不用类型转换就可以克隆数组?

PHP:修剪对象中的每个元素,如果为空,则设置为 N/A

python - 如何从列表中的键获取字典值?

python - 将矩阵的一部分叠加在另一个之上

python - 如何从字符串格式时间戳中提取日期?

python - 用计数替换嵌套列表中的元素

java - 关于java中的数组排序

python - Numpy 作为 django 项目中的库