數(shù)字信號處理中通常是取其有限的時間片段進行分析,而不是對無限長的信號進行測量和運算。具體做法是從信號中截取一個時間片段,然后對信號進行傅里葉變換、相關(guān)分析等數(shù)學(xué)處理。信號的截斷產(chǎn)生了能量泄漏,而用FFT算法計算頻譜又產(chǎn)生了柵欄效應(yīng),從原理上講這兩種誤差都是不能消除的。在FFT分析中為了減少或消除頻譜能量泄漏及柵欄效應(yīng),可采用不同的截取函數(shù)對信號進行截短,截短函數(shù)稱為窗函數(shù),簡稱為窗。
泄漏與窗函數(shù)頻譜的兩側(cè)旁瓣有關(guān),對于窗函數(shù)的選用總的原則是,要從保持最大信息和消除旁瓣的綜合效果出發(fā)來考慮問題,盡可能使窗函數(shù)頻譜中的主瓣寬度應(yīng)盡量窄,以獲得較陡的過渡帶;旁瓣衰減應(yīng)盡量大,以提高阻帶的衰減,但通常都不能同時滿足這兩個要求。頻譜中的如果兩側(cè)瓣的高度趨于零,而使能量相對集中在主瓣,就可以較為接近于真實的頻譜。不同的窗函數(shù)對信號頻譜的影響是不一樣的,這主要是因為不同的窗函數(shù),產(chǎn)生泄漏的大小不一樣,頻率分辨能力也不一樣。信號的加窗處理,重要的問題是在于根據(jù)信號的性質(zhì)和研究目的來選用窗函數(shù)。圖1是幾種常用的窗函數(shù)的時域和頻域波形,其中矩形窗主瓣窄,旁瓣大,頻率識別精度最高,幅值識別精度最低,如果僅要求精確讀出主瓣頻率,而不考慮幅值精度,則可選用矩形窗,例如測量物體的自振頻率等;布萊克曼窗主瓣寬,旁瓣小,頻率識別精度最低,但幅值識別精度最高;如果分析窄帶信號,且有較強的干擾噪聲,則應(yīng)選用旁瓣幅度小的窗函數(shù),如漢寧窗、三角窗等;對于隨時間按指數(shù)衰減的函數(shù),可采用指數(shù)窗來提高信噪比。表1 是幾種常用的窗函數(shù)的比較。 如果被測信號是隨機或者未知的,或者是一般使用者對窗函數(shù)不大了解,要求也不是特別高時,可以選擇漢寧窗,因為它的泄漏、波動都較小,并且選擇性也較高。但在用于校準(zhǔn)時選用平頂窗較好,因為它的通帶波動非常小,幅度誤差也較小。
表1 幾種常用的窗函數(shù)的比較
下面是幾種窗函數(shù)歸一化DTFT幅度的MATLAB程序: 附上DTFT函數(shù)(dtft.m): function [ X ] = dtft( x,n,w ) % Computes Discrete-time Fourier Transform % [X] = dtft(x,n,w) % X = DTFT values computed at w.frequencies % x = finite duration sequence over n % n = sample position vector % w = frequency location vector X = x*exp(-j*n'*w); % end
矩形窗: %DTFT of a Rectangular Window, M=10,25,50,101 clc; close all; Hf_1=figure; set(Hf_1,'NumberTitle','off','Name','P0304a'); w=linspace(-pi,pi,501); wtick=[-1:0.5:1]; magtick=[0:0.5:1.1]; % M=10 M=10; n=0:M; x=ones(1,length(n)); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,1); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); ylabel('|X|'); title(['M=10']); set(gca,'XTick',wtick,'YTick',magtick); % M=25 M=25; n=0:M; x=ones(1,length(n)); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,2); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); title(['M=25']); set(gca,'XTick',wtick,'YTick',magtick); % M=50 M=50; n=0:M; x=ones(1,length(n)); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,3); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); ylabel('|X|'); title('M=50'); set(gca,'XTick',wtick,'YTick',magtick); % M=101 M=101; n=0:M; x=ones(1,length(n)); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,4); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); ylabel('|X|'); title(['M=101']);
三角窗: % Triangular Window: % DTFT of a Triangular Window,M = 10,25,50,101 clc; close all; Hf_1=figure; set(Hf_1,'NumberTitle','off','Name','P0304b'); w=linspace(-pi,pi,501); wtick=[-1:0.5:1]; magtick=[0:0.5:1.1]; % M = 10 M=10; n=0:M; x=(1-(abs(M-1-(2*n))/(M+1))); x=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,1); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); ylabel('|X|'); title(['M = 10']); set(gca,'XTick',wtick,'YTick',magtick); % M = 25 M=25; n=0:M; x=(1-(abs(M-1-(2*n))/(M+1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,2); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); title(['M = 25']); set(gca,'XTick',wtick,'YTick',magtick); % M = 50 M=50; n=0:M; x=(1-(abs(M-1-(2*n))/(M+1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,3); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); ylabel('|X|'); title(['M = 50']); set(gca,'XTick',wtick,'YTick',magtick); % M = 100 M=101;n=0:M; x=(1-(abs(M-1-(2*n))/(M+1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,4); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); title(['M = 101']); set(gca,'XTick',wtick,'YTick',magtick);
海寧窗: % Hann Window % DTFT of a Hann Window, M = 10,25,50,101 clc;close all; Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0304c'); w=linspace(-pi,pi,501); wtick=[-1:0.5:1]; magtick=[0:0.5:1.1]; % M = 10 M=10;n=0:M; x=0.5*(1-cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,1); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); ylabel('|X|'); title(['M = 10']); set(gca,'XTick',wtick,'YTick',magtick); % M = 25 M=25;n=0:M; x=0.5*(1-cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,2); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); title(['M = 25']); set(gca,'XTick',wtick,'YTick',magtick); % M = 50 M=50;n=0:M; x=0.5*(1-cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,3); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); ylabel('|X|'); title(['M = 50']); set(gca,'XTick',wtick,'YTick',magtick); % M = 101 M=101;n=0:M; x=0.5*(1-cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,4); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); title(['M = 101']); set(gca,'XTick',wtick,'YTick',magtick);
哈明窗: % Hamming Window: clc; close all; Hf_1=figure; set(Hf_1,'NumberTitle','off','Name','P0304d'); w=linspace(-pi,pi,501); wtick=[-1:0.5:1]; magtick=[0:0.5:1.1]; % M = 10 M=10; n=0:M; x=(0.54-0.46*cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,1); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); ylabel('|X|'); title(['M = 10']); set(gca,'XTick',wtick,'YTick',magtick); % M = 25 M=25; n=0:M; x=(0.54-0.46*cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,2); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); title(['M = 25']); set(gca,'XTick',wtick,'YTick',magtick); % M = 50 M=50; n=0:M; x=(0.54-0.46*cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,3); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi'); ylabel('|X|'); title(['M=50']); set(gca,'XTick',wtick,'YTick',magtick); % M = 101 M=101; n=0:M; x=(0.54-0.46*cos((2*pi*n)/(M-1))); X=dtft(x,n,w); magX=abs(X); magX=magX/max(magX); subplot(2,2,4); plot(w/pi,magX,'LineWidth',1.5); axis([-1 1 0 1.1]); xlabel('\omega/\pi');title(['M=101']); set(gca,'XTick',wtick,'YTick',magtick); |
|