《DSP using MATLAB》Problem 5.6

频率采样定理是这样的:

        由上述定理可知,一个有限长序列(假设为N)的DTFT等间隔采样,采样数至少大于等于N。

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%%            Output Info about this m-file
fprintf('
***********************************************************
');
fprintf('        <DSP using MATLAB> Problem 5.6 

');

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

% --------------------------------------------------
%        1  x(n) = n + 1    n=[ 0:49]
%                = 100-n    n=[50:99]
%                = 0        otherwise
% --------------------------------------------------
L = 50; n = [0:L-1]; N = 100; %k1 = [0 : N-1];             % wave parameters

xn_1 = [n+1, 100-(n+50)];                                  % length 100
xn_2 = [xn_1, zeros(1,100)];                               % padding 100 zeros

figure('NumberTitle', 'off', 'Name', 'P5.6 xn_1 and xn_2')
set(gcf,'Color','white'); 
subplot(2,1,1); stem([0:N-1], xn_1);
xlabel('n'); ylabel('x(n)');
title('xn1 sequence');  grid on;
subplot(2,1,2); stem([0:length(xn_2)-1], xn_2);
xlabel('n'); ylabel('x(n)');
title('xn2 sequence');  grid on;


% -------------------------------------------------------------
%                        X(jw), DTFT of x(n)
% -------------------------------------------------------------
MM1 = 500;
%k = [-MM : MM];        % [-pi, pi]
%k = [0:MM];             % [0, pi]
%w = (2*pi/MM) * k;

[X1, w1] = dtft1(xn_1, [0:N-1], MM1);  
                         
%[X] = dtft(xn_1, [0:N-1], w);

magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1);

figure('NumberTitle', 'off', 'Name', 'Problem 5.6 DTFT X(jw) of x(n)'); 
set(gcf,'Color','white');
subplot(2,1,1); plot(w1/pi, magX1); grid on; 
title('Magnitude Part');
xlabel('frequency in pi units'); ylabel('Magnitude'); 
subplot(2,1,2); plot(w1/pi, angX1); grid on;
title('Angle Part');
xlabel('frequency in pi units'); ylabel('Phase');

figure('NumberTitle', 'off', 'Name', 'Problem 5.6 Real and Imag of X(jw)'); 
set(gcf,'Color','white');
subplot('2,1,1'); plot(w1/pi, realX1); grid on;
title('Real Part');
xlabel('frequency in pi units'); ylabel('Real');
subplot('2,1,2'); plot(w1/pi, imagX1); grid on;
title('Imaginary Part');
xlabel('frequency in pi units'); ylabel('Imaginary');

%% -----------------------------------------------------------------------
%%        10-point frequency sample of X(w), DTFT of xn1 sequence
%%        then IDFS to get y1(n)
%% -----------------------------------------------------------------------
y1 = real( idfs( X1(1:100:1000), 10) );

figure('NumberTitle', 'off', 'Name', 'Problem 5.6 10-point IDFS X(jw)'); 
set(gcf,'Color','white');
%subplot(2,1,1); 
stem([0:9], y1); grid on; 
title('y1(n)');
xlabel('n'); ylabel('y1'); 


%% -----------------------------------------------------------------------
%%        200-point frequency sample of X(w), DTFT of xn1 sequence
%%        then IDFS to get y2(n)
%% -----------------------------------------------------------------------
y2 = real( idfs(X1(1:5:1000), 200) );
figure('NumberTitle', 'off', 'Name', 'Problem 5.6 200-point IDFS X(jw)'); 
set(gcf,'Color','white');
%subplot(2,1,1); 
stem([0:199], y2); grid on; 
title('y2(n)');
xlabel('n'); ylabel('y2'); 


%% -----------------------------------------------------------------------
%%        100-point frequency sample of X(w), DTFT of xn1 sequence
%%        then IDFS to get y3(n)
%% -----------------------------------------------------------------------
y3 = real( idfs(X1(1:10:1000), 100) );
figure('NumberTitle', 'off', 'Name', 'Problem 5.6 100-point IDFS X(jw)'); 
set(gcf,'Color','white');
%subplot(2,1,1); 
stem([0:99], y3); grid on; 
title('y3(n)');
xlabel('n'); ylabel('y3'); 

  运行结果:

        原始序列,长度为N=200,但是只有前100个元素不为零,可以看成长度为100的序列末尾补了100个零。

        [-2π,2π]范围内的DTFT

          [0,2π]范围内的DTFT

          DTFT进行10等分采样,然后IDFS变换得到序列y1

          DTFT进行200等分采样,然后IDFS变换得到序列y2

           DTFT进行100等分采样,然后IDFS变换得到序列y3

          由上图可知,y3(100等分DTFT再逆变换)与原始序列的非零部分相同,y2(200等分DTFT再逆变换)与原始序列完全相同,y1有畸变。

牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
原文地址:https://www.cnblogs.com/ky027wh-sx/p/9308456.html