Winsiz = 256; Shift = 32; Base = 0; [Sg , Fs] = wavread('E:\1.wav');
n = floor((length(Sg) - Winsiz)/Shift)+1;%总的帧数
A = zeros(Winsiz/2+1 , n);
for i = 1:n
n1 = (i-1)*Shift + 1;%每帧的帧头
n2 = n1 + Winsiz - 1;%每帧的帧尾
s = Sg(n1:n2); s = s.*hanning(Winsiz);%加窗
z = fft(s);%求fft
z = z(1:(Winsiz/2)+1); z = z.*conj(z);%复数求共轭,并计算能量
z = 10 * log10(z);%得到语谱图的db表示
A(:,i) = z;
end
L0 = (A > Base); L1 = (A < Base);
B = A.*L0 + Base*L1;%滤除db小于0的点
L = (B-Base)./(max(max(B))-Base);%归一化
y = [0:Winsiz/2]*Fs/Winsiz; x = [0:n-1]*Shift/1000;