首页 > 代码库 > 《DSP using MATLAB》示例Example5.2
《DSP using MATLAB》示例Example5.2
代码:
L = 5; N = 20; k = [-N/2:N/2]; % square wave parameters xn = [ones(1,L), zeros(1,N-L)]; % Sq wave x(n) Xk = dfs(xn,N); % DFS %% ---------------------------------------------------- %% START periodic sequence %% ---------------------------------------------------- self_periods = N; periods = 3; n1 = [-20: -1 + (periods-1) * self_periods]; xtilde = xn‘ * ones(1,periods); xtilde = (xtilde(:))‘; figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example5.2 3 Period Sequence‘) set(gcf,‘Color‘,‘white‘); stem(n1,xtilde); title(‘Three Peroids of xtilde(n)‘);axis([-20, 40, -0.5, 1.5]); xlabel(‘n‘); ylabel(‘xtilde(n)‘);grid on; %% ---------------------------------------------------- %% END periodic sequence %% ---------------------------------------------------- magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); % DFS magnitude figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example5.2‘) set(gcf,‘Color‘,‘white‘); subplot(2,2,1); stem(k, magXk); axis([-N/2, N/2, -0.5, 5.5]); xlabel(‘k‘); ylabel(‘Xtilde(k)‘); grid on; title(‘DFS of SQ. wave: L=5 N=20‘); L = 5; N = 40; k = [-N/2:N/2]; % square wave parameters xn = [ones(1,L), zeros(1,N-L)]; % Sq wave x(n) Xk = dfs(xn,N); % DFS magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); % DFS magnitude %figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example5.2‘) %set(gcf,‘Color‘,‘white‘); subplot(2,2,2); stem(k, magXk); axis([-N/2, N/2, -0.5, 5.5]); xlabel(‘k‘); ylabel(‘Xtilde(k)‘); grid on; title(‘DFS of SQ. wave: L=5 N=40‘); L = 5; N = 60; k = [-N/2:N/2]; % square wave parameters xn = [ones(1,L), zeros(1,N-L)]; % Sq wave x(n) Xk = dfs(xn,N); % DFS magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); % DFS magnitude %figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example5.2‘) %set(gcf,‘Color‘,‘white‘); subplot(2,2,3); stem(k, magXk); axis([-N/2, N/2, -0.5, 5.5]); xlabel(‘k‘); ylabel(‘Xtilde(k)‘); grid on; title(‘DFS of SQ. wave: L=5 N=60‘); L = 7; N = 60; k = [-N/2:N/2]; % square wave parameters xn = [ones(1,L), zeros(1,N-L)]; % Sq wave x(n) Xk = dfs(xn,N); % DFS magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); % DFS magnitude %figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Example5.2‘) %set(gcf,‘Color‘,‘white‘); subplot(2,2,4); stem(k, magXk); axis([-N/2, N/2, -0.5, 7.5]); xlabel(‘k‘); ylabel(‘Xtilde(k)‘); grid on; title(‘DFS of SQ. wave: L=7 N=60‘);
运行结果:
《DSP using MATLAB》示例Example5.2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。