代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.9 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------------
% 1 x(n) = 2*exp(-0.9*n) n=[0:5]
% = 2*exp(0.9*(11-n)) n=[6:10]
% = 0 else
% -------------------------------------------------------
N = 11;
nn1 = [-5:5];
xx1 = 2*exp(-0.9*abs(nn1)); figure('NumberTitle', 'off', 'Name', 'P5.9 x(n)')
set(gcf,'Color','white');
%subplot(2,1,1);
stem(nn1, xx1);
xlabel('n'); ylabel('x(n)');
title('x(n) sequence'); grid on; n1 = [0 : 5]; n2 = [6:N-1];
x1 = 2*exp(-0.9*n1); x2 = 2*exp(-0.9*(11-n2));
x = [x1 x2 ]; % sequence
n = [n1 n2];
x3 = [x, zeros(1,9)]; % padding 9 zeros
n3 = [0 : length(x3)-1]; figure('NumberTitle', 'off', 'Name', 'P5.9 x(n) and x3(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(n3, x3);
xlabel('n'); ylabel('x1(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.9 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(x3);
k1 = [0 : N1-1];
%k2 = [-N : N-1];
%k3 = [-N/2 : N/2];
Xk_DFT = dft(x3, 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.9 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=20'); 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=20'); grid on;

  运行结果:

原始序列的n定义在-5到5,有负数的域。而N点序列的DFT定义在[0, N-1]中,所以需要将n进行周期N延拓,再取主值区间。

这里在序列后补零9个,增加频率域采样点数。

下图中,序列的DTFT(红色虚线)和DFT(蓝色棒状图)。

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

  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. nginx:在linux上进行nginx的安装

    -----1.安装 换源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 下载: wget ...

  2. 【转】Java迭代:Iterator和Iterable接口

    Java迭代 : Iterator和Iterable接口 从英文意思去理解 Iterable :故名思议,实现了这个接口的集合对象支持迭代,是可迭代的.able结尾的表示 能...样,可以做.... ...

  3. QuickHit 项目

    package cn.javaoppday01; import java.util.Random; public class Game { public Player player; public G ...

  4. SAL-9 获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'

    题目描述 获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'CREATE TABLE `dept_man ...

  5. 补偿接口中循环一直执行sql的问题

    事件: 项目即将上线,测试,观察日志,发现一sql在dal.xml中一直刷日志,但对应在biz日志却是空的 排查步骤: 1.查看对应日志的sql,在项目中找到对应代码所在位置,查看入口与代码逻辑 接口 ...

  6. 更改centos源为aliyun

    完全参考 http://mirrors.aliyun.com/help/centos?spm=5176.bbsr150321.0.0.d6ykiD 1.备份 mv /etc/yum.repos.d/C ...

  7. countdownlatch 和 CyclicBarrier 和 Semaphore

    cdl用的是aqs,共享的是aqs那个volatile的state,阻塞线程列表用的也是aqs的 cb用的是reentrantlock+condition,当然rel用的也是aqs不过不同的是用的是互 ...

  8. Oracle数据库三种备份方案

    Oracle数据库有三种标准的备份方法,它们分别是导出/导入(EXP/IMP).热备份和冷备份.导出备件是一种逻辑备份,冷备份和热备份是物理备份. 一. 导出/导入(Export/Import) 利用 ...

  9. LeetCode子集问题

    给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(子集当中不包括重复的元素) 代码如下: def subsets(nums): target=[[]] for num in nums ...

  10. shell脚本实例-内存磁盘使用警告

    1,磁盘使用警告并发送邮件 #!usr/bin/bash #df -Th|grep '/$' 这个是获取内存使用的那一条记录 #后面两句是获取内存的使用率 disk=`df -Th|grep '/$' ...