《DSP using MATLAB》 Problem 3.22 - 跑啊跑

ky027wh-sx 2021-08-09 原文


《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方法

        其他初相位的情况,这里不上图了。

发表于
2018-01-19 09:21 
跑啊跑 
阅读(137
评论(0
编辑 
收藏 
举报

 

版权声明:本文为ky027wh-sx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/ky027wh-sx/p/8315347.html

《DSP using MATLAB》 Problem 3.22 - 跑啊跑的更多相关文章

  1. JSP九大内置对象及四个作用域 – ZYXS

    JSP九大内置对象及四大作用域概述 Jsp九大内置对象及四大作用域概述:   在Jsp开发中,Jsp提供了9个 […]...

  2. Java基础知识回顾之一 —– 基本数据类型

    前言 在开始工作至今,学习各种各样的技术之中发现自己的很多Java的基础知识都忘了⊙﹏⊙b汗。。。 而且越是学 […]...

  3. itest(爱测试) 4.1.1 发布,开源BUG 跟踪管理 & 敏捷测试管理软件

    itest 开源敏捷测试管理,testOps 践行者。可按测试包分配测试用例执行,也可建测试迭代(含任务,测试 […]...

  4. 数据库的几个概念:主键,外键,索引,唯一索引 – 三戒1993

    数据库的几个概念:主键,外键,索引,唯一索引 2012-10-18 09:34  三戒1993  阅读(145 […]...

  5. MAC OSX 驱动操作 – ArRan

    mac ox系统的驱动安装常规操作:下载到 *.kext 的驱动以后,都可以直接把它拖到 /System/Li […]...

  6. OSI七层模型与TCP/IP五层模型 – SevenFormer

    OSI七层模型与TCP/IP五层模型         博主是搞是个FPGA的,一直没有真正的研究过以太网相关的 […]...

  7. 下载安装与配置Excel 2013数据挖掘加载项(SQL Server 2012 SP1 + SQLServer2012_DMAddin.msi)

        一、系统要求   在安装这个数据挖掘加载项前,你的机器必须要可以支持如下的相关系统设备:   (1)操 […]...

  8. [知乎]学了 Python 之后,再学 Java 是不是会更容易? – morxio

    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。作者:Lambda链接:https://w […]...

随机推荐

  1. JS中调用android和ios系统手机打开相机并可选择相册功能

    编写不易,如有转载,请声明出处: 梦回河口:http://blog.csdn.net/zxc514257857 […]...

  2. Java并发编程笔记之基础总结(一)

    一.线程概念 说到线程就必须要提一下进程,因为线程是进程中的一个实体,线程本身是不会独立存在的。进程是代码在数 […]...

  3. 华为交换机配置Telnet远程登入方式

    网络拓扑图如下: 需求:在AR 1上telnet 1.1.1.1需要账户认证,在LSW 1上telnet 1. […]...

  4. 百度地图API-搜索地址、定位、点击获取经纬度并标注

    百度地图api:http://developer.baidu.com/map/jsdemo.htm api申请 […]...

  5. 微信小程序 – 生成二维码

    生成二维码有两种方式: 前端生成(仅展示用)   1 onShow: function() { 2 3 4 5 […]...

  6. Junit单元测试遇到的initializationerror:method initializationerror not found

    原因可能如下: 1.有返回值的方法不能直接测试 2.带参数的方法不能直接测试 3.访问权限在public一下的 […]...

  7. 段码表大全

    段码太多会加重Flash区负担,应给予优化。 LED数码管   共阳极LED: 0xc0,0xf9,0xa4, […]...

  8. 必学Excel2013打印机巧之让表格居中打印

    大家应该对打印Word文档都是很熟悉了的,可是Excel呢?打印Excel也是有很多技巧的,今天我们就来学习最 […]...

展开目录

目录导航