Pages

2011年3月13日 星期日

[通訊] 頻譜及相位的模擬

用Matlab模擬頻譜及相位時,可依照以下步驟:
(1)確定時域觀察區間。
(2)由時域觀察區間得取樣點數。
(3)依據取樣點數規劃頻譜橫軸的刻度。

以下matlab程式碼,可以觀察sinc函數的頻譜及相位:
-----------------------------------------------
%%This code was written by Uncle.
%%This code can perform DFT operation, and observe the phase spectrum of the signal.
fs = 250;
T = (1/200);
dt = (1/fs);
t = [-5:dt:5]; %觀察區間在-5~+5之間。
x_t = sinc(t/T);

N = length(x_t); %或者N = length(t)也可以。

F_t = fft(x_t,N)*dt;
F_t = fftshift(F_t);

df = fs/(N-1);
f = [0:df:fs] - fs/2;

p_f = angle(F_t); %還沒取abs之前就要先取相位。

subplot(2,1,1)
plot(f,abs(F_t))
subplot(2,1,2)
plot(f,p_f)
%end

----------------------------------------------

沒有留言:

張貼留言