在八度音阶上绘制FFT [英] Plotting FFT on octave

查看:104
本文介绍了在八度音阶上绘制FFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道FFT将时域的功能更改为频域中显示的功能.

I know that FFT changes a function in the time domain to one showed in the frequency domain.

但是,当我尝试在频域中绘制上述图形时,我只能通过使用时间作为X轴来使它正常工作,而显然应该不是时间,而是频率.

However, when I try plotting said graph in the frequency domain, I can only get it to work properly by using the time as X-axis, when it was obviously supposed to be not that, but the frequency.

此外,我只能通过将y轴除以某个整数来获得与原始信号中的振幅匹配的振幅.为什么会这样?

Also, I can only get the amplitudes to match the ones in the original signal by dividing the y-axis by a certain integer. Why is that?

这是我的代码

t=0:0.001:2

x=2*sin(20*pi*t) + sin(100*pi*t)
subplot(2,1,1)
plot(1000*t,x)
grid
xlabel("Time in milliseconds")
ylabel("Signal amplitude")

subplot(2,1,2)
y=fft(x)
plot(1000*t,abs(y))
xlabel("Frequency")
ylabel("Signal amplitude")

和图形.

请帮助=(

推荐答案

频率关系(x轴缩放)

FFT产生的每个值的频率通过以下方式与输出值的索引线性相关:

Frequency relationship (x-axis scaling)

The frequency of each values produced by the FFT is linearly related to the index of the output value through:

f(i) = (i-1)*sampling_frequency/N

其中N是FFT点数(即N=length(y)).您的情况是N=2001.

Where N is the number of FFT points (ie. N=length(y)). In your case, N=2001.

您可以从您对t的定义中减去采样频率为1/T,其中T是采样时间间隔(在您的情况下为T = 0.001). 因此采样频率为1000Hz.

One can deduct the sampling frequency from your definition of t as 1/T where T is the sampling time interval (T=0.001 in your case). So the sampling frequency is 1000Hz.

请注意,由于t(i)的值也与索引i线性相关,因此

Note that since the value of t(i) is also linearly related to the index i, through

t(i) = (i-1)*0.001

有可能(尽管不一定建议这样做,因为这只会使您的代码晦涩难懂)来定义f = 1000*t*sampling_frequency/N. 请注意,您错过了sampling_frequency/N术语,这相应地导致以错误的频率显示音调 (根据x的定义,应该在10Hz和50Hz处出现峰值,并在990Hz和950Hz处出现相应的别名.)

it is possible (though not necessarilly advised, as this would just obscure your code) to define f = 1000*t*sampling_frequency/N. Note that you were missing the sampling_frequency/N term which correspondingly resulted in tones being shown at the wrong frequency (from the definition of x there should be peaks at 10Hz and 50Hz, and the corresponding aliases at 990Hz and 950Hz).

请注意,观察到的关系只是近似的,因此以下内容并不是数学证明,而只是可视化时域音调幅度与频域峰值之间关系的直观方式.

Note that the observed relationship is only approximate, so the following is not a mathematical proof, but merely a intuitive way to visualize the relationship between the time-domain tone amplitudes and the frequency-domain peak values.

将问题简化为一个音调:

Simplifying the problem to a single tone:

x = A*sin(2*pi*f*t)

可以使用 Parseval定理得出相应峰值的近似振幅:

The approximate amplitude of the corresponding peak could be derived using Parseval's theorem:

在时域(等式的左侧),表达式近似等于0.5*N*(A^2).

In the time domain (the left side of the equation), the expression is approximately equal to 0.5*N*(A^2).

在频域(等式的右侧),进行以下假设:

In the frequency domain (the right side of the equation), making the following assumptions:

  • 光谱泄漏效应可以忽略不计
  • 音的
  • 频谱内容仅包含在两个仓中(在频率f和相应的别名频率sampling_frequency-f),用于求和(所有其他仓为〜0).请注意,这通常仅在音频频率是sampling_frequency/N的精确(或近似精确)倍数时成立.
  • spectral leakage effects are negligible
  • spectral content of the tone is contained in only 2 bins (at frequency f and the corresponding aliased frequency sampling_frequency-f) account for the summation (all other bins being ~0). Note that this typically only holds if the tone frequency is an exact (or near exact) multiple of sampling_frequency/N.

对于某些k值(对应于频率f的峰值),右侧的表达式近似等于2*(1/N)*abs(X(k))^2.

the expression on the right side is approximately equal to 2*(1/N)*abs(X(k))^2 for some value of k corresponding to the peak at frequency f.

将两者放在一起将产生abs(X(k)) ~ 0.5*A*N.换句话说,正如您所观察到的那样,输出幅度相对于时域幅度的比例因子为0.5*N(在您的情况下约为1000).

Putting the two together yields abs(X(k)) ~ 0.5*A*N. In other words the output amplitude shows a scaling factor of 0.5*N (or approximately 1000 in your case) with respect to the time-domain amplitude, as you had observed.

这个想法仍然适用于不止一种音调(尽管可以忽略的频谱泄漏假设最终被打破了).

The idea still applies with more than one tone (although the negligible spectral leakage assumption eventually breaks down).

这篇关于在八度音阶上绘制FFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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