1、满足下面三个条件,不会产生泄漏
. 采样频率是信号频率的整数倍
. 截取时间包含了各信号分量周期的整数倍
. 不补零
以信号
为例,
这个信号当中包含频率为100Hz,50Hz和25Hz的三个分量,相应的周期为0.01s,0.02s和0.04s。
使用采样频率
采样时间0.16s
上述设置满足了不产生频谱泄漏的三个条件。
Matlab代码如下:
clf clc clear N=64; fs=400 T=0.16 N_sample=T*fs ts=0:1/fs:(T-1/fs) x=cos(2*pi*100*ts)+sin(2*pi*50*ts)+cos(2*pi*25*ts) n=0:1/fs:((N_sample-1)/fs) scatter(n,x,'k');hold on; plot(n,x,'r'); clf y1_dft=dft1(x,N) n=0:fs/N:(fs-fs/N); stem(n,abs(y1_dft));%do not use plot here |
时域波形如下:
截取时间长度为信号的3个周期
DFT结果如下:
可以看出,没有产生频谱泄漏。
2、不满足这三个条件,将产生频谱泄漏
2.1 采样时间0.18秒,25Hz的分量采样4.5个周期。
clf clc clear fs=400 T=0.18 N_sample=T*fs N=N_sample ts=0:1/fs:(T-1/fs) x=cos(2*pi*100*ts)+sin(2*pi*50*ts)+cos(2*pi*25*ts) n=0:1/fs:((N_sample-1)/fs) scatter(n,x,'k');hold on; plot(n,x,'r'); clf y1_dft=dft1(x,N) n=0:fs/N:(fs-fs/N); stem(n,abs(y1_dft));%do not use plot here |
由于25Hz的信号不是整周期采样,频谱泄漏很明显。
2.2 采样时间0.16秒,补充192个零采样点。
Matlab代码:
clf clc clear N=256; Ts_mul_32=2 y1=ones(1,N/8*Ts_mul_32) fs=400 T=0.08*Ts_mul_32 N_sample=T*fs ts=0:1/fs:(T-1/fs) x=cos(2*pi*100*ts)+sin(2*pi*50*ts)+cos(2*pi*25*ts) n=0:1/fs:((N_sample-1)/fs) add_zero=zeros(1,N*(1-Ts_mul_32/8)); y1_rec =[x.*y1 add_zero]; n=0:1/fs:((N-1)/fs) scatter(n,y1_rec,'k');hold on plot(n,y1_rec,'g'); hold on; clf y1_dft=dft1(y1_rec,N) n=0:fs/N:(fs-fs/N); stem(n,abs(y1_dft)) |
时序数据图形如下:
DFT结果如下:
补零之后,产生了明显的频谱泄露。
2.3 采样频率不是信号分量的整数倍。
采样频率修改为410,DFT结果如下:
3. 频谱泄漏对IDFT结果的影响
产生频谱泄漏后,DFT结果再进行IDFT,还会得到原信号吗?
3.1 对不产生频谱泄漏的DFT进行反变换
对第1章的产生的信号进行DFT和IDFT。
Matlab代码
clf clc clear fs=410 T=0.16 N_sample=T*fs N=N_sample; ts=0:1/fs:(T-1/fs) x=cos(2*pi*100*ts)+sin(2*pi*50*ts)+cos(2*pi*25*ts) n=0:1/fs:((N_sample-1)/fs) y1_dft=dft1(x,N) n=0:fs/N:(fs-fs/N); stem(n,abs(y1_dft));%do not use plot here y1_idft=idft(y1_dft,N)/N n=0:1/fs:((N_sample-1)/fs) subplot(211) scatter(n,x,'k');hold on; plot(n,x,'r'); subplot(212) scatter(n,y1_idft,'k');hold on; plot(n,y1_idft,'r'); |
时域数据波形如下,上图为原始数据采样,下图为数据经过DFT和IDFT后结果,可以看出IDFT结果与原数据结果完成相同。
3.2 对产生频谱泄漏的DFT进行反变换
对2.2节产生的信号进行DFT和IDFT操作。
clf y1_idft=idft(y1_dft,N)/N |
将IDFT的结果和原始数据做差,误差很小。尽管有频谱泄漏,原始信号还是很好地恢复了。
频谱泄漏的影响对IDFT不是那么大(可能是信号成分相对小,信号比较简单),但是对频域信号的分析影响比较大。
以2.2节的第2个图为例,旁瓣的幅度已经比较大。如果信号中包含的有用信号分量也落在这个范围里面,有用信号的频谱将受到较大的干扰。
4. 时域加窗处理
没有不加窗的操作,自然的截取数据相当于加矩形窗。
加矩形窗后,数据块之间就会出现不连续。对这样的数据块进行DFT分析后,引入了频谱泄漏。为了避免不连续带来的频谱泄漏,就使用窗口函数来解决这个问题。窗口函数的共同特点是,确保信号在块的开头和结尾处为零或者几乎为零。加了窗之后,数据有了0的过渡,显得连续了。
加窗的过程中,时域当中的每个点都要乘以相应的窗口系数。加窗之后,时域信号在每个采样块的开头淡入,结尾淡出。
加矩形窗,hamming窗和blackman窗的代码如下:
clf clc clear N=256; Ts_mul_32=2 y1=ones(1,N/8*Ts_mul_32) y2=hamming(N/8*Ts_mul_32); y2=y2' y3=blackman(N/8*Ts_mul_32); y3=y3' fs=400 T=0.08*Ts_mul_32 N_sample=T*fs ts=0:1/fs:(T-1/fs) x=cos(2*pi*100*ts)+sin(2*pi*50*ts)+cos(2*pi*25*ts) n=0:1/fs:((N_sample-1)/fs) scatter(n,x,'k');hold on plot(n,x,'r'); clf add_zero=zeros(1,N*(1-Ts_mul_32/8)); y_0 =[x add_zero]; y1_rec =[x.*y1 add_zero]; y2_hamming =[x.*y2 add_zero]; y3_blackman =[x.*y3 add_zero]; n=0:1/fs:((N-1)/fs) scatter(n,y_0,'k');hold on plot(n,y_0,'r'); hold on; plot(n,y1_rec,'g'); hold on; clf y1_dft=dft1(y1_rec,N) y2_dft=dft1(y2_hamming,N) y3_dft=dft1(y3_blackman,N) n=0:fs/N:(fs-fs/N); subplot(311); scatter(n,abs(y1_dft),'k');hold on plot(n,abs(y1_dft)) subplot(312); scatter(n,abs(y2_dft),'k');hold on plot(n,abs(y2_dft)) subplot(313); scatter(n,abs(y3_dft),'k');hold on plot(n,abs(y3_dft)) clf %plot time domian signal y_original=y1_rec; y1_idft=idft(y1_dft,N)/N y2_idft=idft(y2_dft,N)/N y3_idft=idft(y3_dft,N)/N n=0:1/fs:((N-1)/fs) scatter(n,y_original,'k');hold on plot(n,y_original,'r'); hold on; plot(n,y1_idft,'g'); hold on; plot(n,y2_idft,'b'); hold on; plot(n,y3_idft,'m'); |
DFT结果如下:
可以看出,加hamming窗和blackman窗有效减小了频谱当中的旁瓣。