1、 代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.13 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -----------------------------------------------------------------
% 1 x(n) = [1, 2, -3, 4, 5, 1, 2, -3, 4, 5]
% x(n) = x(n+N/2) N=even integer
% ----------------------------------------------------------------- nn1 = [0:9];
xx1 = [1, 2, -3, 4, 5, 1, 2, -3, 4, 5];
NN1 = length(xx1); % length is 10 %m = mod_1(nn1, NN1);
%x = [xx1 zeros(1, 0)]; % padding zeros
%n = [nn1 max(nn1)+1:max(nn1)+6];
x = xx1;
n = nn1; figure('NumberTitle', 'off', 'Name', 'P5.13.1 x(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(nn1, xx1);
xlabel('n'); ylabel('x(n)');
title('x(n) ori sequence'); grid on;
subplot(2,1,2); stem(n, x);
xlabel('n'); ylabel('x(n)');
title('x(n) padding zeros'); grid on; %% =============================================================================
%% DTFT X(w) of xn sequence, w=[0:2pi],
%% =============================================================================
MM = 500;
[Xw_DTFT, w] = dtft1(x, n, MM); magXw_DTFT = abs(Xw_DTFT); angXw_DTFT = angle(Xw_DTFT)/pi;
realXw_DTFT = real(Xw_DTFT); imagXw_DTFT = imag(Xw_DTFT); %% --------------------------------------------------------------
%% START X_DTFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'P5.13.1 X(w) DTFT of x(n)');
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi,magXw_DTFT); grid on; % axis([-2,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |X\_DTFT|');
subplot(2,2,3); plot(w/pi, angXw_DTFT); grid on; % axis([-2,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Rad \pi'); %axis([-200,200,0,2]); subplot('2,2,2'); plot(w/pi, realXw_DTFT); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w/pi, imagXw_DTFT); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DTFT's mag ang real imag
%% -------------------------------------------------------------- %% ------------------------------------------------------------------
%% DFT(k) of xn sequence, k=[0:N-1]
%% w=2pi*k/N k=Nw/(2pi)
%% ------------------------------------------------------------------
N1 = length(x);
k1 = [0 : N1-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_DFT = dft(x, N1); % DFT
magXk_DFT = abs( [ Xk_DFT ] ); % DFT magnitude
angXk_DFT = angle( [Xk_DFT] )/pi; % DFT angle
realXk_DFT = real(Xk_DFT); imagXk_DFT = imag(Xk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.13.1 DFT(k) of x(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(k1, magXk_DFT); hold on; plot(N1*w/(2*pi), magXw_DTFT,'r--'); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('magnitude(k)');
title('DFT magnitude of x(n), N=10'); grid on;
subplot(2,1,2); stem(k1, angXk_DFT); hold on; plot(N1*w/(2*pi), angXw_DTFT,'r--'); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('DFT angle of x(n), N=10'); grid on;

  运行结果:

2、代码

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.13 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -----------------------------------------------------------------
% 2 x(n) = [1, 2, -3, 4, 5, -1, -2, 3, -4, -5]
% x(n) = -x(n + N/2) N=even integer
% ----------------------------------------------------------------- nn1 = [0:9];
xx1 = [1, 2, -3, 4, 5, -1, -2, 3, -4, -5];
NN1 = length(xx1); % length is 10 %m = mod_1(nn1, NN1);
%x = [xx1 zeros(1, 0)]; % padding zeros
%n = [nn1 max(nn1)+1:max(nn1)+6];
x = xx1;
n = nn1; figure('NumberTitle', 'off', 'Name', 'P5.13.2 x(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(nn1, xx1);
xlabel('n'); ylabel('x(n)');
title('x(n) ori sequence'); grid on;
subplot(2,1,2); stem(n, x);
xlabel('n'); ylabel('x(n)');
title('x(n) no padding zeros'); grid on; %% =============================================================================
%% DTFT X(w) of xn sequence, w=[0:2pi],
%% =============================================================================
MM = 500;
[Xw_DTFT, w] = dtft1(x, n, MM); magXw_DTFT = abs(Xw_DTFT); angXw_DTFT = angle(Xw_DTFT)/pi;
realXw_DTFT = real(Xw_DTFT); imagXw_DTFT = imag(Xw_DTFT); %% --------------------------------------------------------------
%% START X_DTFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'P5.13.2 X(w) DTFT of x(n)');
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi,magXw_DTFT); grid on; % axis([-2,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |X\_DTFT|');
subplot(2,2,3); plot(w/pi, angXw_DTFT); grid on; % axis([-2,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Rad \pi'); %axis([-200,200,0,2]); subplot('2,2,2'); plot(w/pi, realXw_DTFT); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w/pi, imagXw_DTFT); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DTFT's mag ang real imag
%% -------------------------------------------------------------- %% ------------------------------------------------------------------
%% DFT(k) of xn sequence, k=[0:N-1]
%% w=2pi*k/N k=Nw/(2pi)
%% ------------------------------------------------------------------
N1 = length(x);
k1 = [0 : N1-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_DFT = dft(x, N1); % DFT
magXk_DFT = abs( [ Xk_DFT ] ); % DFT magnitude
angXk_DFT = angle( [Xk_DFT] )/pi; % DFT angle
realXk_DFT = real(Xk_DFT); imagXk_DFT = imag(Xk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.13.2 DFT(k) of x(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(k1, magXk_DFT); hold on; plot(N1*w/(2*pi), magXw_DTFT,'r--'); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('magnitude(k)');
title('DFT magnitude of x(n), N=10'); grid on;
subplot(2,1,2); stem(k1, angXk_DFT); hold on; plot(N1*w/(2*pi), angXw_DTFT,'r--'); hold off;
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('DFT angle of x(n), N=10'); grid on;

  运行结果:

《DSP using MATLAB》Problem 5.13的更多相关文章

  1. 《DSP using MATLAB》Problem 7.13

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  2. 《DSP using MATLAB》Problem 6.13

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  3. 《DSP using MATLAB》Problem 4.13

    代码: %% ---------------------------------------------------------------------------- %% Output Info a ...

  4. 《DSP using MATLAB》Problem 8.13

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  5. 《DSP using MATLAB》Problem 6.12

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  6. 《DSP using MATLAB》Problem 6.10

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  7. 《DSP using MATLAB》Problem 4.11

    代码: %% ---------------------------------------------------------------------------- %% Output Info a ...

  8. 《DSP using MATLAB》Problem 3.3

    按照题目的意思需要利用DTFT的性质,得到序列的DTFT结果(公式表示),本人数学功底太差,就不写了,直接用 书中的方法计算并画图. 代码: %% -------------------------- ...

  9. 《DSP using MATLAB》Problem 3.1

    先写DTFT子函数: function [X] = dtft(x, n, w) %% --------------------------------------------------------- ...

随机推荐

  1. 图片加载------reactVirtualized

    作用: 让HTML文档始终保持固定数量的图片数量,可以节省带宽

  2. day1-python简介+安装

    Python 简介 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有 ...

  3. servlet之中文乱码:request.getParameter()

    参考: http://blog.csdn.net/u014558484/article/details/53445178

  4. Netty完成网络通信(二)

    Netty是基于NIO的框架,完善了NIO的一些缺陷,因此可以用Netty替代NIO Netty实现通信步骤: 1.创建两个NIO线程组,一个专门用于网络事件处理(接受客户端的连接),另一个则进行网络 ...

  5. 使用AWR报告诊断Oracle性能问题

    在做单交易负载测试时,有的交易响应时间超出了指标值,在排除完测试环境等可能造成交易超时的原因后,去分析数据库问题.数据库用的是Oracle,对于Oracle数据库整体的性能问题, awr的报告是一个非 ...

  6. 在嵌入式设计中使用MicroBlaze(Vivado版本)(转)

    原文Xilinx官方文档<ug898-vivado-embedded-design>第三章 一.MicroBlaze处理器设计介绍(略) 二.创建带有MicroBlaze处理器的IP设计 ...

  7. 理解K系列与ultra-scale的区别

    总结:   K系列FPGA与KU系列FPGA的主要区别,体现在: (1)工艺制程不一样,K-28nm,KU-20nm:   (2)Ultra-Scale采用SSI:大容量K系列也采用SSI,SSI为了 ...

  8. OJ_查找二叉树

    #include<iostream>using namespace std;int n,m;int d[120];int t=1;int re;struct Node{ int data; ...

  9. 使用MyEclipse开发Java EE应用:用XDoclet创建EJB 2 Session Bean项目(二)

    [MyEclipse最新版下载] 二.创建一个Session EJB – Part 1 MyEclipse中的EJB 2.x开发使用了EJB向导和集成XDoclet支持的组合. 每个EJB由三个基本部 ...

  10. openstack网络DVR

    一.DVR描述 分布式路由 二.相关的专业术语 术语名称 术语解释 SNAT 在路由器后(POSTROUTING)将内网的ip地址修改为外网网卡的ip地址,也就是绑定浮动IP和外部通信 DNAT 在路 ...