代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.8 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------------
% 1 x(n) = sinc^2[(n-50)/2] n=[0:100]
% = 0 else
% -------------------------------------------------------
N = 101; n = [0 : N-1];
x = sinc((n-50)/2) .* sinc((n-50)/2); % sequence
x1 = [x, zeros(1,20)]; % padding zeros
n1 = [0 : length(x1)-1]; figure('NumberTitle', 'off', 'Name', 'P5.8 x(n) and x1(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(n, x);
xlabel('n'); ylabel('x(n)');
title('x(n) sequence'); grid on;
subplot(2,1,2); stem(n1, x1);
xlabel('n'); ylabel('x1(n)');
title('x1(n) sequence'); 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.8 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], N=101
%% w=2pi*k/N k=Nw/(2pi)
%% ------------------------------------------------------------------
k1 = [0 : length(x)-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_DFT = dft(x, N); % 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.8 DFT(k) of x(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(k1, magXk_DFT); hold on; plot(N*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=101'); grid on;
subplot(2,1,2); stem(k1, angXk_DFT); hold on; plot(N*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=101'); grid on;

  运行结果:

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

  1. 《DSP using MATLAB》Problem 7.27

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

  2. 《DSP using MATLAB》Problem 7.26

    注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...

  3. 《DSP using MATLAB》Problem 7.25

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

  4. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

  5. 《DSP using MATLAB》Problem 7.23

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...

  6. 《DSP using MATLAB》Problem 7.16

    使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  7. 《DSP using MATLAB》Problem 7.15

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

  8. 《DSP using MATLAB》Problem 7.14

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

  9. 《DSP using MATLAB》Problem 7.13

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

  10. 《DSP using MATLAB》Problem 7.12

    阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. UVa 11039 - Building designing 贪心,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  2. UVA 11990 `Dynamic'' Inversion CDQ分治, 归并排序, 树状数组, 尺取法, 三偏序统计 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. bzoj4698

    题解: 后缀数组 对所有序列差分一下 公共串的长度+1就是答案了 二分 扫一遍height即可,.. 代码: #include <bits/stdc++.h> using namespac ...

  4. Cracking The Coding Interview 4.1

    //Implement a function to check if a tree is balanced. For the purposes of this question, a balanced ...

  5. 无法获取 vmci 驱动程序版本: 句柄无效

    https://jingyan.baidu.com/article/a3a3f811ea5d2a8da2eb8aa1.html 将 vmci0.present = "TURE" 改 ...

  6. Android开发 ---xml布局元素

    1.android:orientation="vertical/horizontal" vertical为垂直布局, horizontal为水平布局 2.android:layou ...

  7. Redis部署与基本操作

    1.安装 1)不指定安装位置,则会把redis的可执行文件安装到  redis-2.8.6/src/目录下 [root@CentOS6 ~]# ls anaconda-ks.cfg  httpd-2. ...

  8. 二、先在SD卡上启动U-boot,再烧写新的U-boot进Nandflash

    1. 制作SD卡 先准备一张2G的SD卡(不能用8G的,2G的卡和8G的卡协议不一样),和烧写SD卡的工具write_sd以及需要烧写到SD卡中的u-boot-movi.bin.将SD卡格式化后连接到 ...

  9. this 指向问题, 三个例子

    'use strict'; var a = 20; function foo () { var a = 1; var obj = { a: 10, c: this.a + 20, fn: functi ...

  10. C# 创建 写入 读取 excel

    public static void CreateExcelFile(string FileName, List<UUser> luu) { ] == "xlsx")/ ...