只放第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的更多相关文章

  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. Ext OOP基础

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Linux之-命令

    安装xshell http://jingyan.baidu.com/article/1612d500af1c97e20e1eee25.html 1.帮助命令 man:获得某个命令的说明和使用方式的详细 ...

  3. (转)OpenFire源码学习之七:组(用户群)与花名册(用户好友)

    转:http://blog.csdn.net/huwenfeng_2011/article/details/43413651 Group 在openfire中的gorop——组,也可以理解为共享组.什 ...

  4. PAT 1010 Radix(X)

    1010 Radix (25 分)   Given a pair of positive integers, for example, 6 and 110, can this equation 6 = ...

  5. normal use for autotools

    1. remove temporary files, only used for test purpose. ls | sed -e rm -rf 2. edit autogen.sh echo &q ...

  6. 洛谷 P4173 残缺的字符串 (FFT)

    题目链接:P4173 残缺的字符串 题意 给定长度为 \(m\) 的模式串和长度为 \(n\) 的目标串,两个串都带有通配符,求所有匹配的位置. 思路 FFT 带有通配符的字符串匹配问题. 设模式串为 ...

  7. PAT_A1048#Find Coins

    Source: PAT A1048 Find Coins (25 分) Description: Eva loves to collect coins from all over the univer ...

  8. Java 反射获取私有方法

    通常我们创建一个类时,它的私有方法在类外是不可见的,但是可以通过反射机制来获取调用.具体的反射机制的介绍大家自己百度. 所以反射可能会破坏我们的单例模式,当然解决方案也是有的,就是做个标记记录次数,第 ...

  9. 三(1)、springcloud之Eureka服务注册与发现

    1.认识Eureka ​ Eureka是Netflix的一个子模块,也是核心模块之一.Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对于微服务架 ...

  10. 《深入理解Java虚拟机》- 重载与重写

    这一节打算从“方法调用”的主题进行分析. 方法调用并不等同于方法执行,方法调用阶段唯一的任务就是确定被调用方法的版本(即调用哪一个方法),暂时还不设计方法内部的具体运行过程. 一.概念 解析调用:所有 ...