代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 5.7 '); banner(); %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------- % 1 x(n) = [ 2,4,6,1,3,5 ] N--period % | % -------------------------------------------------- x = [2, 4, 6, 1, 3, 5]; N = 6; n = [0 : N-1]; % periodic sequence with period N y = x( mod(-n, N)+1 ); % circular fold figure('NumberTitle', 'off', 'Name', 'P5.7 x(n) and x(-n)') set(gcf,'Color','white'); subplot(2,1,1); stem(n, x); xlabel('n'); ylabel('x(n)'); title('$ ilde x(n) sequence, period N=6$', 'interpreter', 'latex', 'fontsize', 14); grid on; subplot(2,1,2); stem(n, y); xlabel('n'); ylabel('y(n)'); title('x(-n) sequence'); grid on; %% ------------------------------------------------------------------ %% DFS(k) of xn sequence, k=[0:N-1], N=6 %% ------------------------------------------------------------------ k1 = [0 : length(x)-1]; %k2 = [-N : N-1]; %k3 = [-N/2 : N/2]; Xk_1 = dfs(x, N); % DFS magXk = abs( [ Xk_1 ] ); % DFS magnitude angXk = angle( [Xk_1] )/pi; % DFS angle figure('NumberTitle', 'off', 'Name', 'P5.7 DFS(k) of x(n)') 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 x(n), N=6'); 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 x(n), N=6'); grid on; %% ------------------------------------------------------------------ %% DFS(k) of yn sequence, k=[0:N-1], N=6 %% ------------------------------------------------------------------ k1 = [0 : length(y)-1]; %k2 = [-N : N-1]; %k3 = [-N/2 : N/2]; Yk_1 = dfs(y, N); % DFS magYk = abs( [ Yk_1 ] ); % DFS magnitude angYk = angle( [Yk_1] )/pi; % DFS angle figure('NumberTitle', 'off', 'Name', 'P5.7 DFS(k) of y(n)') set(gcf,'Color','white'); subplot(2,1,1); stem(k1, magYk); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('magnitude(k)'); title('DFS magnitude of y(n), N=6'); grid on; subplot(2,1,2); stem(k1, angYk); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('angle(k)'); title('DFS angle of y(n), N=6'); grid on;
运行结果:
周期序列及其圆周折叠序列:
原始序列的DFS系数
圆周折叠序列的DFS系数