代码:

%% ------------------------------------------------------------------------
%% 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的更多相关文章

  1. 《DSP using MATLAB》Problem 6.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  2. 《DSP using MATLAB》Problem 5.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...

  3. 《DSP using MATLAB》Problem 8.22

    时光飞逝,亲朋会一个一个离我们远去,孤独漂泊一阵子后,我们自己也要离开, 代码: %% -------------------------------------------------------- ...

  4. 《DSP using MATLAB》Problem 7.25

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  5. 《DSP using MATLAB》Problem 3.1

    先写DTFT子函数: function [X] = dtft(x, n, w) %% --------------------------------------------------------- ...

  6. 《DSP using MATLAB》Problem 7.29

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  7. 《DSP using MATLAB》Problem 7.27

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  8. 《DSP using MATLAB》Problem 7.26

    注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...

  9. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. Codeforces C - Om Nom and Candies

    C - Om Nom and Candies 思路:贪心+思维(或者叫数学).假设最大值max(wr,wb)为wr,当c/wr小于√c时,可以枚举r糖的数量(从0到c/wr),更新答案,复杂度√c:否 ...

  2. [.NET开发] C#实现的SQL备份与还原功能示例

    本文实例讲述了C#实现的SQL备份与还原功能.分享给大家供大家参考,具体如下: //记得加 folderBrowserDialog1 openFileDialog1 控件 using System.D ...

  3. Python的url解析库--urlparse

    一.urlparse解析url的query并构建字典 下面的方法主要的功能: 解析url的各个部分,并能够获取url的query部分,并把query部分构建成dict. 具体的代码实现: >&g ...

  4. python-day30--粘包

    一. 什么是粘包 1.须知:只有TCP有粘包现象,UDP永远不会粘包 2.所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 二.两种情况下会发生粘包. 1. ...

  5. python-day7--%s与%d的使用,python2中的input及raw_input

    #coding:utf-8 #utf-8格式打开#%s %d# name='egon'# age=18# print('my name is',name)# print('my name is my ...

  6. 用DFS 解决全排列问题的思想详解

    首先考虑一道奥数题目: □□□ + □□□ = □□□,要将数字1~9分别填入9个□中,使得等式成立.例如173+286 = 459.请输出所有合理的组合的个数. 我们或许可以枚举每一位上所有的数,然 ...

  7. hpu积分赛(回溯法)

    问题 : 不开心的小明① 时间限制: 1 Sec 内存限制: 128 MB 提交: 2 解决: 1 题目描述 一天, 小明很不开心,先是向女神表白被拒, 数学又考了0分, 回家的路上又丢了钥匙, 他非 ...

  8. UVA-10127 Ones (数论)

    题目大意:给一个数n,找出一个各位全是1的最小的十进制数,使得n能整除这个数.只输出最小位数. 题目分析:纯粹是数论,暴力. 代码如下: # include<iostream> # inc ...

  9. python 使用yield进行数据的流式处理

    demo:从文件中取包含字符“a”的5行数据做一次批处理!!! # coding: utf-8 import time def cat(f): for line in f: yield line de ...

  10. Jpa实体类生成图解

    Jpa实体类生成图解   创建连接     创建项目