使用matlab判断男声与女声

(转自) http://wenku.baidu.com/view/1d55480fbe1e650e52ea99a3.html

%filename:manwoman.m
%different man from woman.
%===========================================================
clear;
% [x,fs,bits]=wavread('d.wav', [1 5000]);       % 读入声音文件(*.wav)  
[x,fs,bits]=wavread('d.wav', [5000 10944]);       % 读入声音文件(*.wav) 
sound(x,fs,bits);                % 数据通过声卡转换为声音
%===========================================================
% pause;
data1=x(:,1);
n=0:length(x)-1;
time=n/fs;
subplot(3,1,1)                                        % 绘制2行1列的第1张子图
plot(time,data1)                                      % 以时间为横轴,数据为纵轴作图
xlabel('Time (sec.)')                                 % 标注横坐标
ylabel('Signal Level (Volts)')                        % 标注纵坐标
grid on                                               % 添加网格
% pause;
% 对采集数据作滤波处理
blocksize =length(data1);                             % 计算窗函数长度 
window = hanning(blocksize);                   % 计算汉宁窗函数(此函数为MATLAB自带)
data2=window.*data1;                                  % 对数据先作加窗处理
% wp=[70,400];                                             %100Hz--400Hz
% wp=wp*2/fs;
wp=3000*2/fs;
[b,a]=ellip(4,0.1,20,wp);                      % 构造椭圆滤波器
data=filter(b,a,data2);                               % 求加窗处理后的数据经过滤波器的响应
subplot(3,1,2)                                        % 绘制2行1列的第1张子图
plot(time,data)                                      % 以时间为横轴,数据为纵轴作图
xlabel('Time (sec.)')                                 % 标注横坐标
%ylabel('Signal Level (Volts)')                        % 标注纵坐标
grid on                                               % 添加网格
% pause;
[xmax,index]=max(data1);
timewin=floor(0.015*fs);
xwin=data1(index-timewin:index+timewin);
[y,lags]=xcov(xwin);
subplot(3,1,3)
plot(lags,y)
grid on
ylen=length(y);
halflen=(ylen+1)/2 +30;
yy=y(halflen: ylen);
[ymax,maxindex] = max(yy);
fmax=fs/(maxindex+30);
disp(['Maximum occurred at ', num2str(fmax), ' Hz'])

f=fmax;
justify=f;   %Hz
if justify<180  %limitHz以下判断是男的
    display '男'
else
    display '女'
end

posted @ 2015-05-04 16:31  aprial  阅读(1493)  评论(0编辑  收藏  举报