《DSP using MATLAB》Problem 5.13

1、 代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> Problem 5.13 \n\n‘);

banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

% -----------------------------------------------------------------
%              1  x(n) = [1, 2, -3, 4, 5, 1, 2, -3, 4, 5]
%                   x(n) = x(n+N/2)  N=even integer
% -----------------------------------------------------------------

nn1 = [0:9];
xx1 = [1, 2, -3, 4, 5, 1, 2, -3, 4, 5];
NN1 = length(xx1);                                % length is 10

%m = mod_1(nn1, NN1);
%x = [xx1 zeros(1, 0)];                        % padding zeros
%n = [nn1 max(nn1)+1:max(nn1)+6];
x = xx1;
n = nn1;

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.13.1 x(n)‘)
set(gcf,‘Color‘,‘white‘);
subplot(2,1,1); stem(nn1, xx1);
xlabel(‘n‘); ylabel(‘x(n)‘);
title(‘x(n) ori sequence‘);  grid on;
subplot(2,1,2); stem(n, x);
xlabel(‘n‘); ylabel(‘x(n)‘);
title(‘x(n) padding zeros‘);  grid on;

%% =============================================================================
%%                 DTFT X(w) of xn sequence, w=[0:2pi],
%% =============================================================================
MM = 500;
[Xw_DTFT, w] = dtft1(x, n, MM);

 magXw_DTFT = abs(Xw_DTFT);   angXw_DTFT = angle(Xw_DTFT)/pi;
realXw_DTFT = real(Xw_DTFT); imagXw_DTFT = imag(Xw_DTFT);

%% --------------------------------------------------------------
%%        START X_DTFT‘s  mag ang real imag
%% --------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.13.1 X(w) DTFT of x(n)‘);
set(gcf,‘Color‘,‘white‘);
subplot(2,2,1); plot(w/pi,magXw_DTFT); grid on;  % axis([-2,2,0,15]);
title(‘Magnitude Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude  |X\_DTFT|‘);
subplot(2,2,3); plot(w/pi, angXw_DTFT); grid on;  % axis([-2,2,-1,1]);
title(‘Angle Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Rad \pi‘); %axis([-200,200,0,2]);

subplot(‘2,2,2‘); plot(w/pi, realXw_DTFT); grid on;
title(‘Real Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Real‘);
subplot(‘2,2,4‘); plot(w/pi, imagXw_DTFT); grid on;
title(‘Imaginary Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);
%% --------------------------------------------------------------
%%        END X_DTFT‘s  mag ang real imag
%% --------------------------------------------------------------

%% ------------------------------------------------------------------
%%                 DFT(k) of xn sequence, k=[0:N-1]
%%                      w=2pi*k/N       k=Nw/(2pi)
%% ------------------------------------------------------------------
N1 = length(x);
k1 = [0 : N1-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_DFT = dft(x, N1);                                         % 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);

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.13.1 DFT(k) of x(n)‘)
set(gcf,‘Color‘,‘white‘);
subplot(2,1,1); stem(k1, magXk_DFT); hold on; plot(N1*w/(2*pi), magXw_DTFT,‘r--‘); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘magnitude(k)‘);
title(‘DFT magnitude of x(n), N=10‘);  grid on;
subplot(2,1,2); stem(k1, angXk_DFT);  hold on; plot(N1*w/(2*pi), angXw_DTFT,‘r--‘); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘angle(k)‘);
title(‘DFT angle of x(n), N=10‘);  grid on;

  运行结果:

2、代码

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> Problem 5.13 \n\n‘);

banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

% -----------------------------------------------------------------
%              2  x(n) = [1, 2, -3, 4, 5, -1, -2, 3, -4, -5]
%                       x(n) = -x(n + N/2)   N=even integer
% -----------------------------------------------------------------

nn1 = [0:9];
xx1 = [1, 2, -3, 4, 5, -1, -2, 3, -4, -5];
NN1 = length(xx1);                                % length is 10

%m = mod_1(nn1, NN1);
%x = [xx1 zeros(1, 0)];                        % padding zeros
%n = [nn1 max(nn1)+1:max(nn1)+6];
x = xx1;
n = nn1;

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.13.2 x(n)‘)
set(gcf,‘Color‘,‘white‘);
subplot(2,1,1); stem(nn1, xx1);
xlabel(‘n‘); ylabel(‘x(n)‘);
title(‘x(n) ori sequence‘);  grid on;
subplot(2,1,2); stem(n, x);
xlabel(‘n‘); ylabel(‘x(n)‘);
title(‘x(n) no padding zeros‘);  grid on;

%% =============================================================================
%%                 DTFT X(w) of xn sequence, w=[0:2pi],
%% =============================================================================
MM = 500;
[Xw_DTFT, w] = dtft1(x, n, MM);

 magXw_DTFT = abs(Xw_DTFT);   angXw_DTFT = angle(Xw_DTFT)/pi;
realXw_DTFT = real(Xw_DTFT); imagXw_DTFT = imag(Xw_DTFT);

%% --------------------------------------------------------------
%%        START X_DTFT‘s  mag ang real imag
%% --------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.13.2 X(w) DTFT of x(n)‘);
set(gcf,‘Color‘,‘white‘);
subplot(2,2,1); plot(w/pi,magXw_DTFT); grid on;  % axis([-2,2,0,15]);
title(‘Magnitude Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude  |X\_DTFT|‘);
subplot(2,2,3); plot(w/pi, angXw_DTFT); grid on;  % axis([-2,2,-1,1]);
title(‘Angle Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Rad \pi‘); %axis([-200,200,0,2]);

subplot(‘2,2,2‘); plot(w/pi, realXw_DTFT); grid on;
title(‘Real Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Real‘);
subplot(‘2,2,4‘); plot(w/pi, imagXw_DTFT); grid on;
title(‘Imaginary Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);
%% --------------------------------------------------------------
%%        END X_DTFT‘s  mag ang real imag
%% --------------------------------------------------------------

%% ------------------------------------------------------------------
%%                 DFT(k) of xn sequence, k=[0:N-1]
%%                      w=2pi*k/N       k=Nw/(2pi)
%% ------------------------------------------------------------------
N1 = length(x);
k1 = [0 : N1-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_DFT = dft(x, N1);                                         % 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);

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.13.2 DFT(k) of x(n)‘)
set(gcf,‘Color‘,‘white‘);
subplot(2,1,1); stem(k1, magXk_DFT); hold on; plot(N1*w/(2*pi), magXw_DTFT,‘r--‘); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘magnitude(k)‘);
title(‘DFT magnitude of x(n), N=10‘);  grid on;
subplot(2,1,2); stem(k1, angXk_DFT);  hold on; plot(N1*w/(2*pi), angXw_DTFT,‘r--‘); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘angle(k)‘);
title(‘DFT angle of x(n), N=10‘);  grid on;

  运行结果:

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

时间: 2024-11-12 02:00:24

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

《DSP using MATLAB》Problem 4.13

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

《DSP using MATLAB》Problem 8.13

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 8.13 \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,

《DSP using MATLAB》Problem 4.11

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

《DSP using MATLAB》Problem 6.12

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

《DSP using MATLAB》Problem 7.28

又是一年五一节,朋友圈都是晒名山大川的,晒脑袋的,我这没钱的待在家里上网转转吧 频率采样法设计带通滤波器,过渡带中有一个样点 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf('\n*******************************************************

《DSP using MATLAB》Problem 9.4

只放第1小题. 代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 9.4.1 \n\n'); b

《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