《DSP using MATLAB》Problem 5.21

证明:

代码:

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

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

% ---------------------------------------------------------------------------------
%
%         Parseval relation
%           sum[abs(x(n))^2] = sum[abs(X(k))^2]/N
%
% ---------------------------------------------------------------------------------
 n = [0:10];
 x = [5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4];             % N=11 sequence
 N = length(x);

Exn = sum(abs(x).^2)

m1 = -5; N1 = 12;
n1 = [0:N1-1];

m2 = 8; N2 = 15;
n2 = [0:N2-1];

% -----------------------------------------------------
%     1st way to get circular shift---time domain
% -----------------------------------------------------
y1_1 = cirshftt(x, m1, N1);
y2_1 = cirshftt(x, m2, N2);

% --------------------------------------------------------
%     2rd way to get circular shift --- freq domain
% --------------------------------------------------------
y1_2 = cirshftf(x, m1, N1);
y2_2 = cirshftf(x, m2, N2);

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.21.a x(n) and its cir shift‘)
set(gcf,‘Color‘,‘white‘);
subplot(3,1,1); stem(n, x);
xlabel(‘n‘); ylabel(‘x(n)‘);
title(‘x(n), N=11‘);  grid on;
subplot(3,1,2); stem(n1, y1_1);
xlabel(‘n‘); ylabel(‘y(n)‘);
title(‘TIME domain circular shift x(n), m=-5, N=12‘);  grid on;
subplot(3,1,3); stem(n1, y1_2);
xlabel(‘n‘); ylabel(‘y(n)‘);
title(‘FREQ domain circular shift x(n), m=-5, N=12‘);  grid on;
axis([0, N1, 0, 6]);

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.21.b x(n) and its cir shift‘)
set(gcf,‘Color‘,‘white‘);
subplot(3,1,1); stem(n, x);
xlabel(‘n‘); ylabel(‘x(n)‘);
title(‘x(n), N=11‘);  grid on;
subplot(3,1,2); stem(n2, y2_1);
xlabel(‘n‘); ylabel(‘y(n)‘);
title(‘TIME domain circular shift x(n), m=8, N=15‘);  grid on;
subplot(3,1,3); stem(n2, y2_2);
xlabel(‘n‘); ylabel(‘y(n)‘);
title(‘FREQ domain circular shift x(n), m=8, N=15‘);  grid on;
axis([0, N2-1, 0, 6]);

% ----------------------------------------------------
%        DFT of sequence
% ----------------------------------------------------

  Xk_DFT = dft(x, N);
  k = n;

    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(magXk_DFT .^ 2)/N

 Y11k_DFT = dft(y1_1, N1);
 k1 = n1;

    magY11k_DFT = abs( [ Y11k_DFT ] );                                    % DFT magnitude
    angY11k_DFT = angle( [Y11k_DFT] )/pi;                                 % DFT angle
   realY11k_DFT = real(Y11k_DFT);
   imagY11k_DFT = imag(Y11k_DFT);

   EY11k = sum(magY11k_DFT.^2)/N1

Y21k_DFT = dft(y2_1, N2);
 k2 = n2;

    magY21k_DFT = abs( [ Y21k_DFT ] );                                    % DFT magnitude
    angY21k_DFT = angle( [Y21k_DFT] )/pi;                                 % DFT angle
   realY21k_DFT = real(Y21k_DFT);
   imagY21k_DFT = imag(Y21k_DFT);

   EY21k = sum(magY21k_DFT.^2)/N2

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.21 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=11‘);  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=11‘);  grid on;
subplot(2,2,2); stem(k, realXk_DFT);
xlabel(‘k‘); ylabel(‘real (k)‘);
title(‘real DFT of x(n), N=11‘);  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=11‘);  grid on;   

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.21 Y11(k), DFT of x((n+5))12‘)
set(gcf,‘Color‘,‘white‘);
subplot(2,2,1); stem(k1, magY11k_DFT);
xlabel(‘k‘); ylabel(‘magnitude(k)‘);
title(‘magnitude DFT of y11(n), N=12‘);  grid on;
subplot(2,2,3); stem(k1, angY11k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘angle(k)‘);
title(‘angle DFT of y11(n), N=12‘);  grid on;
subplot(2,2,2); stem(k1, realY11k_DFT);
xlabel(‘k‘); ylabel(‘real (k)‘);
title(‘real DFT of y11(n), N=12‘);  grid on;
subplot(2,2,4); stem(k1, imagY11k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘imag (k)‘);
title(‘imag DFT of y11(n), N=12‘);  grid on;   

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.21 Y21(k), DFT of x((n-8))15‘)
set(gcf,‘Color‘,‘white‘);
subplot(2,2,1); stem(k2, magY21k_DFT);
xlabel(‘k‘); ylabel(‘magnitude(k)‘);
title(‘magnitude DFT of y21(n), N=15‘);  grid on;
subplot(2,2,3); stem(k2, angY21k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘angle(k)‘);
title(‘angle DFT of y21(n), N=15‘);  grid on;
subplot(2,2,2); stem(k2, realY21k_DFT);
xlabel(‘k‘); ylabel(‘real (k)‘);
title(‘real DFT of y21(n), N=15‘);  grid on;
subplot(2,2,4); stem(k2, imagY21k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel(‘k‘); ylabel(‘imag (k)‘);
title(‘imag DFT of y21(n), N=15‘);  grid on;

  运行结果:

序列的圆周移位

原始序列x(n)的DFT

圆周移位序列1的DFT

圆周移位序列2的DFT

上图可知,时域的能量和频域的能量相等。

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

时间: 2024-09-30 07:21:15

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

《DSP using MATLAB》Problem 4.21

快到龙抬头,居然下雪了,天空飘起了雪花,温度下降了近20°. 代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB>

《DSP using MATLAB》Problem 6.21

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

《DSP using MATLAB》Problem 3.21

模拟信号经过不同的采样率进行采样后,得到不同的数字角频率,如下: 三种Fs,采样后的信号的谱 重建模拟信号,这里只显示由第1种Fs=0.01采样后序列进行重建,采用zoh.foh和spline三种方法: 原文地址:https://www.cnblogs.com/ky027wh-sx/p/8271297.html

《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.14

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

用Kaiser窗方法设计一个台阶状滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> P

《DSP using MATLAB》Problem 7.28

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

《DSP using MATLAB》Problem 7.36

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