【 MATLAB 】使用 MATLAB 得到高密度谱(补零得到DFT)和高分辨率谱(获得更多的数据得到DFT)的方式对比(附MATLAB脚本)

版权声明:本博客内容来自于个人学习过程中的总结,参考了互联网、数据手册、帮助文档、书本以及论文等上的内容,仅供学习交流使用,如有侵权,请联系,我会重写!转载请注明地址! https://blog.csdn.net/Reborn_Lee/article/details/83478209

上篇博文分析了同一有限长序列在不同的N下的DFT之间的不同: MATLAB 】使用 MATLAB 作图讨论有限长序列的 N 点 DFT(强烈推荐)(含MATLAB脚本)

那篇博文中,我们通过补零的方式来增加N,这样最后的结论是随着N的不断增大,我们只会得到DTFT上的更多的采样点,也就是说频率采样率增加了。通过补零,得到高密度谱(DFT),但不能得到高分辨率谱,因为补零并没有任何新的信息附加到这个信号上,要想得到高分辨率谱,我们就得通过获得更多的数据来进行求解DFT。

这篇博文就是为此而写。

案例:

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

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

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

a. 求出并画出 x(n), 0 \leq n \leq 9 ,N = 10 的DFT以及DTFT;

b. 对上一问的x(n)通过补零的方式获得区间[0,99]上的x(n),画出 N = 100点的DFT,并画出DTFT作为对比;

c.求出并画出 x(n), 0 \leq n \leq 99 ,N = 100 的DFT以及DTFT;

d.对c问中的x(n)补零到N = 500,画出 N = 500点的DFT,并画出DTFT作为对比;

e. 比较c和d这两个序列的序列的DFT以及DTFT的异同。


那就干呗!

题解:

a.

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,1,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,1,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


b.

clc;clear;close all;

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

% zero padding into N = 100
n1 = 0:99;
y1 = [x(1:10),zeros(1,90)];

subplot(2,1,1)
stem(n1,y1);
title('signal x(n), 0 <= n <= 99');
xlabel('n');ylabel('x(n) over n in [0,99]');
Y1 = dft(y1,100);
magY1 = abs(Y1);
k1 = 0:1:99;
N = 100;
w1 = (2*pi/N)*k1;
subplot(2,1,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);
% w = [-fliplr(w),w(2:K+1)];   %plot DTFT in [-pi,pi]
% X = [fliplr(X),X(2:K+1)];    %plot DTFT in [-pi,pi]
magX = abs(X);
% angX = angle(X)*180/pi;
% figure
% subplot(2,1,1);
hold on 
plot(w/pi,magX);
% title('Discrete-time Fourier Transform in Magnitude Part');
% xlabel('w in pi units');ylabel('Magnitude of X');
% subplot(2,1,2);
% plot(w/pi,angX);
% title('Discrete-time Fourier Transform in Phase Part');
% xlabel('w in pi units');ylabel('Phase of X ');
hold off


c.

clc;clear;close all;

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

% n1 = 0:99;
% y1 = [x(1:10),zeros(1,90)];

subplot(2,1,1)
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,1,2);
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);
% w = [-fliplr(w),w(2:K+1)];   %plot DTFT in [-pi,pi]
% X = [fliplr(X),X(2:K+1)];    %plot DTFT in [-pi,pi]
magX = abs(X);
% angX = angle(X)*180/pi;
% figure
% subplot(2,1,1);
hold on 
plot(w/pi,magX);
% title('Discrete-time Fourier Transform in Magnitude Part');
% xlabel('w in pi units');ylabel('Magnitude of X');
% subplot(2,1,2);
% plot(w/pi,angX);
% title('Discrete-time Fourier Transform in Phase Part');
% xlabel('w in pi units');ylabel('Phase of X ');
hold off


太小了,放大看:

d.

clc;clear;close all;

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

% n1 = 0:99;
% y1 = [x(1:10),zeros(1,90)];

%zero padding into N = 500
n1 = 0:499;
x1 = [x,zeros(1,400)];

subplot(2,1,1)
stem(n1,x1);
title('signal x(n), 0 <= n <= 499');
xlabel('n');ylabel('x(n) over n in [0,499]');
Xk = dft(x1,500);
magXk = abs(Xk);
k1 = 0:1:499;
N = 500;
w1 = (2*pi/N)*k1;
subplot(2,1,2);
% stem(w1/pi,magXk);
stem(w1/pi,magXk);
title('DFT of x(n) in [0,499]');
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 = x1*exp(-j*n1'*w);
% w = [-fliplr(w),w(2:K+1)];   %plot DTFT in [-pi,pi]
% X = [fliplr(X),X(2:K+1)];    %plot DTFT in [-pi,pi]
magX = abs(X);
% angX = angle(X)*180/pi;
% figure
% subplot(2,1,1);
hold on 
plot(w/pi,magX,'r');
% title('Discrete-time Fourier Transform in Magnitude Part');
% xlabel('w in pi units');ylabel('Magnitude of X');
% subplot(2,1,2);
% plot(w/pi,angX);
% title('Discrete-time Fourier Transform in Phase Part');
% xlabel('w in pi units');ylabel('Phase of X ');
hold off


e.

clc;clear;close all;

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

subplot(2,1,1)
% 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;
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);
% w = [-fliplr(w),w(2:K+1)];   %plot DTFT in [-pi,pi]
% X = [fliplr(X),X(2:K+1)];    %plot DTFT in [-pi,pi]
magX = abs(X);
% angX = angle(X)*180/pi;
% figure
% subplot(2,1,1);
hold on 
plot(w/pi,magX);
% title('Discrete-time Fourier Transform in Magnitude Part');
% xlabel('w in pi units');ylabel('Magnitude of X');
% subplot(2,1,2);
% plot(w/pi,angX);
% title('Discrete-time Fourier Transform in Phase Part');
% xlabel('w in pi units');ylabel('Phase of X ');
hold off





% clc;clear;close all;
% 
% n = 0:99;
% x = cos(0.48*pi*n) + cos(0.52*pi*n);

% n1 = 0:99;
% y1 = [x(1:10),zeros(1,90)];

%zero padding into N = 500
n1 = 0:499;
x1 = [x,zeros(1,400)];
subplot(2,1,2);
% subplot(2,1,1)
% stem(n1,x1);
% title('signal x(n), 0 <= n <= 499');
% xlabel('n');ylabel('x(n) over n in [0,499]');
Xk = dft(x1,500);
magXk = abs(Xk);
k1 = 0:1:499;
N = 500;
w1 = (2*pi/N)*k1;

stem(w1/pi,magXk);
title('DFT of x(n) in [0,499]');
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 = x1*exp(-j*n1'*w);
% w = [-fliplr(w),w(2:K+1)];   %plot DTFT in [-pi,pi]
% X = [fliplr(X),X(2:K+1)];    %plot DTFT in [-pi,pi]
magX = abs(X);
% angX = angle(X)*180/pi;
% figure
% subplot(2,1,1);
hold on 
plot(w/pi,magX,'r');
% title('Discrete-time Fourier Transform in Magnitude Part');
% xlabel('w in pi units');ylabel('Magnitude of X');
% subplot(2,1,2);
% plot(w/pi,angX);
% title('Discrete-time Fourier Transform in Phase Part');
% xlabel('w in pi units');ylabel('Phase of X ');
hold off

局部放大看:

猜你喜欢

转载自blog.csdn.net/Reborn_Lee/article/details/83478209