这段时间爬山去了,山中林密荆棘多,沟谷纵横,体力增强不少。
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf('
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% ------------------------------------------
% 1 x1(n)=5sin(0.1pi*n) n=[0:19], N=40
% ------------------------------------------
L = 20; n = [0:L-1]; N = 40; k = [-N/2:N/2]; % wave parameters
xn_1 = [5*sin(0.1*pi*n), zeros(1, N-L)];
Xk_1 = dfs(xn_1, N); % DFS
magXk = abs( [Xk_1(N/2+1 : N) Xk_1(1 : N/2+1)] ); % DFS magnitude
angXk = angle( [Xk_1(N/2+1 : N) Xk_1(1 : N/2+1)] )/pi; % DFS anglefigure('NumberTitle', 'off', 'Name', 'P5.3 xn_1')
set(gcf,'Color','white');
stem([0:N-1], xn_1);
xlabel('n'); ylabel('x(n)');
title('xn1 sequence, N=40'); grid on;%% ------------------------------------------------------
%% DFS(k) of xn1 sequence
%% ------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'P5.3 DFS(k) of xn_1')
set(gcf,'Color','white');
subplot(2,1,1); stem(k, 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(k, angXk); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('DFS angle of xn1, N=40'); grid on;% ------------------------------------------
% 2 x2(n)=5sin(0.1pi*n) n=[0:19], N=80
% ------------------------------------------
L = 20; n = [0:L-1]; N = 80; k = [-N/2:N/2]; % wave parameters
xn_2 = [5*sin(0.1*pi*n), zeros(1, N-L)];
Xk_2 = dfs(xn_2, N); % DFS
magXk = abs( [Xk_2(N/2+1 : N) Xk_2(1 : N/2+1)] ); % DFS magnitude
angXk = angle([Xk_2(N/2+1 : N) Xk_2(1 : N/2+1)] )/pi; % DFS anglefigure('NumberTitle', 'off', 'Name', 'P5.3 xn_2')
set(gcf,'Color','white');
stem([0:N-1], xn_2);
xlabel('n'); ylabel('x(n)');
title('xn2 sequence, N=80'); grid on;%% ------------------------------------------------------
%% DFS(k) of xn2 sequence
%% ------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'P5.3 DFS(k) of xn_2')
set(gcf,'Color','white');
subplot(2,1,1); stem(k, magXk); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('magnitude(k)');
title('DFS magnitude of xn2, N=80'); grid on;
subplot(2,1,2); stem(k, angXk); %axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('DFS angle of xn2, N=80'); grid on;
运行结果:
这两个序列的基本周期不同,但是二者非零元素值相同。x2(n)相当于在x1的末尾进行补零操作,加了40个零。