【问题标题】:Frequency spectrum of signal in MatlabMatlab中信号的频谱
【发布时间】:2015-06-12 13:44:48
【问题描述】:

这是我用来在 Matlab 中绘制频域函数的代码:

    dt = 1/10000; % sampling rate
    et = 0.1; % end of the interval
    t = 0:dt:et; % sampling range
    y = 2+sin(2.*pi.*50.*t)+18.*sin(2.*pi.*90.*t)+6.*sin(2.*pi.*180.*t); %     sample the signal
    subplot(2,1,1); % first of two plots
    plot(t,y); grid on % plot with grid
    xlabel('Time (s)'); % time expressed in seconds
    ylabel('Amplitude'); % amplitude as function of time
    Y = fft(y); % compute Fourier transform
    n = size(y,2)/2; % 2nd half are complex conjugates
    amp_spec = abs(Y)/n; % absolute value and normalize
    subplot(2,1,2); % second of two plots
    freq = (0:100)/(2*n*dt); % abscissa viewing window
    stem(freq,amp_spec(1:101)); grid on % plot amplitude spectrum
    xlabel('Frequency (Hz)'); % 1 Herz = number of cycles/second
    ylabel('Amplitude'); % amplitude as function of frequency

问题是,当我放大图表时,我看不到 50Hz、90Hz 和 180Hz 的峰值。

我的代码做错了什么?

【问题讨论】:

  • 您应该尝试设置更高的dt 值(如1/1000),或/和绘制更多freqfreq=(0:1000)/2*n*dt 的点。还要确保size(y,2) 是偶数。
  • 嗨 eventHandler,我试过了,但没有帮助。

标签: matlab fft frequency spectrum


【解决方案1】:

问题在于,为了获得完美的光谱(峰值在 50、90、180 和 0 否则),您的间隔应该是所有频率的乘数。

解释:考虑y=sin(2.*pi.*t)。使用您的代码绘制它:

1)et = 1-dt;

2)et = 1;

在第一种情况下,如果放大,您会看到峰值正好在 1 Hz。在第二种情况下,它不是(也非常接近)。

为什么?因为您正在处理有限数量的点,因此,有限数量的频率。如果 1 Hz 在这组频率中(第一种情况),您将在 1 Hz 处获得完美的峰值,而在所有其他频率处为零。

在情况 2 中,您的集合中没有 1 Hz 的频率,因此您将在最近的频率上获得峰值(并且它的宽度也有限)。

最终,在您的原始代码中,您的全套频率中没有 50、90、180 Hz 的频率。

【讨论】:

  • 感谢米哈伊尔根金的回复。所以我在这里没有什么可以为完美的情节做的吗?
  • 使用et = 0.1-dt; 代替et=0.1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-15
  • 1970-01-01
相关资源
最近更新 更多