语谱图:
所谓语谱图就是语音频谱图,一般是通过处理接收的时域信号得到频谱图,
因此只要有足够时间长度的时域信号就可以(时间长度为保证频率分辨率)。专业点讲,语谱图就是频谱分析视图,如果针对语音数据的话,叫语谱图,语谱图的横坐标是时间,
纵坐标是频率,坐标点值为语音数据能量。
采用二维平面来表达三维信息。所以能量值的大小通过颜色来表示。颜色深表示该点的语音能量越强。
代码实现:
[x, Fs, nBits] = wavread('audio.wav');
specgram(x, 512, Fs, 100);
xlabel('Time(s)');
ylabel('Frequency(Hz)');
title('Spectrogram');
另一种不用specgram函数实现的语谱图画法matlab实现如下:
clear all;
clc
close all;
[x,Fs,nBits]=wavread('audio.wav');
if (size(x,1)>size(x,2))
x=x';
end
s=length(x); % calcualte the length of the signal x.
w=256;
n=w;
ov=w/2;
h=w-ov;
win=hamming(n)';
c=1;
ncols=1+fix((s-n)/h);
%fix:round towards zero. fix(x) rounds the elements of x to the nearest integers towards zero
%for example, if x=1.2345, after m = fix(x), the value of m is 1.
d=zeros((1+n/2),ncols);
for b=0:h:(s-n)
u=win.*x((b+1):(b+n)); % add window to n samples.
t=fft(u); % do fft.
d(:,c)=t(1:(1+n/2))';
c=c+1;
end
tt=[0:h:(s-n)]/Fs;
ff=[0:(n/2)]*Fs/n;
imagesc(tt/1000,ff/1000,20*log10(abs(d)));
colormap(hot);
axis xy
xlabel('时间/s');
ylabel('频率/kHz');