STFT短时傅立叶变换程序有问题说我mesh数据维度有问题,求指导
function = STFT(Sig,nLevel,WinLen,SampFreq)
%计算离散信号的短时Fourier变换
% Sig:待分析信号
%nLevel:频率轴长度划分(默认值512)
%WinLen:汉宁窗长度(默认值64)
%SamFreq:信号的采样频率(默认值1)
if(nargin<1),
error ('At least one parameter required!');
end;
Sig = real(Sig);
SigLen=length(Sig);
if(nargin<4),
SampFreq = 1;
end
if(nargin<3),
WinLen=64;
end
if (nargin<2),
nLevel=513;
end
nLevel=ceil(nLevel/2)*2+1;
WinLen=ceil(WinLen/2)*2+1;
WinFun=exp(-6*linspace(-1,1,WinLen).^2);
WinFun=WinFun/norm(WinFun);
Lh=(WinLen-1)/2;
Ln=(nLevel-1)/2;
Spec=zeros(nLevel,SigLen);
wait=waitbar(0,'Under calculation,please wait...');
for iLoop =1:SigLen,
waitbar(iLoop/SigLen,wait);
iLeft=min();
iRight=min();
iIndex=iLeft:iRight;
iIndex1=iIndex+iLoop;
iIndex2=iIndex+Lh+1;
Index=iIndex+Ln+1;
Spec(Index,iLoop)=Sig(iIndex1).*conj(WinFun(iIndex2));
end;
close(wait);
Spec=fft(Spec);
Spec=abs(Spec(1:(end-1)/2,:));
Freq=linspace(0,0.5,(nLevel-1)/2)*SampFreq;
t=(0:(SigLen))/SampFreq;
clf
set(gcf,'Position',);
set(gcf,'Color','w');
axes('Position',);
mesh(t,Freq,Spec);
axis();
colorbar
xlabel('t/s');
ylabel('f/Hz');
title('STFT时频谱图');
axes('Position',);
polt(t,Sig);
axis tight
ylabel('x(t)');
title('时域波形');
axes('Position',);
PSP=abs(fft(Sig));
Freq=linspace(0,1,SigLen)*SampFreq;
plot(PSP(1:end/2),Freq(1:end/2));
tiltle('频谱');
SampFreq = 100;
t = 0:1/SampFreq:5;
Sig=sin(2*pi*(5*t+4*t.^2));
Sig=Sig+sin(2*pi*(45*t-4*t.^2));
STFT(Sig,512,128,100);
上面的这个是要画的函数..
数据没有一一对应吧 学习了~~~ 提示你索引超出维度了吗 注意数据矩阵的对应关系
页:
[1]