代码:

n = [0:1:99]; x = cos(0.48*pi*n) + cos(0.52*pi*n);
n1 = [0:1:9]; y1 = x(1:1:10); % N = 10 figure('NumberTitle', 'off', 'Name', 'Exameple5.8 x sequence')
set(gcf,'Color','white');
subplot(3,1,1); stem(n1,y1); title('signal x(n), 0<= n <=9, N = 10'); axis([0,10,-2.5,2.5]);
xlabel('n'); ylabel('x(n)'); grid on; Y1_DFT = dft(y1,10); % DFT of y1 magY1_DFT = abs(Y1_DFT(1:1:6));
%magY1_DFT = abs(Y1_DFT);
%phaY1_DFT = angle(Y1_DFT)*180/pi % degrees
phaY1_DFT = angle(Y1_DFT(1:1:6))*180/pi % degrees
%realX_DFT = real(X_DFT); imagX_DFT = imag(X_DFT);
%angX_DFT = angle(X_DFT); % radias k1 = 0:1:5; w1 = 2*pi/10*k1; % [0,2pi] axis divided into 501 points.
%k = 0:500; w = (pi/500)*k; % [0,pi] axis divided into 501 points.
%X_DTFT = x * (exp(-j*pi/500)) .^ (n'*k); % DTFT of x(n) %magX_DTFT = abs(X_DTFT); angX_DTFT = angle(X_DTFT); realX_DTFT = real(X_DTFT); imagX_DTFT = imag(X_DTFT);
subplot(3,1,2); stem(w1/pi,magY1_DFT); title('Samples of DTFT Magnitude, Not Enough'); %axis([0,N,-0.5,1.5]);
xlabel('frequency in \pi units');
%ylabel('x(n)');
grid on;
subplot(3,1,3); stem(w1/pi,phaY1_DFT); title('Samples of DTFT Phase, Not Enough'); %axis([0,N,-0.5,1.5]);
xlabel('frequency in \pi units');
%ylabel('x(n)');
grid on; %% ------------------------------------------------------
%% zero-padding coperation, Append 90 zeros
%% To obtain a dense spectrum
%% ------------------------------------------------------
n2 = [0:1:99]; y2 = [x(1:1:10) zeros(1,90)]; % zero-padding, N = 100 figure('NumberTitle', 'off', 'Name', 'Exameple5.8 x sequence')
set(gcf,'Color','white');
subplot(2,1,1); stem(n2,y2); title('signal x(n), 0<= n <=9 + 90 zeros, N = 100'); axis([0,100,-2.5,2.5]);
xlabel('n'); ylabel('x(n)'); grid on; Y2_DFT = dft(y2,100); % DFT of y2 magY2_DFT = abs(Y2_DFT(1:1:51));
phaY2_DFT = angle(Y2_DFT)*180/pi % degrees k2 = 0:1:50; w2 = (2*pi/100)*k2; % [0,2pi] axis divided into 501 points.
subplot(2,1,2); stem(w2/pi,magY2_DFT); hold on; plot(w2/pi,magY2_DFT,'--r');
title('DTFT Magnitude'); axis([0,1,0,10.5]); hold off;
xlabel('frequency in \pi units');
%ylabel('x(n)');
grid on; %% -----------------------------------------------------------
%% Exameple5.8b take first 100 samples of x(n)
%% determine the DTFT
%% -----------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Exameple5.8b ')
set(gcf,'Color','white');
subplot(2,1,1); stem(n,x); axis([0,100,-2.5,2.5]);
title('signal x(n), 0 <= n <= 99, N = 100'); xlabel('n'); grid on; X = dft(x,100); magX = abs(X(1:1:51));
k = 0:1:50; w = 2*pi/100*k;
subplot(2,1,2); plot(w/pi, magX); title('DTFT Magnitude');
xlabel('frequency in \pi units'); axis([0,1,0,60]); grid on;
%% -----------------------------------------------------------
%% END Exameple5.8b
%% -----------------------------------------------------------

  结果:

《DSP using MATLAB》示例Example5.8的更多相关文章

  1. DSP using MATLAB 示例Example3.21

    代码: % Discrete-time Signal x1(n) % Ts = 0.0002; n = -25:1:25; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*a ...

  2. DSP using MATLAB 示例 Example3.19

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Discrete-time Signa ...

  3. DSP using MATLAB示例Example3.18

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Continuous-time Fou ...

  4. DSP using MATLAB 示例Example3.23

    代码: % Discrete-time Signal x1(n) : Ts = 0.0002 Ts = 0.0002; n = -25:1:25; nTs = n*Ts; x1 = exp(-1000 ...

  5. DSP using MATLAB 示例Example3.22

    代码: % Discrete-time Signal x2(n) Ts = 0.001; n = -5:1:5; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*abs(nT ...

  6. DSP using MATLAB 示例Example3.17

  7. DSP using MATLAB示例Example3.16

    代码: b = [0.0181, 0.0543, 0.0543, 0.0181]; % filter coefficient array b a = [1.0000, -1.7600, 1.1829, ...

  8. DSP using MATLAB 示例 Example3.15

    上代码: subplot(1,1,1); b = 1; a = [1, -0.8]; n = [0:100]; x = cos(0.05*pi*n); y = filter(b,a,x); figur ...

  9. DSP using MATLAB 示例 Example3.13

    上代码: w = [0:1:500]*pi/500; % freqency between 0 and +pi, [0,pi] axis divided into 501 points. H = ex ...

  10. DSP using MATLAB 示例 Example3.12

    用到的性质 代码: n = -5:10; x = sin(pi*n/2); k = -100:100; w = (pi/100)*k; % freqency between -pi and +pi , ...

随机推荐

  1. WebStorage的使用

    HTML5中的WebStorage有两种类型的API:localStorage和sessionStorage: localStorage在本地永久性存储数据,除非显式将其删除或清空: sessionS ...

  2. 《Python核心编程》18.多线程编程(二)

    18.1没有线程支持 #!/usr/bin/env python # -*- coding:utf-8 -*- from time import sleep, ctime def loop0(): p ...

  3. Eclipse Maven3新建web项目

    环境: Eclipse Neon JDK1.8 先决条件: 本机下载apache-tomcat-8,解压,在Eclipse->preferences->server里配置安装目录.并在ec ...

  4. ArcGIS Server开发教程系列(2)配置ARCMAP和ARCCatalog发布服务

    1.       Arc catalog的配置 打开catalog,如图新增刚刚创建的server 1. Use GIS services: 用户身份连接 使用此种连接,可以浏览.使用站点内发布的所有 ...

  5. Dapper.Net 应用

    Dapper应用 1.Dapper是什么 Dapper是一款轻量级ORM工具.如果你在小的项目中,使用Entity Framework.NHibernate 来处理大数据访问及关系映射,未免有点杀鸡用 ...

  6. css 基础---选择器

    1.css基础 selector {property: value} eg: h1 {color:red; font-size:14px;} p { text-align: center; color ...

  7. IntelliJ IDEA 14.x 快捷键/个性化设置

    常用快捷键设置(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> Keymap -> ...

  8. Linux启动新进程的几种方法汇总

    有时候,我们需要在自己的程序(进程)中启动另一个程序(进程)来帮助我们完成一些工作,那么我们需要怎么才能在自己的进程中启动其他的进程呢?在Linux中提供了不少的方法来实现这一点,下面就来介绍一个这些 ...

  9. synchronized在jvm底层是如何实现的

    目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...

  10. CSS修改input[type=range]滑块样式

    input[type="range"]是html5中的input标签新属性,样子如下: <input type="range" value="4 ...