k=0:N/2;w=2*pi/N*k; X=fft(x,N);
magX=abs(X(1:N/2+1));
subplot(2,1,1);stem(n,x,'.');title('Signal x(n)'); subplot(2,1,2);plot(w/pi,magX);title('FFT N=128'); xlabel('Fre(unit :pi)');ylabel('|X|');grid;
N=64,df=1/16 N=64,df=1/64 Signal x(n)Signal x(n)442200-2-2-4020406080100120140-4010203040506070FFT N=128FFT N=6480306020||XX|40|2010000.10.20.30.40.50.60.70.80.91000.10.20.30.40.50.60.70.80.91Fre(unit :pi)Fre(unit :pi) N=128,df=1/64
Signal x(n)420-2-4010203040506070FFT N=644030|X|2010000.10.20.30.40.50.60.70.80.91Fre(unit :pi)
程序3: t=0:0.001:0.8;
x=sin(2*pi*50*t)+cos(2*pi*120*t); y=x+1.5*randn(1,length(t));
17
subplot(3,1,1);plot(t,x);
subplot(3,1,2);plot(t,y);%title('press any key,continue...'); %pause; Y=fft(y,512); P=Y.*conj(Y)/512; f=1000*(0:255)/512;
subplot(3,1,3);plot(f,P(1:256));
20-210000.10.20.30.40.50.60.70.8-1015010050000.10.20.30.40.50.60.70.8050100150200250300350400450500
五.思考题
FFT对信号进行频谱分析时,信号的频率的分辨率与什么有关?能否给出其数学关系?
答:FFT对信号进行频谱分析时,信号的频率分辨率与采样点数N和采样周期T有关,其数学关系为:频率分辨率?1/NT 六.心得体会
18