[filename,pathname]=uigetfile('*.wav','choose a audio file:')
[wavin,fs,nbits]=wavread([pathname filename])
wav_l=length(wavin) %采样点数,length()返回烂旅值是标量
frame_l=0.04*fs %根据fs选择帧长,
step_l=floor(0.5*frame_l)%设置帧移
num_frame=floor((wav_l-frame_l)/step_l)+1%确定帧数
win_ham=hamming(frame_l)%在做fft之前,为移除直流分量和加重高频分量,采用汉明窗,对信号进行加权
%加窗处理用亮含来消除分帧时带来的截断效应
%加窗,分帧(矩阵每一行为一帧)
for i=1:num_frame
n1=(i-1)*step_l+1
n2=(i-1)*step_l+frame_l
zy(i,:)=(win_ham').*(yt(n1:n2)') %存储每一帧噪音(行向量) %win_ham、yt是列向量,需转置
yy(i,:)=(win_ham').*(wavin(n1:n2)')%存储每一帧纯敬历笑净语音
end
先说第一段晌烂k 是从WAV文件读取出来的一段语音信号,其实就是一个h点的行向量,h是k的长度。
设置了一个门限值th=0.035。对向量k,从头开始每个点依次与门限值比较,第一个幅度大于0.035的点记为语音起点i,从尾开始每个点依次与门限值比较,第一个幅度大于0.035的点记为语音终点j。
将k的语音部分新命名为new,把原始语念谨差音和找到的纯语音分别在两个坐标中画出。
总的来说,这段程序用很简便的方法将一段包含静音的语音信号中的仔皮纯语音提取出来,但这种方法有很大的局限性,只能作为理论学习,基本上没有实际应用价值
%在噪声环境下语音信号的增强%语音信号为读入的声音文件
%噪声为正态随机噪声
sound=wavread('c12345.wav')
count1=length(sound)
noise=0.05*randn(1,count1)
for i=1:count1
signal(i)=sound(i)
end
for i=1:count1
y(i)=signal(i)+noise(i)
end
%在小波基'db3'下进行渗拆乎一维离散小波变换
[coefs1,coefs2]=dwt(y,'db3')%[低频 高频]
count2=length(coefs1)
count3=length(coefs2)
energy1=sum((abs(coefs1)).^2)
energy2=sum((abs(coefs2)).^2)
energy3=energy1+energy2
for i=1:count2
recoefs1(i)=coefs1(i)/energy3
end
for i=1:count3
recoefs2(i)=coefs2(i)/energy3
end
%低频系数进行语音信号清浊音的判别
zhen=160
count4=fix(count2/zhen)
for i=1:count4
n=160*(i-1)+1:160+160*(i-1)
s=sound(n)
w=hamming(160)
sw=s.*w
a=aryule(sw,10)
sw=filter(a,1,sw)
sw=sw/sum(sw)
r=xcorr(sw,'御念biased')
corr=max(r)
%为清音(unvoice)时,输出为1;为浊音(voice)时,输出为0
if corr>=0.8
output1(i)=0
elseif corr<=0.1
output1(i)=1
end
end
for i=1:count4
n=160*(i-1)+1:160+160*(i-1)
if output1(i)==1
switch abs(recoefs1(i))
case abs(recoefs1(i))<=0.002
recoefs1(i)=0
case abs(recoefs1(i))>0.002 &abs(recoefs1(i))<=0.003
recoefs1(i)=sgn(recoefs1(i))*(0.003*abs(recoefs1(i))-0.000003)/0.002
otherwise recoefs1(i)=recoefs1(i)
end
elseif output1(i)==0
recoefs1(i)=recoefs1(i)
end
end
%对高频系丛悉数进行语音信号清浊音的判别
count5=fix(count3/zhen)
for i=1:count5
n=160*(i-1)+1:160+160*(i-1)
s=sound(n)
w=hamming(160)
sw=s.*w
a=aryule(sw,10)
sw=filter(a,1,sw)
sw=sw/sum(sw)
r=xcorr(sw,'biased')
corr=max(r)
%为清音(unvoice)时,输出为1;为浊音(voice)时,输出为0
if corr>=0.8
output2(i)=0
elseif corr<=0.1
output2(i)=1
end
end
for i=1:count5
n=160*(i-1)+1:160+160*(i-1)
if output2(i)==1
switch abs(recoefs2(i))
case abs(recoefs2(i))<=0.002
recoefs2(i)=0
case abs(recoefs2(i))>0.002 &abs(recoefs2(i))<=0.003
recoefs2(i)=sgn(recoefs2(i))*(0.003*abs(recoefs2(i))-0.000003)/0.002
otherwise recoefs2(i)=recoefs2(i)
end
elseif output2(i)==0
recoefs2(i)=recoefs2(i)
end
end
%在小波基'db3'下进行一维离散小波反变换
output3=idwt(recoefs1, recoefs2,'db3')
%对输出信号抽样点值进行归一化处理
maxdata=max(output3)
output4=output3/maxdata
%读出带噪语音信号,存为'101.wav'
wavwrite(y,5500,16,'c101')
%读出处理后语音信号,存为'102.wav'
wavwrite(output4,5500,16,'c102')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)