function [magX,angX,w] = plot_dtft(b,a) % DTFT computes the magnitude and phase responses(spectra) for a filter(signal) % for digital frequencies between -2*pi ~ 2*pi radians. % % [MAG, PHASE, W] = plot_dtft(B,A); % produces the dtft of the filter defined by the coefficients B and A. % % Chun-Tang Chao, 2008. 5. 5 % Ref: [1] "Digital Signal System with Matlab," Ingle and Proakis, Thomson Learning, 2000. % [2] "Fundamentals of Digital Signal Processing," Joyce Van de Vegte , Prentice Hall, 2002. w=-2*pi: pi/100:2*pi; % -2*pi ~ 2*pi ¶¡¡A¨ú 401 points k= -200:200; nb=0:length(b)-1; na=0:length(a)-1; Xb=b*exp(-j*nb'*w); % Xb=b*(exp(-j*pi/100)).^(nb'*k); if a==1 X=Xb; else Xa=a*exp(-j*na'*w); % Xa=a*(exp(-j*pi/100)).^(na'*k); X=Xb./Xa; end magX = abs(X); angX = angle(X); subplot(2,1,1); plot(w/pi,magX);grid xlabel('Frequency in pi units'); ylabel('|X|'); title('Magnitude Part') subplot(2,1,2); plot(w/pi,angX/pi);grid xlabel('Frequency in pi units'); ylabel('Radians/pi');title('Angle Part')