function [Xk]=plot_dfs(xn) % Plot Discrete-Time Fourier Series of a periodic sequence % Ref:“Digital Signal with Matlab,” Ingle and Proakis, Thomas Learning, 2000. %【“數位訊號處理—使用Matlab”, 余兆棠 陳順智 譯(Ingle and Proakis 原著),滄海圖書】 % Example 1: %>> h=[1/3 1/3 1/3]; %>> [Xk]=plot_dfs(h); % Example 2: %>> h=[1/3 1/3 1/3 0 0 0 0 0]; %>> [Xk]=plot_dfs(h); N=length(xn) w=0:2*pi/N:(2*pi-2*pi/N); % 0 <= w < 2*pi 間取 N 點 n=0:1:(N-1); Xk=xn*exp(-j*n'*w); 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')