《DSP using MATLAB》Problem 9.4
只放第1小题。
代码:
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 9.4.1 \n\n'); banner();
%% ------------------------------------------------------------------------ % ------------------------------------------------------------
% PART 1
% ------------------------------------------------------------ % Discrete time signal n1_start = 0; n1_end = 100;
n1 = [n1_start:1:n1_end]; xn1 = cos(0.15*pi*n1); % digital signal D = 4; % downsample by factor D
OFFSET = 0;
y = downsample(xn1, D, OFFSET);
ny = [n1_start:n1_end/D];
% ny = [n1_start:n1_end/D-1]; % OFFSET=2 figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 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(sprintf('y sequence, downsample by D=%d offset=%d', D, OFFSET)); 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);
max(magX1) %% --------------------------------------------------------------------
%% START X(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 X1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-2, -1, -0.5, 0, 0.15, 0.5, 1, 2]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
set(gca, 'xtick', [-2,-1.85,-1.5,-1,-0.15,0,0.15,0.5,1,1.5,1.85,2]);
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.4.1 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);
max(magY_DTFT)
ratio = max(magX1)/max(magY_DTFT) %% --------------------------------------------------------------------
%% START Y(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 Y DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magY_DTFT); grid on; %axis([-2,2, -1, 2]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
set(gca, 'xtick', [-2,-1.4,-1,-0.6,0,0.6,1,1.4,2]);
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.4.1 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', sprintf('Problem 9.4.1 X1 & Y--DTFT of x and y, D=%d offset=%d', D,OFFSET));
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|');
set(gca, 'xtick', [-2,-1.85,-1.4,-1,-0.6,-0.5,-0.15,0,0.15,0.5,0.6,1,1.4,1.85,2]);
set(gca, 'ytick', [-0.2, 0, 13.5, 20, 40, 51, 60]);
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;
运行结果:
分两种情况
1、按照D=4抽取,offset=0
原始序列,抽取序列
原始序列的谱
抽取序列的谱
二者的DTFT混叠到一起,红颜色曲线是抽取序列的DTFT,可看出,其幅度大致为原始序列的谱幅度的1/4(精确值是1/3.7778)。
2、按照D=4抽取,offset=2
二者的DTFT混叠到一起,红颜色曲线是抽取序列的DTFT,可看出,其幅度大致为原始序列的谱幅度的1/4(精确值是1/4.0699)。
《DSP using MATLAB》Problem 9.4的更多相关文章
- 《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窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- delphi 给程序加托盘图标
一些程序运行时,会在桌面的右下角显示一个图标(任务栏的右边),这类图标称为 托盘.托盘是一个PNotifyIconDataA类型的结构,要增加托盘图标其实就是对结构PNotifyIconDataA的操 ...
- Apache解析漏洞复现(CVE-2017-15715),可以绕过黑名单
照着P神的文章准备复现一下(总结一下经验) 环境的安装 这里面直接使用的vulhub里面的环境来进行安装的(为了方便吗) 基础环境如下  实际上Apache版本在2.4.0~2.4.29即可 i ...
- [NOIP模拟测试9]题(Problem) 题解 (组合数全家桶+dp)
达哥送分给我我都不要,感觉自己挺牛批. $type=0:$ 跟visit那题类似,枚举横向移动的步数直接推公式: $ans=\sum C_n^i \times C_i^{\frac{i}{2}} \t ...
- jmeter 创建接口测试案例
1 怎么做接口测试? 一般情况下,由于我们项目前后调用主要是基于http协议的接口,所以测试接口时主要是通过工具或代码模拟http请求的发送和接收.所以我们下面整理了一下使用Jmeter工具进行htt ...
- PHP面试 PHP基础知识 一(引用变量)
PHP引用变量 常见引用变量面试题: 什么是引用变量? 在PHP中用什么符号定义引用变量? 考点:PHP的引用变量的概念及定义方式 概念:在PHP中引用意味着用不用的名字访问同一个变量内容 定 ...
- 剑指offer——64和为s的数字
题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. 题解 ...
- jenkins集成sonar代码审核工具
在项目测试管理过程中,项目上线很多时候时间仓促,导致代码质量不高,测试时间不充分会导致线上出现各种各样的问题,这个时候一方面是增加测试的质量把控,还要从根本上解决开发小哥的代码质量问题.而Sonar这 ...
- Spring事务详细解释
前言 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为.事务传播行为是Spring框架独有的事务增强特性,他不属于的事务实际提供方数据库行为.这是Spring ...
- 判断页面是否在iframe中,
//判断页面是否在iframe中,是的话就跳出iframe框,多用于登录页 ,将此段代码放到要做判断的页面上即可 if (window != top) { top.location.href = l ...
- Object相关方法
const object1 = { a: 'somestring', b: 42, c: false }; console.log(Object.values(object1)); // expect ...