代码:

%% ------------------------------------------------------------------------
%% 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. javascript对象使用总结

    javascript对象使用总结 一.总结 一句话总结:js对象的主要知识点是创建对象和继承,并且创建对象和继承的方法都是逐步层层递进的 创建对象 继承 原型 创建对象 1 <script> ...

  2. LeetCode--027--移除元素

    问题描述: 给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间 ...

  3. 20161227xlVBA多文件合并计算

    Sub NextSeven_CodeFrame() '应用程序设置 Application.ScreenUpdating = False Application.DisplayAlerts = Fal ...

  4. Linux 下载最新kubectl版本的命令:

    ubuntu centos下通用 第一步.下载最新版本的命令: curl -LO https://storage.googleapis.com/kubernetes-release/release/$ ...

  5. vue 右键菜单插件 简单、可扩展、样式自定义的右键菜单

    今天分享的不是技术,今天给大家分享个插件,针对现有的vue右键菜单插件,大多数都是需要使用插件本身自定义的标签,很多地方不方便,可扩展性也很低,所以我决定写了一款自定义指令调用右键菜单(vuerigh ...

  6. UVA-11029 Leading and Trailing

    Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...

  7. HttpServletResponse输出的中文乱码

    HttpServletResponse输出有两种格式,一种是字符流,一种是字节流. 1.字符流 // 这句话的意思,是让浏览器用utf8来解析返回的数据,即设置客户端解析的编码 response.se ...

  8. React Js 之JSX

    React使用JSX作为模板替换JavaScript,它不是必须的,但是它是推荐使用.原因如下: 1.它比传统的JavaScript更快,因为编译代码的时候,JSX做了相应的优化 2.它是类型安全的, ...

  9. UVALive 4764 dp

    DES: 这是一个新的游戏.给你一套牌.编号从1到100000.正常来说.你手中的牌和这次翻的牌是一样的,就会加一分.但是.如果是999的话.加三分.所以问你最大的分是多少. 貌似是简单的DP吧.(D ...

  10. poj2892

    题解: 答案=后缀-前缀-1 如果被轰了,那么就时0 在一开始加入0,n+1,保证有前缀后缀 代码: #include<cstdio> #include<cmath> #inc ...