📄 wrb1.m
字号:
function wrb1(wavename,noisename,c)
%speech 表示纯净语音时域波形;
%noise 表示噪声;
% c表示判决的数值 经验值通常取2
speech=wavread(wavename);
L=length(speech);
%L表示语音的长度;
t=0:L-1;
subplot(2,1,1);
plot(t,speech,'r');
xlabel('Time(ms)');
ylabel('Magnitude of speech');
title('Time domain of speech');
hold on
%noise表示噪声;
noise=wavread(noisename);
noise1=noise(1:L);
%noise1表示对噪声的截断和纯净语音有相同的长度;
subplot(2,1,2);
plot(t,noise1,'r');
xlabel('Time(s)');
ylabel('Magnitude of noise1');
title('Time domain of noise1');
figure;
speechnoise=speech+noise1;
%langguang表示含噪音信号;
subplot(2,1,1);
plot(t,speechnoise);
xlabel('Time (ms)');
ylabel('Magnitude domain of language');
title('Time domain of language');
a=200; % a表示每一桢的桢长为200个点
b=floor(L/a);
for i=0:1:b-1
y=speechnoise(i*a+1:i*a+a);
%每桢为200个点,共411桢
N=200;
yk=fft(y,N);
u=real(yk(1:N/4));
v=imag(yk(1:N/4));
j=i+1;
eplow(j)=sum(u.^2+v.^2);
end
%对200个点进行求和
%eplow 表示低频的能量
subplot(2,1,2);
j=1:b;
plot(j,eplow,'r-');
xlabel('Frame of total 411');
ylabel('eplow power of every frame');
axis([0,412,0,1500]);
title('The Power Envelope of low frequency') ;
figure;
for i=0:b-1
y=speechnoise(i*a+1:i*a+a);
%每桢为200个点,共411桢
N=200;
yk=fft(y,N);
m=real(yk((N/4)+1:N/2));
n=imag(yk((N/4)+1:N/2));
j=i+1;
ephigh(j)=sum(m.^2+n.^2);
end
%对200个点进行求和
%ephigh表示高频的能量;
subplot(2,1,1);
j=1:b;
plot(j,ephigh,'r-');
xlabel('Frame of total 411');
ylabel('ephigh power of every frame');
title('The Power Envelope of high frequency');
figure;
%对含有语音的信号进行检测
for i=0:1:9
y=speechnoise(i*a+1:i*a+a);
%取前十桢,对起始噪声进行均值估计,确定门限值;
N=200;
yk=fft(y,N);
u=real(yk(1:N/4));
v=imag(yk(1:N/4));
j=i+1;
eplow1(j)=sum(u.^2+v.^2);
end
TH=sum(eplow1)/10;%TH表示门限
%对语音进行判决;
K=0;
%c表示经验值
for i=0:1:b-1
y=speechnoise(i*a+1:i*a+a);
%每桢为200个点,共411桢
N=200;
yk=fft(y,N);
u=real(yk(1:N/4));
v=imag(yk(1:N/4));
j=i+1;
eplow2(j)=sum(u.^2+v.^2);
if (eplow2(j)>c*TH)
K=K+1;
eplow3(K)=eplow2(j);%eplow3表式示超过门限的全部值
ep(K)=i;%ep表示的超过门限所对应的点
end
end
k=1:K;
subplot(2,1,1);
plot(k,eplow3,'r');%所有超过门限的能量幅值图;
xlabel('frame');
ylabel('Magnitude of power')
subplot(2,1,2);
plot(k,ep,'r'); %所有超过门限的桢图;
xlabel('Number of frame');
ylabel('frame');
figure;
speechnoise=speech+noise1;
%speechnoise表示含噪音信号;
subplot(2,1,1);
plot(t,speechnoise);
xlabel('Time (ms)');
ylabel('Magnitude domain of language');
title('Time domain of language');
hold on;
%根据判决结果对含有语音的部分进行标识;
x=0;
for k=2:K;
if (ep(k)-ep(k-1))>4
x=x+1;
ep1(x)=ep(k);
ep2(x)=ep(k-1);
end
end
q=-1:0.001:0.8;
for X=1:x-1
plot(ep1(X)*a,q,'r');
plot(ep2(X+1)*a,q,'r');
p=ep1(X)*a:ep2(X+1)*a;
plot(p,0.8,'r');
hold on;
end
plot(ep(1)*a,q,'r');
plot(ep2(1)*a,q,'r');
p=ep(1)*a:ep2(1)*a;
plot(p,0.8,'r');
plot(ep1(X)*a,q,'r');
plot(ep(K)*a,q,'r');
w=ep1(X)*a:ep(K)*a;
plot(w,0.8,'r');
figure;
%对speechnoise进行降噪处理
%取200个点做为噪声的平均功率谱估计
i=0;
y=speechnoise(i*a+1:i*a+a);
N=200;
yk1=fft(y,N);
u1=real(yk1(1:N/2));
v1=imag(yk1(1:N/2));
epl=u1.^2+v1.^2;
TH1=sum(epl)/100 ; %噪声的估计的平均值
for i=0:1:b-1
y=speechnoise(i*a+1:i*a+a);
%每桢为200个点,共411桢
N=200;
yk=fft(y,N);
u=real(yk(1:N/2));
v=imag(yk(1:N/2));
epl1=u.^2+v.^2-0.8*TH1;
yk1=epl1.^0.5; %yk1表示的输入纯净语音信号频域;
N=200;
y1=ifft(yk1,N);
w=real(y1(1:a));
m=imag(y1(1:a));
tt=i*a+1:i*a+a;
subplot(2,1,1);
plot(tt,(w.^2+m.^2)*0.5,'r');
hold on
plot(tt,-(w.^2+m.^2)*0.5,'r');
xlabel('Time of damain (ms)');
ylabel('Magnitude of damain (V)');
title('clean language');
hold on;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -