%-----------------------------------------------------------------
% exa040801_fft.m: for example 4.8.1
% to test fft.m dn ifft.m
%-----------------------------------------------------------------
clear all;
% 产生两个正弦加白噪声;
N=128;
df=1/64;
f1=0.15;f2=0.15+df;f3=0.15+2*df;
w1=2*pi*f1;w2=2*pi*f2;w3=2*pi*f3;
n=0:N-1;
x=sin(w1*n)+cos(w2*n)+cos(w3*n);
figure
% 应用FFT 求频谱;
subplot(2,1,1);
stem(n,x,'.');
f=-0.5:1/N:0.5-1/N;
X=fft(x);
subplot(2,1,2);
plot(f,fftshift(abs(X)));grid