代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.15 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ------------------------------------------------------------------------
% 1 x(n) = [1, -2, 3, 1,-2,3, 1, -2, 3, 1, -2, 3,1,-2,3,1,-2,3]
% N=18 N=2uv
% x(n) = x(n+v)
% ------------------------------------------------------------------------ nn1 = [0:17];
xx1 = [1, -2, 3, 1, -2, 3, 1, -2, 3, 1, -2, 3, 1, -2, 3, 1, -2, 3];
NN1 = length(xx1); % length is 18 %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.15.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 0 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.15.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.15.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=18'); 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=18'); grid on;

  运行结果:

第2小题:

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

  1. 《DSP using MATLAB》Problem 7.15

    用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  2. 《DSP using MATLAB》Problem 6.15

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

  3. 《DSP using MATLAB》Problem 4.15

    只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...

  4. 《DSP using MATLAB》Problem 2.15

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

  5. 《DSP using MATLAB》Problem 8.15

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

  6. 《DSP using MATLAB》Problem 5.38

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

  7. 《DSP using MATLAB》Problem 5.31

    第3小题: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Out ...

  8. 《DSP using MATLAB》Problem 5.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...

  9. 《DSP using MATLAB》Problem 5.21

    证明: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. django+xadmin+djcelery实现后台管理定时任务

    继上一篇中间表的数据是动态的,图表展示的数据才比较准确.这里用到一个新的模块Djcelery,安装配置步骤如下: 1.安装 redis==2.10.6 celery==3.1.23 django-ce ...

  2. day31-python阶段性复习五

    打印目录下所有文件 os 模块 os.listdir(‘/home’) 列出目录下所有文件 os.path.isdir(‘/home’) 判断一个文件是不是一个目录 os.path.isfile(‘/ ...

  3. Docker使用jenkins部署java项目到远程linux(三)

    实现功能:从本地提交代码到gogs上,本地的代码会被检测一遍 如果检测通过才能commit成功 然后可以继续执行push命令 .push后在gogs上使用web钩子自动推送到jenkins触发构建,j ...

  4. Mybatis的二级缓存注意点

    --声明:一下内容都不一定是正确的,只是自己测试的结果,请自己的动手操作得出自己的结论 1.开启Mybatis的二级缓存,不仅要在SqlMapConfig.xml中进行开启总开关,还要在对应的XXXM ...

  5. angular4-常用指令

    ngIf 指令(它与 AngularJS 1.x 中的 ng-if 指令的功能是等价) <div *ngIf="condition">...</div> n ...

  6. ubuntu查看占用某端口的程序

    查看端口使用情况,使用netstat命令. 查看已经连接的服务端口(ESTABLISHED netstat -a 查看所有的服务端口(LISTEN,ESTABLISHED) netstat -ap 查 ...

  7. 九. Python基础(9)--命名空间, 作用域

    九. Python基础(9)--命名空间, 作用域 1 ● !a 与 not a 注意, C/C++可以用if !a表示if a == 0, 但是Python中只能用if not a来表示同样的意义. ...

  8. :迭代器模式1:Iterator

    //今天一口气把这一章前半部分的iterator例子的所有代码写完,涉及到了不少指针的内容,竟然一次性编译通过.... //Iterator与Menu之间应该不是has a的关系,先这样着吧. #if ...

  9. StringUtils详细介绍

    StringUtils详细介绍 public static void TestStr(){ #null 和 "" 操作~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  10. windows剪贴板

    0x01  Windows剪贴板 Windows剪贴板是一种比较简单同时也是开销比较小的IPC(InterProcess Communication,进程间通讯)机制.Windows系统支持剪贴板IP ...