MATLAB 中的 FFT:错误的 0Hz 频率

发布于 2024-09-03 00:15:33 字数 300 浏览 0 评论 0原文

我想在 MATLAB 中使用 fft 来分析一些保存为 Excel 文件的实验数据。 我的代码:

A=xlsread('Book.xls'); G=A'; x=G(2, : );
N=length(x);
F=[-N/2:N/2-1]/N;
X = abs(fft(x-mean(x),N))
X = fftshift(X);
plot(F,X)

但它绘制了一个带有大量 0Hz 错误分量的图表,我的真实频率约为 395Hz,并且它没有显示在绘制的图表中。 请告诉我出了什么问题。

任何帮助将不胜感激。

I want to use fft in MATLAB to analize some exprimental data saved as an excell file.
my code:

A=xlsread('Book.xls'); G=A'; x=G(2, : );
N=length(x);
F=[-N/2:N/2-1]/N;
X = abs(fft(x-mean(x),N))
X = fftshift(X);
plot(F,X)

But it plots a graph with a large 0Hz wrong component, my true frequency is about 395Hz and it is not shown in the plotted graph.
Please tell me what is wrong.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2024-09-10 00:15:33

假设我们从文件中读取信号:

G = xlsread('Book.xls');
t = G(:,1);
x = G(:,2);
N = length(x);

首先我们从时间轴估计采样频率,并构建频率向量:

Fs = 1 ./ abs( t(2)-t(1) );
F = (-N/2:N/2-1)*Fs/N;

然后计算 FFT 并绘图:

X = abs( fft(x-mean(x),N) );
X = fftshift(X);
stem(F,X)

最后找到峰值和相应的频率:

>> [~,ind] = max(X);
>> F(ind)
ans =
         -400

您可能需要放大到更清楚地看到事物的起源:

xlim([-1000 1000])

Assume we read the signal from file:

G = xlsread('Book.xls');
t = G(:,1);
x = G(:,2);
N = length(x);

First we estimate the sampling frequency from the time axis, and build the frequency vector:

Fs = 1 ./ abs( t(2)-t(1) );
F = (-N/2:N/2-1)*Fs/N;

then compute the FFT and plot:

X = abs( fft(x-mean(x),N) );
X = fftshift(X);
stem(F,X)

finally find the peak and the corresponding frequency:

>> [~,ind] = max(X);
>> F(ind)
ans =
         -400

you might want to zoom-in near the origin to see things more clearly:

xlim([-1000 1000])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文