《DSP using MATLAB》Problem 3.1
先写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的更多相关文章
- 《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窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- Java实现最基本的集中排序
排序是一个很重要的概念,现实生活中,我们需要为很多的东西排序.下面我们就介绍几种简单的排序的方法和最基本的思想. 1.冒泡排序:假设一个数组中有10个数字,从左边开始
- Web前台学习总结
前台的技术有很多种,流行的框架也是枚不胜举,在这里我们只讨论html,css,js这些基本的技术,相信大家如果掌握了这些最基本的技术,其他的技术也就会使用了. 下面是一个案例的形式来讲解上述的技术. ...
- Uva11374 Dijkstra
机场快线是市民从市内去机场的首选交通工具.机场快线分为经济线和商业线两种,线路.速度和价格都不同,你有一张商业线车票,可以坐一站商业线,而其他时候,只能乘坐经济线.假设换乘时间忽略不计,你的任务是找一 ...
- 两个星期,用Flutter撸个APP
前言 Flutter是Google推出的跨平台的解决方案,Slogan是"Design beautiful apps",国内也有知名企业在使用和推广,例如阿里.美团都有在尝试. 个 ...
- Vue学习笔记之vue-cli脚手架项目中组件的使用
在webpack-simple模板中,包括webpck模板.一个.vue文件就是一个组件. 为什么会这样呢?因为webpack干活了!webpack的将我们所有的资源文件进行打包.同时webpack还 ...
- Django学习笔记之form组件的局部钩子和全局钩子
本文通过注册页面的form组件,查看其中使用的全局钩子和局部钩子. # Create your views here. class RegForm(forms.Form): username = fo ...
- 中通快递单api查询
request POST https://hdgateway.zto.com/WayBill_GetDetail HTTP/1.1Host: hdgateway.zto.comConnection: ...
- [Opencv]图像的梯度与边缘检测(转)
文章来源:https://blog.csdn.net/on2way/article/details/46851451 梯度简单来说就是求导,在图像上表现出来的就是提取图像的边缘(不管是横向的.纵向的. ...
- Flask 1 Introductory Chapter
reference: <Flask Web 开发> Environment Python 3 Mac OSX Introductory Chapter: 安装 1.安装第三方工具 virt ...
- POJ 1815 Friendship(最小割+字典序输出割点)
http://poj.org/problem?id=1815 题意: 在现代社会,每个人都有自己的朋友.由于每个人都很忙,他们只通过电话联系.你可以假定A可以和B保持联系,当且仅当:①A知道B的电话号 ...