《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 , ...
随机推荐
- codevs 1772 歌词
1772 歌词 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 35痛过以后才知情已难寻吾爱至斯只剩飞花梦影回 ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- 【转】javascript面向对象编程
摘要:本文本来是想自己写的,奈何花了好长时间写好之后忘记保存,还按了刷新键,一键回到解放前,索性不写了,所以本文是转载的. 面向对象编程是用抽象方式创建基于现实世界模型的一种编程模式,主要包括模块化. ...
- jQuery 复习
jQuery 复习 基础知识 1, window.onload $(function(){}); $(document).ready(function(){}); 只执行函数体重的最后一个方法,事 ...
- C#------连接SQLServer和MySQL字符串
<connectionStrings> <add name="ConnectionStrings" connectionString="Data Sou ...
- Java 数据库操作类
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...
- mysql常用操作语句
mysql常用操作语句 1.mysql -u root -p 2.mysql -h localhost -u root -p database_name 2.列出数据库: 1.show datab ...
- [NHibernate]缓存(NHibernate.Caches)
系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 [NHibernate]持久化类(Persistent Classes) [NHibernate ...
- [Nhibernate]SchemaExport工具的使用(一)——通过映射文件修改数据表
目录 写在前面 文档与系列文章 SchemaExport工具 SchemaUpdate工具 一个例子 总结 写在前面 上篇文章介绍了使用代码生成器的nhibernate模版来生成持久化类,映射文件等内 ...
- git版本控制管理实践-2
给网站设置一个 "根目录下的logo.ico", 还是很有必要的,比如赶集网,这时在 "历史"搜索时, 就可以根据 网站的 logo.ico 很轻松的就能够找到 ...