?? addwindowdft.m
字號:
% AddWindowDFT
clear;
disp('用DFT對離散信號進行譜分析');
disp('通過選用不同的加窗函數來抑制信號截斷造成的頻譜泄漏');
Repeat = 1;
disp('輸入信號x(n),n為下標');
n = input('n=');
L = length(n);
x = input('x=');
disp(sprintf('輸入截取信號的長度N(即窗長),N<%d',L));
N = input('N=');
x1 = x(1:N);
k = 0:L-1;
Xk = dft(x,L);
Xk1 = dft(x1,L);
figure;
subplot(2,1,1),stem(n,x),title('原始信號');
subplot(2,1,2),stem(k,abs(Xk)),title('原始信號頻譜');
figure;
subplot(2,1,1),stem(n,[x1,zeros(1,L-N)]),title('不加窗的截斷信號');
subplot(2,1,2),stem(k,abs(Xk1)),title('不加窗的信號頻譜');
while Repeat == 1
disp('選擇窗函數');
disp('1:boxcar');
disp('2:triang');
disp('3:hanning');
disp('4:hamming');
disp('5:blackman');
Ans = input('Choose=');
switch Ans
case 1
w = (boxcar(N))';
x2 = x1.*w;
Xk2 = dft(x2,L);
figure;
subplot(2,1,1),stem(n,[x2,zeros(1,L-N)]),title('用boxcar截斷信號');
subplot(2,1,2),stem(k,abs(Xk2)),title('加窗后的信號頻譜');
case 2
w = (triang(N))';
x2 = x1.*w;
Xk2 = dft(x2,L);
figure;
subplot(2,1,1),stem(n,[x2,zeros(1,L-N)]),title('用triang截斷信號');
subplot(2,1,2),stem(k,abs(Xk2)),title('加窗后的信號頻譜');
case 3
w = (hanning(N))';
x2 = x1.*w;
Xk2 = dft(x2,L);
figure;
subplot(2,1,1),stem(n,[x2,zeros(1,L-N)]),title('用hanning截斷信號');
subplot(2,1,2),stem(k,abs(Xk2)),title('加窗后的信號頻譜');
case 4
w = (hamming(N))';
x2 = x1.*w;
Xk2 = dft(x2,L);
figure;
subplot(2,1,1),stem(n,[x2,zeros(1,L-N)]),title('用hamming截斷信號');
subplot(2,1,2),stem(k,abs(Xk2)),title('加窗后的信號頻譜');
case 5
w = (blackman(N))';
x2 = x1.*w;
Xk2 = dft(x2,L);
figure;
subplot(2,1,1),stem(n,[x2,zeros(1,L-N)]),title('用blackman截斷信號');
subplot(2,1,2),stem(k,abs(Xk2)),title('加窗后的信號頻譜');
%otherwise
%disp('請選擇窗函數');
end
Repeat = input('Still want to continue,Yes=1 No=0? Ans=');
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -