MATLAB FFT。难以理解频率和结果之间的关系

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/171345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:39:31  来源:igfitidea点击:

matlab FFT. Stuck understanding relationship between frequency and result

matlabfft

提问by Kevin

We're trying to analyse flow around circular cylinder and we have a set of Cp values that we got from wind tunnel experiment. Initially, we started off with a sample frequency of 20 Hz and tried to find the frequency of vortex shedding using FFT in matlab. We got a frequency of around 7 Hz. Next, we did the same experiment, but the only thing we changed was the sampling frequency- from 20 Hz to 200 Hz. We got the frequency of the vortex shedding to be around 70 Hz (this is where the peak is located in the graph). The graph doesn't change regardless of the Cp data that we enter. The only time the peak differs is when we change the sample frequency. It seems like the increase in the frequency of vortex shedding is proportional to the sample frequency and this doesn't seem to make sense at all. Any help regarding establishing a relation between sample frequency and vortex shedding frequency would be greatly appreaciated.

我们正在尝试分析圆柱体周围的流动,我们有一组从风洞实验中获得的 Cp 值。最初,我们以 20 Hz 的采样频率开始,并尝试在 matlab 中使用 FFT 找到涡旋脱落的频率。我们得到了大约 7 Hz 的频率。接下来,我们做了同样的实验,但我们唯一改变的是采样频率——从 20 Hz 到 200 Hz。我们得到涡旋脱落的频率约为 70 Hz(这是图中峰值所在的位置)。无论我们输入什么 Cp 数据,图表都不会改变。峰值不同的唯一时间是我们改变采样频率。似乎涡旋脱落频率的增加与采样频率成正比,这似乎根本没有意义。

回答by Kevin

The problem you are seeing is related to "data aliasing" due to limitations of the FFT being able to detect frequencies higher than the Nyquist Frequency(half-the sampling frequency).

由于 FFT 能够检测高于奈奎斯特频率(采样频率的一半)的频率的限制,您看到的问题与“数据混叠”有关。

With data aliasing, a peak in real frequency will be centered around (real frequency moduloNyquist frequency). In your 20 Hz sampling (assuming 70 Hz is the true frequency, that results in zero frequency which means you're not seeing the real information. One thing that can help you with this is to use FFT "windowing".

使用数据混叠,实际频率的峰值将以(实际频率奈奎斯特频率)为中心。在您的 20 Hz 采样中(假设 70 Hz 是真实频率,这会导致频率为零,这意味着您看不到真实信息。可以帮助您解决此问题的一件事是使用 FFT“窗口化”。

Another problem that you may be experiencing is related to noisy data generation via single-FFT measurement. It's better to take lots of data, use windowing with overlap, and make sure you have at least 5 FFTs which you average to find your result. As Steven Lowe mentioned, you should also sample at faster rates if possible. I would recommend sampling at the fastest rate your instruments can sample.

您可能遇到的另一个问题与通过单 FFT 测量生成噪声数据有关。最好获取大量数据,使用重叠的窗口,并确保您至少有 5 个 FFT,您可以平均找到结果。正如 Steven Lowe 所提到的,如果可能,您还应该以更快的速率进行采样。我建议以您的仪器可以采样的最快速度进行采样。

Lastly, I would recommend that you read some excerpts from Numerical Recipes in C(<-- link):

最后,我建议您阅读C 语言中的数值食谱的一些摘录(<-- 链接):

You don't need to read the C source code -- just the explanations. Numerical Recipes for C has excellent condensed information on the subject.

您不需要阅读 C 源代码——只需阅读解释即可。Numerical Recipes for C 有关于这个主题的极好的浓缩信息。

If you have any more questions, leave them in the comments. I'll try to do my best in answering them.

如果您还有其他问题,请在评论中留言。我会尽力回答他们。

Good luck!

祝你好运!

回答by Steven A. Lowe

this is probably not a programming problem, it sounds like an experiment-measurement problem

这可能不是编程问题,听起来像是实验测量问题

i think the sampling frequency has to be at least twice the rate of the oscillation frequency, otherwise you get artifacts; this might explain the difference. Note that the ratio of the FFT frequency to the sampling frequency is 0.35 in both cases. Can you repeat the experiment with higher sampling rates? I'm thinking that if this is a narrow cylinder in a strong wind, it may be vibrating/oscillating faster than the sampling rate can detect..

我认为采样频率必须至少是振荡频率的两倍,否则会出现伪影;这可能解释了差异。请注意,两种情况下 FFT 频率与采样频率的比率均为 0.35。你能用更高的采样率重复这个实验吗?我在想,如果这是一个在强风中的窄圆柱体,它的振动/振荡速度可能比采样率可以检测到的速度快。

i hope this helps - there's a 97.6% probability that i don't know what i'm talking about ;-)

我希望这会有所帮助 - 我有 97.6% 的可能性不知道我在说什么;-)

回答by temp2290

Methinks you need to do some serious reading on digital signal processing before you can even begin to understand all the nuances of the DFT (FFT). If I was you, I'd get grounded in it first with this great book:

我认为在开始理解 DFT (FFT) 的所有细微差别之前,您需要认真阅读有关数字信号处理的内容。如果我是你,我会先用这本好书扎根:

Discrete-Time Signal Processing

离散时间信号处理

If you want more of a mathematical treatment that will really expand your abilities,

如果你想要更多的数学处理来真正扩展你的能力,

Fourier Analysis by K?rner

K?rner 的傅立叶分析

回答by Will Robertson

If it's not an aliasing problem, it sounds like you could be plotting the frequency response on a normalised frequency scale, which will change with sample frequency. Here's an example of a reasonably good way to plot a frequency response of a signal in Matlab:

如果这不是混叠问题,听起来您可以在归一化频率标度上绘制频率响应,该标度将随采样频率而变化。下面是在 Matlab 中绘制信号频率响应的一种相当好的方法示例:

Fs = 100;
Tmax = 10;
time = 0:1/Fs:Tmax; 
omega = 2*pi*10; % 10 Hz
signal = 10*sin(omega*time) + rand(1,Tmax*Fs+1);

Nfft = 2^8;
[Pxx,freq] = pwelch(signal,Nfft,[],[],Fs)
plot(freq,Pxx)

Note that the sample frequency must be explicitly passed to the pwelchcommand in order to output the “real” frequency data. Otherwise, when you change the sample frequency the bin where the resonance occurs will seem to shift, which is similar to the problem you describe.

请注意,采样频率必须明确传递给pwelch命令,以便输出“真实”频率数据。否则,当您更改采样频率时,发生共振的 bin 似乎会发生变化,这与您描述的问题类似。

回答by Will Robertson

I tried using the frequency response code as above but it seems that I dont have the appropriate toolbox in Matlab. Is there any way to do the same thing without using fft command? So far, this is what I have:

我尝试使用上面的频率响应代码,但似乎我在 Matlab 中没有合适的工具箱。有没有办法在不使用 fft 命令的情况下做同样的事情?到目前为止,这就是我所拥有的:

   % FFT Algorithm

Fs = 200;                     % Sampling frequency
T = 1/Fs;                     % Sample time
L = 65536;                    % Length of signal
t = (0:L-1)*T;                % Time vector
y = data1;                    % Your CP values go in this vector

NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2);

% Plot single-sided amplitude spectrum.
loglog(f,2*abs(Y(1:NFFT/2))) 
title(' y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

I think there might be something wrong with the code I am using. I'm not sure what though.

我认为我使用的代码可能有问题。我不确定是什么。

回答by Will Robertson

A colleague of mine has written some nice GPL-licenced functions for spectral analysis: http://www.mecheng.adelaide.edu.au/~pvl/octave/

我的一位同事为频谱分析编写了一些不错的 GPL 许可函数:http: //www.mecheng.adelaide.edu.au/~pvl/octave/

(Update: this code is now part of one of the Octave modules:
http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/signal/inst/.
But it might be tricky to extract just the pieces you need from there.)

更新:此代码现在是 Octave 模块之一的一部分:
http: //octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/signal/inst/
但它可能很棘手从那里只提取您需要的部分。)

They're written for both Matlab and Octave and serve mostly as a drop-in replacement for the analogous functions in the Signal Processing Toolbox. (So the code aboveshould still work fine.)

它们是为 Matlab 和 Octave 编写的,主要用作信号处理工具箱中类似函数的替代品。(所以上面代码应该仍然可以正常工作。)

It may help with your data analysis; better than rolling your own with fftand the like.

它可能有助于您的数据分析;比滚动你自己的更好fft

回答by Andrew Edgecombe

Take a look at thisrelated question. While it was originally asked about asked about VB the responses are generically about FFTs

看看这个相关的问题。虽然最初被问及有关 VB 的问题,但回答通常是关于 FFT 的