《DSP using MATLAB》Problem 9.2
前几天看了看博客,从16年底到现在,3年了,终于看书到第9章了。都怪自己愚钝不堪,唯有吃苦努力,一点一点一页一页慢慢啃了。

代码:
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 9.2 \n\n'); banner();
%% ------------------------------------------------------------------------ % ------------------------------------------------------------
% PART 1
% ------------------------------------------------------------ % Discrete time signal n1_start = 0; n1_end = 60;
n1 = [n1_start:1:n1_end]; xn1 = (0.9).^n1 .* stepseq(0, n1_start, n1_end); % digital signal D = 2; % downsample by factor D
y = downsample(xn1, D);
ny = [n1_start:n1_end/D]; figure('NumberTitle', 'off', 'Name', 'Problem 9.2 xn1 and y')
set(gcf,'Color','white');
subplot(2,1,1); stem(n1, xn1, 'b');
xlabel('n'); ylabel('x(n)');
title('xn1 original sequence'); grid on;
subplot(2,1,2); stem(ny, y, 'r');
xlabel('ny'); ylabel('y(n)');
title('y sequence, downsample by D=2 '); grid on; % ----------------------------
% DTFT of xn1
% ----------------------------
M = 500;
[X1, w] = dtft1(xn1, n1, M); magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1); %% --------------------------------------------------------------------
%% START X(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 9.2 X1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('digital frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 9.2 X1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realX1); grid on;
title('Real Part');
xlabel('digital frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagX1); grid on;
title('Imaginary Part');
xlabel('digital frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- % ----------------------------
% DTFT of y
% ----------------------------
M = 500;
[Y, w] = dtft1(y, ny, M); magY_DTFT = abs(Y); angY_DTFT = angle(Y); realY_DTFT = real(Y); imagY_DTFT = imag(Y); %% --------------------------------------------------------------------
%% START Y(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 9.2 Y DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magY_DTFT); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angY_DTFT/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('digital frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 9.2 Y DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realY_DTFT); grid on;
title('Real Part');
xlabel('digital frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagY_DTFT); grid on;
title('Imaginary Part');
xlabel('digital frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END Y's mag ang real imag
%% ------------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 9.2 X1 & Y, DTFT of x and y');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
hold on;
plot(w/pi, magY_DTFT, 'r'); gtext('magY(\omega)', 'Color', 'r');
hold off; subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('digital frequency in \pi units'); ylabel('Radians/\pi');
hold on;
plot(w/pi, angY_DTFT/pi, 'r'); gtext('AngY(\omega)', 'Color', 'r');
hold off;
运行结果:
原始序列x和按D=2抽取后序列y,如下

原始序列x的DTFT,这里只放幅度谱和相位谱,DTFT的实部和虚部的图不放了(代码中有计算)。

抽取后序列y的DTFT如下图,也是幅度谱和相位谱,实部和虚部的图不放了(代码中有计算)。

将上述两张图叠合到一起做对比,红色曲线是抽取后序列的DTFT,蓝色曲线是原始序列的DTFT。
可见,红色曲线的幅度近似为蓝色曲线的二分之一(1/D,这里D=2)。

《DSP using MATLAB》Problem 9.2的更多相关文章
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.25
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.23
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.15
用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.14
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.13
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.12
阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- python 出现indentationError:expected an indented block!
出现这个问题,代码一般是没问题的,剩下你要考虑: 1. 缩进对齐是否有问题 2. python脚本的格式是啥,如果你在linux上运行,编码需要是unix; (大部分情况下,我们是在windows下 ...
- jQuery 对象与 Dom 对象转化
首先,我们需要知道,为什么我们需要转化两者,原因在于,两者提供的方法不能共用. 比如: $("#id").innerHTML; document.getElementById(id ...
- SQL Serve2008的一些操作
今天花了一下午的时间在熟悉SQL serve的一些操作,在此记录下学习到的东西: 首先创建数据库: use master --设置当前数据库为master,以便方便访问表sysdatabases if ...
- Feign 系列(01)最简使用姿态
目录 Feign 系列(01)最简使用姿态 1. 引入 maven 依赖 2. 基本用法 3. Feign 声明式注解 Feign 系列(01)最简使用姿态 Spring Cloud 系列目录(htt ...
- JUC源码分析-集合篇(七)PriorityBlockingQueue
JUC源码分析-集合篇(七)PriorityBlockingQueue PriorityBlockingQueue 是带优先级的无界阻塞队列,每次出队都返回优先级最高的元素,是二叉树最小堆的实现. P ...
- EE5111_A0206839W
EE5111 Selected Topics in Industrial Control & Instrumentation Assessment: Implement a simple ...
- 启动eclipse出现JVM terminated. Exit code=127 错误解决办法
https://blog.csdn.net/wpzsidis/article/details/72954387 进去第二次又错
- 笔记38 Spring Web Flow——订单流程(定义基本流程)
做一个在线的披萨订购应用 实际上,订购披萨的过程可以很好地定义在一个流程中.我们首先从 构建一个高层次的流程开始,它定义了订购披萨的整体过程.接下 来,我们会将这个流程拆分成子流程,这些子流程在较低的 ...
- vue 外卖app(3) 利用slot分发内容
1. 增加一个HeaderTop.vue <template> <header class="header"> <slot name="le ...
- 基于 CI 1.7.x 的 项目使用新版本CI的文件缓存类库
维护的项目使用的是 codeigniter 1.7.x版本,但是我想使用文件缓存,但是旧版本是没有缓存类库的,并且autoload.php没有drivers这个配置项. 我复制的是 Codeignit ...