在MATLAB中找出实际频率值与FFT图索引之间的关系时出现困惑 [英] Confusion in figuring out the relation between actual frequency values and FFT plot indexes in MATLAB

查看:132
本文介绍了在MATLAB中找出实际频率值与FFT图索引之间的关系时出现困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多与此类似的问题,但我仍然无法找出答案. 假设我们在MATLAB中有时间信号:

I know that there are a lot of similar questions to this, I am still unable to figure out the answer. Let's say we have time signal in MATLAB:

t=0:1/44100:1

和一个频率为500Hz的余弦信号:

and a cosine signal with frequency 500Hz:

x=cos(2*pi*500*t);

现在,我试图在信号x上绘制使用fft命令获得的幅度谱.

Now, I am trying to plot the magnitude spectrum obtained using the fft command on signal x

FFT=abs(fft(x))
plot(FFT)

根据理论,我们应在图中获得两个峰值,一个峰值为-500 Hz,另一个峰值为500Hz. 我不明白的是,我确实有两个峰值,但我无法弄清楚这些峰值的频率.我知道有一种方法可以使用FFT索引,输入信号的长度和采样频率来确定频率,但是我仍然无法计算出频率.

According to the theory, we should get two peaks in the plot, one at -500 Hz and the other at 500Hz. What I don't understand is that I do get two peaks but I can't figure out at what frequencies these peaks are. I know there is a way to figure out the frequency using the FFT index, length of the input signal and the sampling frequency but I still can't calculate the frequency.

我知道有一些方法可以对齐FFT图,从而使峰值位于使用fftshift函数表示的频率的索引号上,但是我想要的是使用该图找出频率只需调用此函数即可:

I know that there are methods to align the FFT plots so that the peaks lie at the index number of the frequency they represent by using the fftshift function, but what I want is to figure out the frequency using the the plot resulting from simply calling this function:

FFT=fft(x)

在这种情况下,我已经知道该信号包含一个500Hz的余弦,但是如果我们想要获取FFT的信号在时间之前未知的话该怎么办.如何使用fft函数的输出获得该样本中峰值的频率值?

In this case, I already know that signal contains a cosine of 500Hz, but what if the signal that we want to get the FFT of is not known before time. How can we get the frequency values of the peaks in that sample using the output from the fft function?

推荐答案

您需要自己生成频率阵列,并针对它绘制FFT结果.

You need to generate the frequency array yourself and plot your FFT result against it.

赞:

function [Ycomp, fHz] = getFFT(data, Fs)
     len = length(data);
     NFFT = 2^nextpow2(len);
     Ydouble = fft(data, NFFT)/len; % Double-sided FFT
     Ycomp = Ydouble(1:NFFT/2+1); % Single-sided FFT, complex
     fHz = Fs/2*linspace(0,1,NFFT/2+1); % Frequency array in Hertz.
     semilogx(fHz, abs(Ycomp))
end

这篇关于在MATLAB中找出实际频率值与FFT图索引之间的关系时出现困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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