2018年元旦,他乡加班中,外面尽是些放炮的,别人的繁华与我无关。
代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(‘\n***********************************************************\n‘); fprintf(‘ <DSP using MATLAB> Problem 3.8 \n\n‘); banner(); %% ------------------------------------------------------------------------ n_start = -5; n_end = 30; n = [n_start:n_end]; x = exp(j*0.1*pi*n) .* (stepseq(0, n_start, n_end)-stepseq(20, n_start, n_end)); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 x(n)‘) set(gcf,‘Color‘,[1,1,1]) % 改变坐标外围背景颜色 subplot(2,1,1); stem(n, real(x)); title(‘x sequence Real Part‘); xlabel(‘n‘); ylabel(‘Real[x(n)]‘) ; % axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(n, imag(x)); title(‘x sequence Imag Part‘); xlabel(‘n‘); ylabel(‘Imag[x(n)]‘); grid on; % ---------------------------------------------------- % DTFT of x(n) % ---------------------------------------------------- MM = 500; k = [-MM:MM]; % [-pi, pi] %k = [0:M]; % [0, pi] w = (pi/MM) * k; [X] = dtft(x, n, w); magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 X(w)--DTFT of x(n)‘); set(gcf,‘Color‘,‘white‘); subplot(2,1,1); plot(w/pi, magX); grid on; title(‘Magnitude Part of X(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude‘); subplot(2,1,2); plot(w/pi, angX); grid on; title(‘Angle Part of X(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Radians‘); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 Real and Imag of X(w)‘); set(gcf,‘Color‘,‘white‘); subplot(‘2,1,1‘); stem(w/pi, realX); grid on; title(‘Real Part of X(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Real‘); subplot(‘2,1,2‘); stem(w/pi, imagX); grid on; title(‘Imaginary Part of X(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘); %% ---------------------------------------------------- %% Even and Odd part of X(jw) %% ---------------------------------------------------- [XE, XO, m] = evenodd_cv(X, w/pi*500); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 XE(m)--Even of X(w)‘) set(gcf,‘Color‘,[1,1,1]) subplot(2,1,1); stem(m/500, real(XE)); title(‘Real Part of Even Sequence‘); xlabel(‘m in \pi units‘); ylabel(‘Real[XE(m)]‘); %axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(m/500, imag(XE)); title(‘Imag Part of Even Sequence‘); xlabel(‘m in \pi units‘); ylabel(‘Imag[XE(m)]‘); %axis([-10,10,0,1.2]) grid on figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 XO(m)--Odd of X(w)‘) set(gcf,‘Color‘,‘white‘) subplot(2,1,1); stem(m/500, real(XO)); title(‘Real Part of Odd Sequence‘); xlabel(‘m in \pi units‘); ylabel(‘Real[XO(m)]‘); %axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(m/500, imag(XO)); title(‘Imag Part of Odd Sequence‘); xlabel(‘m in \pi units‘); ylabel(‘Imag[XO(m)]‘); %axis([-10,10,0,1.2]) grid on % --------------------------------------------------- % DTFT of Realx(n) % --------------------------------------------------- MM = 500; k = [-MM:MM]; % [-pi, pi] %k = [0:M]; % [0, pi] w = (pi/MM) * k; [RX] = dtft(real(x), n, w); magRX = abs(RX); angRX = angle(RX); realRX = real(RX); imagRX = imag(RX); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 RX(w)--DTFT of Realx(n)‘); set(gcf,‘Color‘,‘white‘); subplot(2,1,1); plot(w/pi, magRX); grid on; title(‘Magnitude Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude‘); subplot(2,1,2); plot(w/pi, angRX); grid on; title(‘Angle Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Radians‘); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 Real and Imag of RX(w)‘); set(gcf,‘Color‘,‘white‘); subplot(‘2,1,1‘); plot(w/pi, realRX); grid on; title(‘Real Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Real‘); subplot(‘2,1,2‘); plot(w/pi, imagRX); grid on; title(‘Imaginary Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘); % ------------------------------------------------------- % DTFT of Imagx(n) % ------------------------------------------------------- MM = 500; k = [-MM:MM]; % [-pi, pi] %k = [0:M]; % [0, pi] w = (pi/MM) * k; [IX] = dtft(j*imag(x), n, w); magIX = abs(IX); angIX = angle(IX); realIX = real(IX); imagIX = imag(IX); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 IX(w)--DTFT of Imagx(n)‘); set(gcf,‘Color‘,‘white‘); subplot(2,1,1); plot(w/pi, magIX); grid on; title(‘Magnitude Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude‘); subplot(2,1,2); plot(w/pi, angIX); grid on; title(‘Angle Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Radians‘); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 Real and Imag of IX(w)‘); set(gcf,‘Color‘,‘white‘); subplot(‘2,1,1‘); plot(w/pi, realIX); grid on; title(‘Real Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Real‘); subplot(‘2,1,2‘); plot(w/pi, imagIX); grid on; title(‘Imaginary Part‘); xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘); % ------------------------------------------ % Verify % ------------------------------------------ figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 RX(w) and RealXE‘); set(gcf,‘Color‘,‘white‘); subplot(‘2,1,1‘); plot(w/pi, realRX); grid on; title(‘Real Part of RX(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Real‘); subplot(‘2,1,2‘); plot((m/500), real(XE)); grid on; title(‘Real Part of XE(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Real‘); figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 3.8 IX(w) and ImagXO‘); set(gcf,‘Color‘,‘white‘); subplot(‘2,1,1‘); plot(w/pi, imagIX); grid on; title(‘Imaginary Part of IX(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘); subplot(‘2,1,2‘); plot((m/500), imag(XO)); grid on; title(‘Imaginary Part of XO(w)‘); xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);
运行结果:
1、原始序列及其DTFT
2、序列DTFT进行共轭奇偶对称分解
3、原始序列实部和虚部的DTFT
4、对比结果
序列DTFT的共轭偶对称分量和序列实部的DTFT结果相同;
序列DTFT的共轭奇对称分量和序列虚部的DTFT结果相同;