Basic_LMS.m
上传用户:ay_070428
上传日期:2014-12-04
资源大小:11427k
文件大小:3k
源码类别:

语音合成与识别

开发平台:

Matlab

  1. clear all;
  2. % the channel impulse response; 
  3. Hn =[0.8783   -0.5806    0.6537   -0.3223    0.6577   -0.0582   0.2895   -0.2710    0.1278   -0.1508    0.0238   -0.1814   0.2519   -0.0396    0.0423   -0.0152    0.1664   -0.0245   0.1463   -0.0770    0.1304   -0.0148    0.0054   -0.0381    0.0374   -0.0329    0.0313   -0.0253    0.0552  -0.0369   0.0479   -0.0073    0.0305   -0.0138    0.0152   -0.0012  0.0154   -0.0092    0.0177   -0.0161    0.0070   -0.0042  0.0051   -0.0131    0.0059   -0.0041    0.0077   -0.0034   0.0074   -0.0014    0.0025   -0.0056    0.0028   -0.0005   0.0033   -0.0000    0.0022   -0.0032    0.0012   -0.0020   0.0017   -0.0022    0.0004   -0.0011      0          0   ];
  4. Hn=Hn(1:64);
  5. %读入语音;  it is a column vector;
  6. r=wavread('C:MatlabworkWrite_In_PaperShi_Yan.wav');
  7. % cut the former 5000 points;
  8. r=r'; r=r(1:5000); r=r+0.2*randn(size(r));% r is the input noisy signal vector;
  9. mu=0.3;
  10. % the output signal vector;
  11. output=conv(r,Hn);  N=length(r);
  12. output=output(1:N);
  13. % ss=wavread('C:MatlabworkWrite_In_PaperShi_Yan1.wav');
  14. % ss=ss(1:N);
  15. % output=output+sqrt(1000)*ss';
  16. k=length(Hn);   % k is the order of the filter;
  17. win=zeros(1,k);  % the filter coeffients vector;
  18. error=zeros(1,N);
  19. for i=k:N
  20.     input=r(i:-1:i-k+1);  % intercept the input vector;
  21.     e=output(i)-win*input';%进行滤波
  22.     win=win+mu*e*input;%修正系数
  23.     error(i)=error(i)+e^2;%累积误差
  24. end;
  25.     figure;    plot(win,'r'); hold on; plot(Hn,'b');%绘制滤波器系数和信道脉冲响应曲线
  26.    figure;
  27.     semilogy(error,'b');
  28.  
  29.     
  30.     
  31.     
  32.       %axis([0  N  10^(-30) 0]);
  33.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34. %%%% Normalized LMS Algorithm   
  35. mu=1.5;
  36. win=zeros(1,k);  % the filter coeffients vector;
  37. error=zeros(1,N);
  38. for i=k:N
  39.     input=r(i:-1:i-k+1);  % intercept the input vector;
  40.     e=output(i)-win*input';
  41.     win=win+mu*e*input/(3.5+input*input');
  42.     error(i)=error(i)+e^2;
  43. end;
  44.     hold on;
  45.     semilogy(error,'r');%对纵坐标取对数的误差曲线
  46.   
  47.     
  48.     
  49.       T=64;
  50.       L=zeros(T,T);
  51.   for j=1:T
  52.       L(1,j)=sqrt(1/T);
  53.   end;
  54.   for i=2:T
  55.       for j=1:T
  56.           L(i,j)=sqrt(2/T)*cos((i-1)*(2*j-1)*pi/(2*T));%????
  57.       end;
  58.   end;
  59.     win=zeros(1,k);  % the filter coeffients vector;
  60.     error=zeros(1,N);
  61.     l=zeros(64,1);
  62. for i=k:N
  63.      u=r(i:-1:i-k+1);
  64.      for n=1:64
  65.          l(n)=L(n,:)*u';
  66.      end;
  67.     input=l';
  68.     mu=0.1;
  69.      % intercept the input vector;
  70.     e=output(i)-win*input';
  71.     win=win+mu*e*input;
  72.     error(i)=error(i)+e^2;
  73. end;
  74. hold on;
  75.     semilogy(error,'y');
  76.     
  77.     
  78.     
  79.     
  80.     
  81.     
  82.