《DSP using MATLAB》示例Example5.7

代码:
x = [1, 1, 1, 1, zeros(1,4)];
N = 8; % zero-padding operation
X_DFT = dft(x,N); % DFT of x(n) magX_DFT = abs(X_DFT)
phaX_DFT = angle(X_DFT)*180/pi % degrees
realX_DFT = real(X_DFT); imagX_DFT = imag(X_DFT);
angX_DFT = angle(X_DFT); % radias n = 0:(N - 1);
k = 0:1000; w = (pi/500)*k; % [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); figure('NumberTitle', 'off', 'Name', 'Exameple5.7 x sequence')
set(gcf,'Color','white');
stem(n,x); title('x sequence'); axis([0,N,-0.5,1.5]);
xlabel('n'); ylabel('x(n)'); grid on; %% --------------------------------------------------------------
%% START X_DTFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'X_DTFT its Magnitude and Angle, Real and Imaginary Part');
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi,magX_DTFT); grid on; % axis([-2,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |X\_DTFT|');
subplot(2,2,3); plot(w/pi, angX_DTFT*180/pi); grid on; % axis([-2,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Degrees'); %axis([-200,200,0,2]); subplot('2,2,2'); plot(w/pi, realX_DTFT); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w/pi, imagX_DTFT); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DTFT's mag ang real imag
%% -------------------------------------------------------------- %% --------------------------------------------------------------
%% START X_DFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Example5.7 X_DFT its Magnitude and Angle');
set(gcf,'Color','white');
subplot(2,1,1); stem(n,magX_DFT); hold on; plot(4*w/pi,magX_DTFT,'--'); hold off;
grid on; axis([-0.5,8.2,-1,5]);
title('Magnitude Part of the DFT: N = 8');
xlabel('k'); ylabel('Magnitude |X\_DFT|');
subplot(2,1,2); stem(n, phaX_DFT); hold on; plot(4*w/pi,angX_DTFT*180/pi,'--'); hold off;
grid on; axis([-0.5,8.2,-200,200]);
title('Angle Part of the DFT: N = 8');
xlabel('k'); ylabel('Degrees'); %axis([-200,200,0,2]); %subplot('2,2,2'); stem(n, realX_DFT); grid on;
%title('Real Part');
%xlabel('frequency in \pi units'); ylabel('Real');
%subplot('2,2,4'); stem(n, imagX_DFT); grid on;
%title('Imaginary Part');
%xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DFT's mag ang real imag
%% --------------------------------------------------------------
结果:




将序列末尾补12个零,长度达到16位
代码:
x = [1, 1, 1, 1, zeros(1,12)]; % append 12 zeros to the end of x(n)
N = 16; % zero-padding operation
X_DFT = dft(x,N); % DFT of x(n) magX_DFT = abs(X_DFT)
phaX_DFT = angle(X_DFT)*180/pi % degrees
realX_DFT = real(X_DFT); imagX_DFT = imag(X_DFT);
angX_DFT = angle(X_DFT); % radias n = 0:(N - 1);
k = 0:1000; w = (pi/500)*k; % [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); figure('NumberTitle', 'off', 'Name', 'Exameple5.7 x sequence')
set(gcf,'Color','white');
stem(n,x); title('x sequence, N = 16'); axis([0,N,-0.5,1.5]);
xlabel('n'); ylabel('x(n)'); grid on; %% --------------------------------------------------------------
%% START X_DTFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'X_DTFT its Magnitude and Angle, Real and Imaginary Part');
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi,magX_DTFT); grid on; % axis([-2,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |X\_DTFT|');
subplot(2,2,3); plot(w/pi, angX_DTFT*180/pi); grid on; % axis([-2,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Degrees'); %axis([-200,200,0,2]); subplot('2,2,2'); plot(w/pi, realX_DTFT); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w/pi, imagX_DTFT); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DTFT's mag ang real imag
%% -------------------------------------------------------------- %% --------------------------------------------------------------
%% START X_DFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Example5.7 X_DFT its Magnitude and Angle');
set(gcf,'Color','white');
subplot(2,1,1); stem(n,magX_DFT); hold on; plot(8*w/pi,magX_DTFT,'--'); hold off;
grid on; axis([-0.5,16.2,-1,5]);
title('Magnitude Part of the DFT: N = 16');
xlabel('k'); ylabel('Magnitude |X\_DFT|');
subplot(2,1,2); stem(n, phaX_DFT); hold on; plot(8*w/pi,angX_DTFT*180/pi,'--'); hold off;
grid on; axis([-0.5,16.2,-200,200]);
title('Angle Part of the DFT: N = 16');
xlabel('k'); ylabel('Degrees'); %axis([-200,200,0,2]); %subplot('2,2,2'); stem(n, realX_DFT); grid on;
%title('Real Part');
%xlabel('frequency in \pi units'); ylabel('Real');
%subplot('2,2,4'); stem(n, imagX_DFT); grid on;
%title('Imaginary Part');
%xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DFT's mag ang real imag
%% --------------------------------------------------------------
结果:


继续补零,长度N=128,
代码:
x = [1, 1, 1, 1, zeros(1,124)]; % append 124 zeros to the end of x(n)
N = 128; % zero-padding operation
X_DFT = dft(x,N); % DFT of x(n) magX_DFT = abs(X_DFT)
phaX_DFT = angle(X_DFT)*180/pi % degrees
realX_DFT = real(X_DFT); imagX_DFT = imag(X_DFT);
angX_DFT = angle(X_DFT); % radias n = 0:(N - 1);
k = 0:1000; w = (pi/500)*k; % [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); figure('NumberTitle', 'off', 'Name', 'Exameple5.7 x sequence')
set(gcf,'Color','white');
stem(n,x); title('x sequence, N = 128'); axis([0,N,-0.5,1.5]);
xlabel('n'); ylabel('x(n)'); grid on; %% --------------------------------------------------------------
%% START X_DTFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'X_DTFT its Magnitude and Angle, Real and Imaginary Part');
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi,magX_DTFT); grid on; % axis([-2,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |X\_DTFT|');
subplot(2,2,3); plot(w/pi, angX_DTFT*180/pi); grid on; % axis([-2,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Degrees'); %axis([-200,200,0,2]); subplot('2,2,2'); plot(w/pi, realX_DTFT); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w/pi, imagX_DTFT); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DTFT's mag ang real imag
%% -------------------------------------------------------------- %% --------------------------------------------------------------
%% START X_DFT's mag ang real imag
%% --------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Example5.7 X_DFT its Magnitude and Angle');
set(gcf,'Color','white');
subplot(2,1,1); stem(n,magX_DFT); hold on; plot(64*w/pi,magX_DTFT,'--'); hold off;
grid on; axis([-0.5,128.2,-1,5]);
title('Magnitude Part of the DFT: N = 128');
xlabel('k'); ylabel('Magnitude |X\_DFT|');
subplot(2,1,2); stem(n, phaX_DFT); hold on; plot(64*w/pi,angX_DTFT*180/pi,'--'); hold off;
grid on; axis([-0.5,128.2,-200,200]);
title('Angle Part of the DFT: N = 128');
xlabel('k'); ylabel('Degrees'); %axis([-200,200,0,2]); %subplot('2,2,2'); stem(n, realX_DFT); grid on;
%title('Real Part');
%xlabel('frequency in \pi units'); ylabel('Real');
%subplot('2,2,4'); stem(n, imagX_DFT); grid on;
%title('Imaginary Part');
%xlabel('frequency in \pi units'); ylabel('Imaginary');
%% --------------------------------------------------------------
%% END X_DFT's mag ang real imag
%% --------------------------------------------------------------
运行结果:


《DSP using MATLAB》示例Example5.7的更多相关文章
- 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 ...
- DSP using MATLAB 示例 Example3.19
代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Discrete-time Signa ...
- DSP using MATLAB示例Example3.18
代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Continuous-time Fou ...
- 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 ...
- 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 ...
- DSP using MATLAB 示例Example3.17
- 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, ...
- 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 ...
- 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 ...
- 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 , ...
随机推荐
- TypeScript Writing .d.ts files(编写声明文件)
当使用扩展的JavaScript库或者插件API的时候,将需要使用声明文件(.d.ts)来描述库的类型.本文内容将包括如何编写声明文件相关的一些高级概念,然后用一些例子来展示如何将各式各样的概念与声明 ...
- <<< tomcat启动报错StandardServer.await: create[8005]
启动tomcat的时候出现异常 严重: StandardServer.await: create[8005]: java.net.BindException: Address already in u ...
- 如何夯实(Java)编程基础,并深入学习和提高
如何夯实(Java)编程基础,并深入学习和提高? 240赞同反对,不会显示你的姓名 匿名用户 240 人赞同 多学习...网上自学的学习网站很多,见以下榜单~一.汇总榜单: 公开课_学习网站导航 收录 ...
- Java开发的基础条件:
------------Java开发的基础条件:Java相关的基础+对编程的自己的理解+调试代码+自己的坚持 一定要谦逊,不人云亦云,不去妄言某一门语言或技术好或坏!不是哪门技术有问题,而是(不会用才 ...
- Java排序算法——基数排序
- [NHibernate]存储过程的使用(三)
目录 写在前面 文档与系列文章 查询 总结 写在前面 前面的文章介绍了在nhibernate中使用存储过程进行增删改的操作,当然查询也是可以的,在nhibernate中也可以执行任意的存储过程.本篇文 ...
- NPM
参考资料: 淘宝NPM
- log4j的使用详细解析
1 Log4j配置说明 1.1 配置文件Log4j可以通过java程序动态设置,该方式明显缺点是:如果需要修改日志输出级别等信息,则必须修改java文件,然后重新编译,很是麻烦: log4j也可以通过 ...
- Java实现Excel的操作
JAVA EXCEL API: 开源项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该API非Windows操作系统也可以通过纯Ja ...
- Linux进程间通信(五):信号量 semget()、semop()、semctl()
这篇文章将讲述别一种进程间通信的机制——信号量.注意请不要把它与之前所说的信号混淆起来,信号与信号量是不同的两种事物.有关信号的更多内容,可以阅读我的另一篇文章:Linux进程间通信 -- 信号.下面 ...