1、短时傅里叶变换mat I ab程序(总2页)本页仅作为文档封面,使用时可以删除This document is for reference only-rar21 year.Marchfunction SpeczFreq=STFT(Sig,nLevel,WinLen,SampFreq)%计算离散信号的短时傅里叶变换;% Sig待分析信号;%nLevel频率轴长度划分(默认值512);%WinLen汉宁窗长度(默认值64);% SampFreq信号的采样频率(默认值1);讦(nargin 1),errorfAt least one parameter required!1);end;Sig=rea
2、l(Sig);SigLe n=length(Sig);if (nargin 4)zSampFreq=l;end讦(nargin 3),WinLen=64;endif (nargin 2),n Level=513;endnLevel=ceil(nLevel/2)*2+l;WinLen=ceil(WinLen/2)*2+l;WinFun=exp(-6*linspace(-l,l/WinLen).A2);WinFun=WinFun/norm(WinFun);Lh=(WinLen-l)/2;Ln 二(n Level-l)/2;Spec=zeros (n Level,SigL en);wait=wait
3、bar(O/Under calculation,please wait.1);for iLoop=l:SigLen,waitbar(iLoop/SigLen,wait);iLeft二min(iLoopl 丄h 丄n);iRight=min( gLen-iLoop丄 h,Ln); ilndex=-iLeft:iRight;ilndexl=il ndex+iLoop;ilndex2=ilndex+Lh+l;lndex=ilndex+L n+1;Spec(lndex,iLoop)=Sig(ilndexl).*conj(WinFun(ilndex2); end;close(wait);Spec=fft
4、(Spec);Spec=abs(Spec(l:(end-l)/2/:);Freq=linspace(0/,(nLevel-l)/2)*SampFreq; t=(O:(SigLen-l)/SampFreq;elfset(gcf; Posit ion1, 20 100 500 430); setfgcf/Color/w1);axesfTosition,!);mesh(t,Freq,Spec);axis(min(t) max(t) 0 max(Freq)J); colorbarxlabel(t/s);ylabelff/Hz);title(STFT 时频谱图);axes(,Position,);plot(t,Sig);axis tightylabelCx(t); title/时域波形J; axesfPositionJ );PSP=abs(fft (Sig);Freq=linspace(0,l,SigLe n)*SampFreq;plot(PSP(l:end/2),Freq(l:end/2); titled 频谱!);