|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
最近看自适应噪声抵消,参考别人的例子,写了个基于基本LMS算法的程序,如下:
% LMS method for noise cancellation
%----------------use audio signal "good morning"--------------------------------------
clear;
clc;
disp(' =========================');
disp(' LMS ');
disp(' =========================');
% --------- Initialization ----------
hord=20;
% ---------- signal and noise generation -----------
s=wavread('sound');
len=length(s);
n=1:len;
v=(sin(0.6*n))'; %噪声
x=(sin(0.6*n-0.8*pi))'; %参考输入
d=s+10*v;
wavwrite(x,15000,16,'daizao');
ws=zeros(hord+1,len-hord);
errs=zeros(len,1);
mus=0.008;
% --------- LMS noise cancellation ---------
for i=hord+1:len-hord
j=i-hord:1:i;
x1=x(j);
ys(i)=ws(:,i)'*x1;
errs(i)=d(i)-ys(i);
q(i)=errs(i)-s(i);
n1=hord+1;n2=len-hord;
Eq(i)=sum(abs(q(i)).^2);
Pq(i)=Eq(i)/(n2-n1);
ws(:,i+1)=ws(:,i)+mus*x1*errs(i);
end
% WAVWRITE(Y,FS,WAVEFILE)
wavwrite(errs,15000,'shuchu');
figure(1)
plot(s),title('original');
figure(2)
plot(d),title('noisy signal');
figure(3)
plot(errs),title('output');
% ERROR EFFICIENCY
figure(4)
plot(Pq),title('error efficency');
figure(5)
plot(ws(10,:)),title('converge line')
上面的程序采用的是在一个wav音频+上了噪声,然后去噪.可是如果我把噪声改成一个wav音频,还用这个方法,得到的结果怎么不对呀,请明白的同学指教.
具体噪声加入是这样的:
我把语音信号和噪声信号通过采样得到矩阵为y1和y2;
把y1,y2以mat文件保存在matlab的work里,
直接调出来用:
% LMS method for noise cancellation
%----------------use audio signal "good morning"--------------------------------------
clear;
clc;
disp(' =========================');
disp(' LMS ');
disp(' =========================');
% --------- Initialization ----------
hord=20;
% ---------- signal and noise generation -----------
y1 %信号
len=length(y1);
n=1:len;
y2 %噪声
x=y2+1; %参考输入(或通过已采样的信号x= s2(2:39001));
d=y1+10*y2;
wavwrite(x,112025,16,'daizao');
ws=zeros(hord+1,len-hord);
errs=zeros(len,1);
mus=0.008;
% --------- LMS noise cancellation ---------
for i=hord+1:len-hord
j=i-hord:1:i;
x1=x(j);
ys(i)=ws(:,i)'*x1;
errs(i)=d(i)-ys(i);
q(i)=errs(i)-s(i);
n1=hord+1;n2=len-hord;
Eq(i)=sum(abs(q(i)).^2);
Pq(i)=Eq(i)/(n2-n1);
ws(:,i+1)=ws(:,i)+mus*x1*errs(i);
end
% WAVWRITE(Y,FS,WAVEFILE)
wavwrite(errs,15000,'shuchu');
figure(1)
plot(s),title('original');
figure(2)
plot(d),title('noisy signal');
figure(3)
plot(errs),title('output');
% ERROR EFFICIENCY
figure(4)
plot(Pq),title('error efficency');
figure(5)
plot(ws(10,:)),title('converge line')
为什么去不了噪呀,请教各位大侠.谢谢?可以给我发邮件.495489646@qq.com
急用,马上毕业了,再次谢谢. |
|