【问题标题】:how to get fourier transform of a signal如何获得信号的傅里叶变换
【发布时间】:2014-12-29 10:23:09
【问题描述】:

在下面的代码中,我试图获取固定信号 (x3) 的 fourier transform。但是在运行时,我得到的图绝对是错误的,并且没有显示信号 x3 的任何频率。

请指导我并帮助我正确获取fourier transform

代码

 %% Time specifications:
  Fs = 8000;                       % samples per second
  dt = 1/Fs;                       % seconds per sample
 StopTime = 1;                    % seconds
 t = (0:dt:StopTime-dt);         % seconds

 x1 = (10)*cos(2*pi*3*(t));
 x2 = x1 + (10)*cos(2*pi*5*(t));
 x3 = x2 + (10)*cos(2*pi*10*(t));


 %% here i try to Plot fourier transform of the signal x3:
 NFFT = 2^nextpow2(StopTime); % Next power of 2 from length of y
 Y = fft(y,NFFT)/StopTime;
 f = Fs/2*linspace(0,1,NFFT/2+1);
 figure;
 plot(f,2*abs(Y(1:NFFT/2+1)));

 %% Plot the signal versus time:
 figure;
 hold on;
 plot(t,x1,'r');
 plot(t,x2,'g');
 plot(t,x3,'b');

Update_1

【问题讨论】:

  • 为什么要用StopTime 缩放FFT?如果您希望时域中的能量等于频域中的能量,则必须按Fs 缩放。

标签: matlab signal-processing fft wavelet


【解决方案1】:

您看不到您的预期,因为NFFT 的值是1,这意味着当您将NFFT/2+1 写为Y 的索引时,它将不是整数值,因此 MATLAB 会警告您。你可以这样计算NFFT

NFFT = 2^nextpow2(length(t))

而不是写

NFFT = 2^nextpow2(StopTime)

好吧,试试这个:

Fs       = 8000;                 % samples per second
dt       = 1/Fs;                 % seconds per sample
StopTime = 1;                    % seconds
t        = (0 : dt : StopTime-dt);   % seconds

x1 = 10 * cos(2*pi*3*t);
x2 = x1 + 10 * cos(2*pi*5*t);
x3 = x2 + 10 * cos(2*pi*10*t);


%% here i try to Plot fourier transform of the signal x3:
NFFT = 2 ^ nextpow2(length(t));     % Next power of 2 from length of y
Y    = fft(x3, NFFT) / StopTime;
f    = Fs / 2 * linspace(0, 1, NFFT/2 + 1);
figure;
plot(f, 2 * abs( Y( 1:length(f) ) ) ); % // Also try this: plot(f(f <= 200), 2 * abs( Y( 1:length(f(f <= 200)) ) ) )

%% Plot the signal versus time:
figure;
hold on;
plot(t, x1, 'r');
plot(t, x2, 'g');
plot(t, x3, 'b');

情节:

编辑:

1- 其实你不必使用nextpow() 函数。如果你使用它,fft() 函数的工作速度会更快。因为,由于时间效率,fft() 的工作方式每次递归地将信号除以 2。然后计算每个部分的离散傅里叶变换并收集它们。这意味着当信号向量长度为​​ 2 的幂时,FFT 效率最高。

2- 将 fft 结果除以 StopTime 部分对我来说也没有任何意义。理论上,将 fft 结果除以NFFT 可能更方便。

【讨论】:

  • 感谢您的回答。现在在频率。域,绘图状态 plot(f, 2 * abs( Y( 1:length(f) ) ) );在 x 轴上从零到 4000 生成一个图形。例如,如何将 x 轴上的值最小化为 0-200。
  • 请再问一个问题,为什么我需要我在文档中读到的函数 nextpow2() 但我为什么需要它?以及为什么在此语句中除以 StopTime:fft(x3, NFFT) / StopTime
  • 你可以写“plot(f(f
  • 我希望你能在我之前的评论中看到我向你提出的问题 :)
  • 感谢您更新您的答案,请查看我对问题的更新并注意频率的差异。当我除以 NFFT 并且它被忽略时呈现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
  • 2021-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多