【发布时间】: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),或/和绘制更多freq、freq=(0:1000)/2*n*dt的点。还要确保size(y,2)是偶数。 -
嗨 eventHandler,我试过了,但没有帮助。
标签: matlab fft frequency spectrum