先写DTFT子函数:

function [X] = dtft(x, n, w)

%% ------------------------------------------------------------------------
%% Computes DTFT (Discrete-Time Fourier Transform)
%% of Finite-Duration Sequence
%% Note: NOT the most elegant way
% [X] = dtft(x, n, w)
% X = DTFT values computed at w frequencies
% x = finite duration sequence over n
% n = sample position vector
% w = frequency location vector M = 500;
k = [-M:M]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/M) * k; X = x * (exp(-j*pi/M)) .^ (n'*k);
% X = x * exp(-j*n'*pi*k/M) ;

下面开始利用上函数开始画图。结构都一样,先显示序列x(n),在进行DTFT,画出幅度响应和相位响应。

代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 3.1 \n\n'); banner();
%% ------------------------------------------------------------------------ % ----------------------------------
% x1(n)
% ----------------------------------
n1_start = -11; n1_end = 13;
n1 = [n1_start : n1_end]; x1 = 0.6 .^ (abs(n1)) .* (stepseq(-10, n1_start, n1_end)-stepseq(11, n1_start, n1_end)); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 x1(n)');
set(gcf,'Color','white');
stem(n1, x1);
xlabel('n'); ylabel('x1');
title('x1(n) sequence'); grid on; M = 500;
k = [-M:M]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/M) * k; [X1] = dtft(x1, n1, w); magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 DTFT');
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi, magX1); grid on;
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude');
subplot(2,2,3); plot(w/pi, angX1/pi); grid on;
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians/\pi');
subplot('2,2,2'); plot(w/pi, realX1); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w/pi, imagX1); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary'); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 DTFT of x1(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, 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'); % -------------------------------------
% x2(n)
% -------------------------------------
n2_start = -1; n2_end = 22;
n2 = [n2_start : n2_end]; x2 = (n2 .* (0.9 .^ n2)) .* (stepseq(0, n2_start, n2_end) - stepseq(21, n2_start, n2_end)); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 x2(n)');
set(gcf,'Color','white');
stem(n2, x2);
xlabel('n'); ylabel('x2');
title('x2(n) sequence'); grid on; M = 500;
k = [-M:M]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/M) * k; [X2] = dtft(x2, n2, w); magX2 = abs(X2); angX2 = angle(X2); realX2 = real(X2); imagX2 = imag(X2); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 DTFT of x2(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, 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'); % -------------------------------------
% x3(n)
% -------------------------------------
n3_start = -1; n3_end = 52;
n3 = [n3_start : n3_end]; x3 = (cos(0.5*pi*n3) + j * sin(0.5*pi*n3)) .* (stepseq(0, n3_start, n3_end) - stepseq(51, n3_start, n3_end)); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 x3(n)');
set(gcf,'Color','white');
stem(n3, x3);
xlabel('n'); ylabel('x3');
title('x3(n) sequence'); grid on; M = 500;
k = [-M:M]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/M) * k; [X3] = dtft(x3, n3, w); magX3 = abs(X3); angX3 = angle(X3); realX3= real(X3); imagX3 = imag(X3); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 DTFT of x3(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, 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'); % -------------------------------------
% x4(n)
% -------------------------------------
n4_start = 0; n4_end = 7;
n4 = [n4_start : n4_end]; x4 = [4:-1:1, 1:4]; figure('NumberTitle', 'off', 'Name', 'Problem 3.1 x4(n)');
set(gcf,'Color','white');
stem(n4, x4, 'r', 'filled');
xlabel('n'); ylabel('x4');
title('x4(n) sequence'); grid on; M = 500;
k = [-M:M]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/M) * k; [X4] = dtft(x4, n4, w); magX4 = abs(X4); angX4 = angle(X4); realX4= real(X4); imagX4 = imag(X4); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 DTFT of x3(n)');;
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, 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'); % -------------------------------------
% x5(n)
% -------------------------------------
n5_start = 0; n5_end = 7;
n5 = [n5_start : n5_end]; x5 = [4:-1:1, -1:-1:-4]; figure('NumberTitle', 'off', 'Name', 'Problem 3.1 x5(n)');
set(gcf,'Color','white');
stem(n5, x5, 'r', 'filled');
xlabel('n'); ylabel('x5');
title('x5(n) sequence'); grid on; M = 500;
k = [-M:M]; % [-pi, pi]
%k = [0:M]; % [0, pi]
w = (pi/M) * k; [X5] = dtft(x5, n5, w); magX5 = abs(X5); angX5 = angle(X5); realX5= real(X5); imagX5 = imag(X5); figure('NumberTitle', 'off', 'Name', 'Problem 3.1 DTFT of x5(n)');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, magX5); grid on;
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude');
subplot(2,1,2); plot(w/pi, angX5); grid on;
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians');

  运行结果:

相位响应是关于ω=0偶对称的。

序列2:

序列3:

序列3的主要频率分量位于ω=0.5π。

序列4:

序列4的相位谱关于ω= 0奇对称。

序列5:

序列5的相位谱关于ω=0奇对称。

《DSP using MATLAB》Problem 3.1的更多相关文章

  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. malloc calloc realloc 区别

    (1)C语言跟内存分配方式 <1>从静态存储区域分配.       内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量.static变量.<2> ...

  2. 将flex页面嵌入到jsp页面中

    如果我们只需要用到Flex的一部分功能,例如播放器功能,我们可以单独把Flex页面嵌入到Jsp页面中.要想实现此功能,需要下载一个工程,将其覆盖在服务器根目录下即可.你可以在次下载:FlexModul ...

  3. 异常来自HRESULT:0x80070422

    今天同事使用一个用VB.NET2008开发的应用程序时提示“出现了下列应用程序错误:无法启动服务,原因可能是已被禁用或与其相关联的设备没有启动.(异常来自HRESULT:0x80070422)”   ...

  4. STM32 DMA简述

    STM32 DMA简述 DMA (Direct Memory Access) 直接内存存储器,在做数据传输时能够大大减轻CPU的负担. DMA的作用 DMA提供了一个关于数据的高数传输通道,这个通道不 ...

  5. linux及安全第五周总结——20135227黄晓妍

    (注意:本文总结备份中有较多我手写笔记的图片,其中重要的部分打出来了.本文对分析system_call对应的汇编代码的工作过程,系统调用处理过程”的理解,以及流程图都写在实验部分.) 实验部分 使用g ...

  6. STRIDE 和 DREAD

    目录 STRIDE 和 DREAD 背景 STRIDE DREAD 注释 STRIDE 和 DREAD 背景 STRIDE 和 DREAD 是最常用也是最好用的安全模型 STRIDE 主要负责对安全风 ...

  7. 路由器实操 能够登陆QQ 收发信息正常 但游览器无法连接网页

    这种情况下,网络是没有问题的. ping www.baidu.com 失败,但是能上QQ说明网络没有问题:这一般是域名解析DNS的问题. 游览器登陆192.168.1.1.输入用户密码,均为admin ...

  8. Linux的硬链接和软链接

    1.Linux链接概念Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link), 也就是软链接.默认情况下,ln命令产生硬链接. [硬连接]硬连 ...

  9. spark 累加历史 + 统计全部 + 行转列

    spark 累加历史主要用到了窗口函数,而进行全部统计,则需要用到rollup函数 1  应用场景: 1.我们需要统计用户的总使用时长(累加历史) 2.前台展现页面需要对多个维度进行查询,如:产品.地 ...

  10. Undertow,Tomcat和Jetty服务器配置详解与性能测试

    undertow,jetty和tomcat可以说是javaweb项目当下最火的三款服务器,tomcat是apache下的一款重量级的服务器,不用多说历史悠久,经得起实践的考验.然而:当下微服务兴起,s ...