Matlab中信号的频谱

3

这是我在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),或者绘制更多的freq点,freq=(0:1000)/2*n*dt。同时确保size(y,2)是一个偶数值。 - eventHandler
嗨,eventHandler,我尝试了,但没有帮助。 - etf
1个回答

1
问题在于为了得到完美的光谱(在50、90、180和0处有峰),你的间隔应该是所有频率的倍数。
解释:考虑 y=sin(2.*pi.*t)。使用你的代码绘制它:
1)et = 1-dt;
2)et = 1;
在第一种情况下,如果你放大,你会看到峰恰好在1 Hz。但在第二种情况下不是(非常接近)。
为什么?因为你正在处理有限数量的点,因此只有有限数量的频率。如果1 Hz在这组频率中(第一种情况),你将得到完美的1 Hz峰,并在所有其他频率上得到零。
在第二种情况下,你的集合中没有1 Hz频率,所以你将得到最近的频率上的峰(并且它也将具有有限的宽度)。
最终,在你的原始代码中,没有50、90、180 Hz频率在你的全部频率集中。

谢谢回复,Mikhail Genkin。所以在这里我无法做任何事情来获得完美的绘图吗? - etf
使用 et = 0.1-dt; 替代 et=0.1 - Mikhail Genkin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接