【 MATLAB 】通过不同样本数的同一个有限长序列作 DTFT 对比

上篇博文我们讨论了:【 MATLAB 】使用 MATLAB 得到高密度谱(补零得到DFT)和高分辨率谱(获得更多的数据得到DFT)的方式对比(附MATLAB脚本)

可是还是觉得不过瘾,还有下面的情况需要对比。于是就有了这篇博文。

案例:

x(n) = cos(0.48\pi n)+cos(0.52\pi n)

想要基于有限样本数来确定他的频谱。

下面我们分如下几种情况来分别讨论:

a. 求出并画出 x(n), 0 \leq n \leq 9 的DTFT;

b. 求出并画出 x(n), 0 \leq n \leq 99 的DTFT;


clc;clear;close all;

n = 0:99;
x = cos(0.48*pi*n) + cos(0.52*pi*n);

n1 = 0:9;
y1 = x(1:10);

subplot(2,2,1)
stem(n1,y1);
title('signal x(n), 0 <= n <= 9');
xlabel('n');ylabel('x(n) over n in [0,9]');
Y1 = dft(y1,10);
magY1 = abs(Y1);
k1 = 0:1:9;
N = 10;
w1 = (2*pi/N)*k1;

subplot(2,2,2);
% stem(w1/pi,magY1);
% title('DFT of x(n) in [0,9]');
% xlabel('frequency in pi units');

%In order to clearly see the relationship between DTFT and DFT, we draw DTFT on the same picture.


%Discrete-time Fourier Transform
K = 500;
k = 0:1:K;
w = 2*pi*k/K; %plot DTFT in [0,2pi];
X = y1*exp(-j*n1'*w);

magX = abs(X);
% hold on 
plot(w/pi,magX);

% hold off






subplot(2,2,3)
stem(n,x);
title('signal x(n), 0 <= n <= 99');
xlabel('n');ylabel('x(n) over n in [0,99]');
Xk = dft(x,100);
magXk = abs(Xk);
k1 = 0:1:99;
N = 100;
w1 = (2*pi/N)*k1;

subplot(2,2,4);
% stem(w1/pi,magXk);
% title('DFT of x(n) in [0,99]');
% xlabel('frequency in pi units');

%In order to clearly see the relationship between DTFT and DFT, we draw DTFT on the same picture.


%Discrete-time Fourier Transform
K = 500;
k = 0:1:K;
w = 2*pi*k/K; %plot DTFT in [0,2pi];
X = x*exp(-j*n'*w);

magX = abs(X);

hold on 
plot(w/pi,magX);

hold off


可见,b问这种情况,拥有x(n)的更多数据,所以得到的DTFT更加的准确,正如我们所料,频谱在w = 0.48pi以及0.52pi处取得峰值。而a问中的图就看不出这种关系,因为获得序列数据太少,已经严重影响到了频谱的形状。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李锐博恩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值