function [Xk]=plot_fft(xn,N) % Plot Discrete Fourier Transform of a nonperiodic sequence by FFT % 參考“數位訊號處理—使用Matlab”, 余兆棠 陳順智 譯(Ingle and Proakis 原著),滄海圖書 % Example: %>> h=[1/3 1/3 1/3]; %>> [Xk]=plot_fft(h,16); Xk=fft(xn,N); n=0:1:(N-1); magXk = abs(Xk); angXk = angle(Xk); figure; subplot(2,1,1); stem(n,magXk);grid; xlabel('n=0~(N-1)'); ylabel('|Xk|'); title('Magnitude Part') subplot(2,1,2); stem(n,angXk);grid xlabel('n=0~(N-1)'); ylabel('radians');title('Angle Part')