1. 程式人生 > >《DSP using MATLAB》Problem 3.8

《DSP using MATLAB》Problem 3.8

pos eve title plot seq hit 對稱 相同 unit

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結果相同;

技術分享圖片

《DSP using MATLAB》Problem 3.8