《DSP using MATLAB》 Problem 3.22

代码:
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 3.22 \n\n'); banner();
%% ------------------------------------------------------------------------ %% -------------------------------------------------------------------
%% 1 xa(t)=cos(20πt+θ) through A/D
%% -------------------------------------------------------------------
Ts = 0.05; % sample interval, 0.05s
Fs = 1/Ts; % Fs=20Hz
%theta = 0;
%theta = pi/6;
%theta = pi/4;
%theta = pi/3;
theta = pi/2; n1_start = 0; n1_end = 20;
n1 = [n1_start:1:n1_end];
nTs = n1 * Ts; % [0, 1]s x1 = cos(20*pi*nTs + theta * ones(1,length(n1))); % Digital signal M = 500;
[X1, w] = dtft1(x1, n1, M); magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1); %% --------------------------------------------------------------------
%% START X(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 X1, theta/pi = %f', theta/pi));
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 X1, theta/pi = %f', theta/pi));
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realX1); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagX1); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 xa(n), theta/pi = %f and x1(n)', theta/pi));
na1 = 0:0.01:1;
xa1 = cos(20 * pi * na1 + theta * ones(1,length(na1)));
set(gcf, 'Color', 'white');
plot(1000*na1,xa1); grid on; %axis([0,1,0,1.5]);
title('x1(n) and xa(n)');
xlabel('t in msec.'); ylabel('xa(t)'); hold on;
plot(1000*nTs, x1, 'o'); hold off; %% ------------------------------------------------------------
%% xa(t) reconstruction from x1(n)
%% ------------------------------------------------------------ Dt = 0.001; t = 0:Dt:1;
xa = x1 * sinc(Fs*(ones(length(n1),1)*t - nTs'*ones(1,length(t)))) ; figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 Reconstructed From x1(n), theta/pi = %f', theta/pi));
set(gcf,'Color','white');
%subplot(2,1,1);
stairs(t*1000,xa,'r'); grid on; %axis([0,1,0,1.5]); % Zero-Order-Hold
title('Reconstructed Signal from x1(n) using Zero-Order-Hold');
xlabel('t in msec.'); ylabel('xa(t)'); hold on;
%stem(nTs*1000, x1); gtext('ZOH'); hold off;
plot(nTs*1000, x1, 'o'); gtext('ZOH'); hold off; figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 Reconstructed From x1(n), theta/pi = %f', theta/pi));
set(gcf,'Color','white');
%subplot(2,1,2);
plot(t*1000,xa,'r'); grid on; %axis([0,1,0,1.5]); % first-Order-Hold
title('Reconstructed Signal from x1(n) using First-Order-Hold');
xlabel('t in msec.'); ylabel('xa(t)'); hold on;
plot(nTs*1000,x1,'o'); gtext('FOH'); hold off; xa = spline(nTs, x1, t);
figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 Reconstructed From x1(n), theta/pi = %f', theta/pi));
set(gcf,'Color','white');
%subplot(2,1,1);
plot(1000*t, xa,'r');
xlabel('t in ms units'); ylabel('x');
title(sprintf('Reconstructed Signal from x1(n) using Spline function')); grid on; hold on;
plot(1000*nTs, x1,'o'); gtext('spline');
运行结果:
这里只看初相位为0的情况,原始模拟信号和采样信号(样点值圆圈标示):

采样信号的谱,模拟角频率20π对应的数字角频率为π,如下图所示:

用采样信号重建原来模拟信号:
sinc方法,stairs函数画图

sinc方法,plot函数画图:

cubic方法

其他初相位的情况,这里不上图了。
《DSP using MATLAB》 Problem 3.22的更多相关文章
- 《DSP using MATLAB》Problem 6.22
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.22
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...
- 《DSP using MATLAB》Problem 8.22
时光飞逝,亲朋会一个一个离我们远去,孤独漂泊一阵子后,我们自己也要离开, 代码: %% -------------------------------------------------------- ...
- 《DSP using MATLAB》Problem 7.25
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 3.1
先写DTFT子函数: function [X] = dtft(x, n, w) %% --------------------------------------------------------- ...
- 《DSP using MATLAB》Problem 7.29
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- Codeforces 260B - Ancient Prophesy
260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...
- Windows 2008 更改网卡绑定顺序
用 ncpa.cpl 或者用鼠标右键点网上邻居进去也好. 来到网卡列表画面. 然后,你会发觉没有菜单去操作[高级设置], 这里,最高级的步骤来了, 就是你需要按一个 [Alt]把菜单给显示出来,太神奇 ...
- (转)HapMap简介
1.人类基因组的HapMap和国际HapMap计划 (1)何谓HapMap HapMap是Haplotype Map 的简称,Haplo意为单一,在基因组中专指来自父母的一对染色体中的一条.Haplo ...
- dp练习(4)——过河卒
1010 过河卒 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 如图,A ...
- JQuery $未定义
---恢复内容开始--- JQuery $未定义 转载▼ jquery是Yii集成的,利用jquery写的代码$(document).ready(function(){// 操作列表$('.ope ...
- 最应该注意的Oracle版本之一
最近以来,两个用户的库接连出现问题,经过查阅资料和分析,确定为数据库bug所致,其实,早在很久前,也遭遇过这个版本的类似bug,当时似乎还惊动了原厂的技术人员,后来确定为这个版本的bug,这个版本就是 ...
- python 利用quick sort思路实现median函数
# import numpy as np def median(arr): #return np.median(arr) arr.sort() return arr[len(arr)>>1 ...
- jsp jsp传统标签开发
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 我的一起开源网 www.17ky.net上线了
.net开源生态的落后,使得.net开发人员所拥有的开源资源比其他语言的开发者少了很多,这也使得笔者很早之前就喜欢收集各种开源项目,经常会去逛codeplex,开源中国社区等网站,同时也喜欢在自己或公 ...
- bzoj3601
题解:gi(pq=pqi-pqi+di 至于为什么,可以看看往上的题解 代码: #include<bits/stdc++.h> using namespace std; typedef l ...