《DSP using MATLAB》Problem 3.8

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

原文地址:https://www.cnblogs.com/ky027wh-sx/p/8167275.html

时间: 2024-10-02 00:10:26

《DSP using MATLAB》Problem 3.8的相关文章

《DSP using MATLAB》 Problem 2.3

本题主要是显示周期序列的. 1.代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.3.1 \

《DSP using MATLAB》Problem 2.5

2.代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.5.2 \n\n'); time_st

《DSP using MATLAB》Problem 2.6

1.代码 %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.6.1 \n\n'); [v, d] =

《DSP using MATLAB》Problem 2.8

1.代码: 从MATLAB官方网上下载的. %*************************************************************************% %A code for the Downsampler% %Author: Yashwant Marathe% %Date:20-12-2010% function [y ny] = dnsample(x,n,M) %x is a sequence over indices specified by v

《DSP using MATLAB》Problem 2.14

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.14 \n\n'); banner();

《DSP using MATLAB》Problem 2.16

先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Prob

《DSP using MATLAB》Problem 2.15

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.15 \n\n'); banner();

《DSP using MATLAB》Problem 2.19

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.19 \n\n'); banner();

《DSP using MATLAB》Problem 2.20

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.20 \n\n'); banner();

《DSP using MATLAB》Problem 3.1

先写DTFT子函数: function [X] = dtft(x, n, w) %% ------------------------------------------------------------------------ %% Computes DTFT (Discrete-Time Fourier Transform) %% of Finite-Duration Sequence %% Note: NOT the most elegant way % [X] = dtft(x, n,