代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 3.4 \n\n'); banner();
%% ------------------------------------------------------------------------ % ----------------------------------------------
% Rectangle Window sequence
% ----------------------------------------------
M = 101; n1_start = 0; n1_end = M;
n1 = [n1_start : n1_end - 1]; x1 = ones(1, length(n1)); figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x1(n) Rectangle');
set(gcf,'Color','white');
stem(n1, x1);
xlabel('n'); ylabel('x1');
title(sprintf('x1(n) sequence, M = %d', M)); grid on; MM = 500;
k = [-MM:MM]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/MM) * k; [X1] = dtft(x1, n1, w); magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1); figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Rm(n)');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magX1/max(magX1)); grid on;
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude');
subplot(2,1,2); plot(w/pi, angX1); grid on;
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians'); % --------------------------------------------------
% Hanning Window Sequence
% --------------------------------------------------
%n2_start = -9; n2_end = 15;
%n2 = [n2_start : n2_end];
n2 = n1;
x2 = 0.5 * (1 - cos(2*pi*n1/(M-1))) .* x1; figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x2(n) Hanning');
set(gcf,'Color','white');
stem(n2, x2);
xlabel('n'); ylabel('x2');
title(sprintf('x2(n) sequence, M = %d', M)); grid on; MM = 500;
k = [-MM:MM]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/MM) * k; [X2] = dtft(x2, n2, w); magX2 = abs(X2); angX2 = angle(X2); realX2 = real(X2); imagX2 = imag(X2); figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Cm(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magX2/max(magX2)); grid on;
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude');
subplot(2,1,2); plot(w/pi, angX2); grid on;
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians'); % --------------------------------------------------
% Triangular Window Sequence
% --------------------------------------------------
%n3_start = -3; n3_end = 10;
%n3 = [n3_start : n3_end];
n3 = n1;
x3 = (1 - abs(M-1-2*n3)/(M-1)) .* x1; figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x3(n) Triangular');
set(gcf,'Color','white');
stem(n3, x3);
xlabel('n'); ylabel('x3');
title(sprintf('x3(n) sequence, M = %d', M)); grid on; MM = 500;
k = [-MM:MM]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/MM) * k; [X3] = dtft(x3, n3, w); magX3 = abs(X3); angX3 = angle(X3); realX3= real(X3); imagX3 = imag(X3); figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Tm(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magX3/max(magX3)); grid on;
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude');
subplot(2,1,2); plot(w/pi, angX3); grid on;
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians'); % ---------------------------------------------
% Hamming Window sequence
% ---------------------------------------------
%n4_start = 0; n4_end = 50;
%n4 = [n4_start : n4_end];
n4 = n1;
x4 = (0.54 - 0.46 * cos(2*pi*n4/(M-1))) .* x1; figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x4(n) Hamming');
set(gcf,'Color','white');
stem(n4, x4, 'filled');
xlabel('n'); ylabel('x4');
title(sprintf('x4(n) sequence, M = %d', M)); grid on; MM = 500;
k = [-MM:MM]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/MM) * k; [X4] = dtft(x4, n4, w); magX4 = abs(X4); angX4 = angle(X4); realX4= real(X4); imagX4 = imag(X4); figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Hm(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magX4/max(magX4)); grid on;
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude');
subplot(2,1,2); plot(w/pi, angX4); grid on;
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians');

  运行结果:

矩形窗:

汉宁窗:

三角窗:

汉明窗:

《DSP using MATLAB》Problem 3.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. C#中正确使用enum做Key的姿势

    C#中自定义enum,然后将其作为Dictionary的Key,通常的做法如下: using System; using System.Text; using System.Collections.G ...

  2. 雷林鹏分享:Ruby 安装 - Windows

    Ruby 安装 - Windows 下面列出了在 Windows 机器上安装 Ruby 的步骤. 注意:在安装时,您可能有不同的可用版本. 下载最新版的 Ruby 压缩文件.请点击这里下载. 下载 R ...

  3. Greengenes Database(16S)

    The Greengenes Database Release 13_5 这是16S的一个非常重要的数据库 The Greengenes Database, a public resource sin ...

  4. BUCTOJ_ACM2017C 回文串的热爱

    #include "iostream" #include "algorithm" #include "cstdio" #include &q ...

  5. 每天一个linux命令(3):pwd

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  6. dubbo provider如何对invoker进行export

    如何把provider的invoker export出去:1)为原始对象加wrapper,生成invoker:2)给invoker加各种filter,启动监听服务:3)注册服务地址 以HelloSer ...

  7. 如何获取显示器的EDID信息

    Q1: 为什么要写这篇文章? A1:在最近的工作中遇到了不少问题,其中很多都是和EDID相关的.可以说,作为一家以“显示”为生的企业,我们时时刻刻在与EDID打交道.EDID这东西很简单,但是如果不了 ...

  8. Flash OS images to SD cards & USB drives & TF cards safely and easily using etcher

    install tools: wget https://github.com/resin-io/etcher/releases/download/v1.4.5/etcher-cli-1.4.5-lin ...

  9. win764位下mysql-5.6.24-x64从安装到登录成功

    1.安装 本人电脑win7,64位,需要安装mysql服务器.版本:mysql-5.6.24-x64.这里我用的是绿色版,免安装.由于免安装的原因,在服务里面并没有mysql的服务.这里我需要打开my ...

  10. Dash:程序员的好帮手(转载)

    作为一名死coder,每天最常见的动作就是查看各种API文档,你一定也有过同时打开N个窗口(HTML.PDF.CHM),不停的在编辑器与文档之间切换的感受吧?怎么说呢,其实我很讨厌这种枯燥无味的动作, ...