代码:
n = [-1:3]; x = [1:5]; % x(n) = {1,2,3,4,5} % * % k = 0:500; w = (pi/500)*k; % [0,pi] axis divided into 501 points. X = x * (exp(-j*pi/500)) .^ (n'*k); magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X); set(gcf,'Color','white'); subplot(2,2,1); plot(k/500,magX); grid on; title('Magnitude Part'); xlabel('frequency in pi units'); ylabel('Magnitude'); subplot(2,2,3); plot(k/500, angX/pi); grid on; title('Angle Part'); xlabel('frequency in pi units'); ylabel('Radians/pi'); subplot('2,2,2'); plot(k/500, realX); grid on; title('Real Part'); xlabel('frequency in pi units'); ylabel('Real'); subplot('2,2,4'); plot(k/500, imagX); grid on; title('Imaginary Part'); xlabel('frequency in pi units'); ylabel('Imaginary');
运行结果: