代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 5.22 '); banner(); %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ------------------------------------------------------------------- % 512-point DFT of a real-valued sequence x(n) % % ------------------------------------------------------------------- k = [0:511]; Xk_DFT = [zeros(1, 512)]; Xk_DFT(0+1) = 20; Xk_DFT(5+1) = 20+j*30; Xk_DFT(32+1) = -10+j*15; Xk_DFT(152+1) = 17+j*23; Xk_DFT(256+1) = 30; Xk_DFT(360+1) = 17-j*23; Xk_DFT(480+1) = -10-j*15; Xk_DFT(507+1) = 20-j*30; N = length(Xk_DFT); magXk_DFT = abs( [ Xk_DFT ] ); % DFT magnitude angXk_DFT = angle( [Xk_DFT] )/pi; % DFT angle realXk_DFT = real(Xk_DFT); imagXk_DFT = imag(Xk_DFT); EXk = sum(abs(Xk_DFT).^2)/N x = real(idft(Xk_DFT, N)); n = [0:N-1]; figure('NumberTitle', 'off', 'Name', 'P5.22 X(k), DFT of x(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(k, magXk_DFT); xlabel('k'); ylabel('magnitude(k)'); title('magnitude DFT of x(n), N=512'); grid on; subplot(2,2,3); stem(k, angXk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('angle(k)'); title('angle DFT of x(n), N=512'); grid on; subplot(2,2,2); stem(k, realXk_DFT); xlabel('k'); ylabel('real (k)'); title('real DFT of x(n), N=512'); grid on; subplot(2,2,4); stem(k, imagXk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('imag (k)'); title('imag DFT of x(n), N=512'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.22 x(n)') set(gcf,'Color','white'); %subplot(3,1,1); stem(n, x); xlabel('n'); ylabel('x(n)'); title('x(n), N=512'); grid on;
运行结果:
把alpha beta, k1、k2、k3求出来后,得知512点DFT有8个点不为零,如下图
进行IDFT,得到时间域序列x(n)
时间信号的能量