如何在Python中提取与fft值相关的频率
我在 numpy 中使用了 fft 函数,这导致了一个复杂的数组。如何获得准确的频率值?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我在 numpy 中使用了 fft 函数,这导致了一个复杂的数组。如何获得准确的频率值?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
np.fft.fftfreq
告诉您与系数相关的频率:OP 询问如何找到以赫兹为单位的频率。
我相信公式是频率(Hz)=abs(fft_freq *帧速率)。
下面是一些代码来演示这一点。
首先,我们制作一个 440 Hz 的波形文件:
这将创建文件
test.wav
。现在我们读入数据,对其进行 FFT,找到功率最大的系数,
并找到对应的fft频率,然后转换为赫兹:
np.fft.fftfreq
tells you the frequencies associated with the coefficients:The OP asks how to find the frequency in Hertz.
I believe the formula is
frequency (Hz) = abs(fft_freq * frame_rate)
.Here is some code that demonstrates that.
First, we make a wave file at 440 Hz:
This creates the file
test.wav
.Now we read in the data, FFT it, find the coefficient with maximum power,
and find the corresponding fft frequency, and then convert to Hertz:
这里我们处理 fft 的 Numpy 实现。
与 DFT 值相关的频率(在 Python 中)
通过 fft(快速傅里叶变换),我们了解了一个算法大家族的成员,这些算法能够快速计算 DFT、离散等采样信号的傅里叶变换。
DFT 转换 N 的有序序列 em> 复数转换为 N 个复数的有序序列,要理解的是这两个序列都是周期性且周期为 N。
在许多情况下,您会想到
X = np.fft.fft(x)
),其元素在频率轴上以采样率 dω 进行采样嗯>。一些定义
信号
x
的周期(又名持续时间²),在dt
处采样,具有N
个样本,是<前><代码> T = dt*N
基频(以Hz为单位,以rad/s为单位)的
X
,你的DFT是<前><代码> df = 1/T
dω = 2*pi/T # =df*2*pi
最高频率是 奈奎斯特频率
<前><代码> ny = dω*N/2
(注意:奈奎斯特频率不是
dω*N
)³与 DFT 中特定元素相关的频率
对于给定索引
0 中的元素相对应的频率=n 可以按如下方式计算:
或者在单次扫描中
,如果您更愿意考虑以 Hz 为单位的频率,
s/ω/f/
使用这些频率
如果您想修改原始信号
x
->y
仅以频率函数的形式在频域中应用算子,方法是计算ω
并引入
np.fft .fftfreq
当然,
numpy
有一个方便的函数np.fft.fftfreq
,它返回无量纲频率,而不是有维频率 但这就像因为
df = 1/T
和T = N/sps
(sps
是每个样本的样本数) 一样简单第二)还可以写注释
周期性的基本思想。
Here we deal with the Numpy implementation of the fft.
Frequencies associated with DFT values (in python)
By fft, Fast Fourier Transform, we understand a member of a large family of algorithms that enable the fast computation of the DFT, Discrete Fourier Transform, of an equisampled signal.
A DFT converts an ordered sequence of N complex numbers to an ordered sequence of N complex numbers, with the understanding that both sequences are periodic with period N.
In many cases, you think of
X = np.fft.fft(x)
), whose elements are sampled on the frequency axis with a sample rate dω.Some definition
the period (aka duration²) of the signal
x
, sampled atdt
withN
samples is isthe fundamental frequencies (in Hz and in rad/s) of
X
, your DFT arethe top frequency is the Nyquist frequency
(NB: the Nyquist frequency is not
dω*N
)³The frequencies associated with a particular element in the DFT
The frequencies corresponding to the elements in
X = np.fft.fft(x)
for a given index0<=n<N
can be computed as follows:or in a single sweep
if you prefer to consider frequencies in Hz,
s/ω/f/
Using those frequencies
If you want to modify the original signal
x
->y
applying an operator in the frequency domain in the form of a function of frequency only, the way to go is computing theω
's andIntroducing
np.fft.fftfreq
Of course
numpy
has a convenience functionnp.fft.fftfreq
that returns dimensionless frequencies rather than dimensional ones but it's as easy asBecause
df = 1/T
andT = N/sps
(sps
being the number of samples per second) one can also writeNotes
fundamental idea of periodicity.
频率只是数组的索引。在索引 n 处,频率为 2πn / 数组长度(每单位弧度)。考虑:
结果在索引 0、2 和 6 处具有非零值。有 8 个元素。这意味着
The frequency is just the index of the array. At index n, the frequency is 2πn / the array's length (radians per unit). Consider:
the result has nonzero values at indices 0, 2 and 6. There are 8 elements. This means