《DSP using MATLAB》Problem 5.5-LMLPHP

《DSP using MATLAB》Problem 5.5-LMLPHP

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.5 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ----------------------------------------------
% 1 x1(n)=5sin(0.1pi*n) n=[0:19], N=40
% ----------------------------------------------
L = 20; n = [0:L-1]; N = 40; %k1 = [0 : N-1]; % wave parameters xn_1 = [5*sin(0.1*pi*n), zeros(1, N-L)]; N3 = 2*length(xn_1);
xn_3 = [xn_1 xn_1]; figure('NumberTitle', 'off', 'Name', 'P5.5 xn_1 and xn_3')
set(gcf,'Color','white');
subplot(2,1,1); stem([0:N-1], xn_1);
xlabel('n'); ylabel('x(n)');
title('xn1 sequence in Problem 5.3, N=40'); grid on;
subplot(2,1,2); stem([0:N3-1], xn_3);
xlabel('n'); ylabel('x(n)');
title('xn3 sequence, N=80'); grid on; %% ------------------------------------------------------
%% DFS(k) of xn1 sequence
%% ------------------------------------------------------
k1 = [0 : length(xn_1)-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_1 = dfs(xn_1, N); % DFS
magXk = abs( [ Xk_1 ] ); % DFS magnitude
angXk = angle( [Xk_1] )/pi; % DFS angle figure('NumberTitle', 'off', 'Name', 'P5.5 DFS(k) of xn_1')
set(gcf,'Color','white');
subplot(2,1,1); stem(k1, magXk); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('magnitude(k)');
title('DFS magnitude of xn1, N=40'); grid on;
subplot(2,1,2); stem(k1, angXk); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('DFS angle of xn1, N=40'); grid on; %% ------------------------------------------------------------
%% DFS(k) of xn3 sequence
%% ------------------------------------------------------------
k1 = [0 : N3-1];
%k2 = [-N : N-1];
%k3 = [-N3/2 : N3/2];
Xk_3 = dfs(xn_3, N3);
magXk_3 = abs( [Xk_3]);
angXk_3 = angle( [Xk_3])/pi; figure('NumberTitle', 'off', 'Name', 'P5.5 DFS(k) of xn_3')
set(gcf,'Color','white');
subplot(2,1,1); stem(k1, magXk_3); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('magnitude(k)');
title('DFS magnitude of xn3, N=80'); grid on;
subplot(2,1,2); stem(k1, angXk_3); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('DFS angle of xn3, N=80'); grid on;

  运行结果:

这里假设M=2,即原序列x1重复出现2次得到新序列x3。

《DSP using MATLAB》Problem 5.5-LMLPHP

《DSP using MATLAB》Problem 5.5-LMLPHP

《DSP using MATLAB》Problem 5.5-LMLPHP

《DSP using MATLAB》Problem 5.5-LMLPHP

《DSP using MATLAB》Problem 5.5-LMLPHP

05-08 15:42