1. 程式人生 > >【 MATLAB 】使用 MATLAB 比較佔空比不同的週期方波的 DFS 圖

【 MATLAB 】使用 MATLAB 比較佔空比不同的週期方波的 DFS 圖

週期方波的表示式我就不提煉了,既然你來看文章了,我就不信你週期方波都不知道。

佔空比定義為:L/N,N為週期,下面我們對 L = 5,N = 20; L = 5,N = 40;L = 5,N = 60;L = 7,N = 60分別畫出它們的DFS圖作比較。

我覺得有必要先把對應的週期方波給出來(每幅圖都只給出一個週期):

clc;clear;close all;


% Periodic square wave parameters L = 5,N = 20
L = 5;
N = 20;
n = 0:N-1;
xn = [ones(1,L),zeros(1,N-L)];

subplot(2,2,1)
stem(n,xn);
title('L = 5,N = 20');
xlabel('n');ylabel('xtilde(n)');


% Periodic square wave parameters L = 5,N = 40
L = 5;
N = 40;
n = 0:N-1;
xn = [ones(1,L),zeros(1,N-L)];

subplot(2,2,2)
stem(n,xn);
title('L = 5,N = 20');
xlabel('n');ylabel('xtilde(n)');


% Periodic square wave parameters L = 5,N = 60
L = 5;
N = 60;
n = 0:N-1;
xn = [ones(1,L),zeros(1,N-L)];

subplot(2,2,3)
stem(n,xn);
title('L = 5,N = 20');
xlabel('n');ylabel('xtilde(n)');



% Periodic square wave parameters L = 7,N = 60
L = 7;
N = 60;
n = 0:N-1;
xn = [ones(1,L),zeros(1,N-L)];
subplot(2,2,4)
stem(n,xn);
title('L = 5,N = 20');
xlabel('n');ylabel('xtilde(n)');

直接給出MATLAB指令碼:

clc;clear;close all;


% Periodic square wave parameters L = 5,N = 20
L = 5;
N = 20;
k = [-N/2:N/2];

xn = [ones(1,L),zeros(1,N-L)];
Xk = dfs(xn,N);
magXk = abs( [ Xk(N/2+1:N),Xk(1:N/2+1) ] );
subplot(2,2,1)
stem(k,magXk);
title('DFS of Square: L = 5,N = 20');
xlabel('k');ylabel('Xtilde(k)');


% Periodic square wave parameters L = 5,N = 40
L = 5;
N = 40;
k = [-N/2:N/2];

xn = [ones(1,L),zeros(1,N-L)];
Xk = dfs(xn,N);
magXk = abs( [ Xk(N/2+1:N),Xk(1:N/2+1) ] );
subplot(2,2,2)
stem(k,magXk);
title('DFS of Square: L = 5,N = 40');
xlabel('k');ylabel('Xtilde(k)');


% Periodic square wave parameters L = 5,N = 60
L = 5;
N = 60;
k = [-N/2:N/2];

xn = [ones(1,L),zeros(1,N-L)];
Xk = dfs(xn,N);
magXk = abs( [ Xk(N/2+1:N),Xk(1:N/2+1) ] );
subplot(2,2,3)
stem(k,magXk);
title('DFS of Square: L = 5,N = 60');
xlabel('k');ylabel('Xtilde(k)');



% Periodic square wave parameters L = 7,N = 60
L = 7;
N = 60;
k = [-N/2:N/2];

xn = [ones(1,L),zeros(1,N-L)];
Xk = dfs(xn,N);
magXk = abs( [ Xk(N/2+1:N),Xk(1:N/2+1) ] );
subplot(2,2,4)
stem(k,magXk);
title('DFS of Square: L = 7,N = 60');
xlabel('k');ylabel('Xtilde(k)');