[Optimization algorithm] Improved LMS algorithm [including Matlab source code 630 period]

1. Introduction

Least Mean Squares (LMS, Least Mean Squares) is the most basic adaptive filtering algorithm.
The LMS algorithm is a commonly used algorithm in adaptive filters. The difference from the Wiener algorithm is that the coefficients of the system change with the input sequence. In the Wiener algorithm, a section of the autocorrelation function of the input sequence is intercepted to construct the optimal coefficient of the system. The LMS algorithm is implemented by continuously correcting the initialized filter coefficients according to the minimum mean square error criterion. Therefore, theoretically speaking, the performance of the LMS algorithm is better than Wiener under the same conditions. However, the LMS is adjusted gradually under the initial value, so before the system is stable, there will be a period of adjustment time. The adjustment time is controlled by the step size factor. Within a certain range, the larger the step size factor, the smaller the adjustment time, and the step size factor The maximum value of is the trace of R. LMS adopts the principle of minimum square error instead of the principle of minimum mean square error, and the basic signal relationship is as follows:
Insert picture description here
Insert picture description here

Second, the source code

 %一种变步长lms 算法
clear all
close all
hold off    
sysorder = 5 ; %抽头数

t = 0:1/5000:1-0.0001;
s = sin(2*pi*t); %不带噪声的信号
N = size(t);
M = length(t);
% %计算自相关矩阵的最大特征值
% xx=rcorr(length(s),s);
% [V,D]=eig(xx);
% Dmax=max(max(D));

n = randn(N);   %产生高斯白噪声
[b,a] = butter(2,0.25);
Gz = tf(b,a,-1); %逆变换函数
y = lsim(Gz,s);  %加入正弦信号
z = n * std(y)/(10*std(n));  %标准差为0的噪声信号
x = s + z;      %实际输入信号
dd = s; %期望输出信号

%算法的开始
w = zeros(1,sysorder);%权向量初始化
umax=0.45;   %设置步长最大值
umin=0.0003; %设置步长最小值

for i=1:2
          u = umax;
          y(i) = x(i:i+4)* w' ; %系统输出

          e(i) = dd(i) - y(i);%误差
  
          w = w + u * e(i) * x(i); %迭代方程
end

for i = 3:M-4

     if ((u >= umin)&&(u <= umax))

       y(i) = x(i:i+4)* w' ;  %系统输出
 
       e(i) = dd(i) - y(i);  %误差

       w = w + u * e(i) * x(i);  %迭代方程

       u = ((e(i) * e(i-1)/((dd(i))^2)))* umax;  %步长更新公式
    end
   
    if    u > umax
          u = umax;
          
          y(i) = x(i:i+4)* w' ; %系统输出
   
          e(i) = dd(i) - y(i);   %误差

           w = w + u * e(i) * x(i);  %迭代方程
           
           u = ((e(i) * e(i-1)/((dd(i))^2)))* umax;  %步长更新公式
    end
    
   if     u < umin
          u = umin;

          y(i) = x(i:i+4)* w' ;  %系统输出

          e(i) = dd(i) - y(i); %误差

             w = w + u * e(i) * x(i);  %迭代方程

             u = ((e(i) * e(i-1)/((dd(i))^2)))* umax; %步长更新公式
   end

end

 %计算均方误差 
st = 0;
 i = 1;

while i <= M-4       
      a = (e(i))^2;
     st = st+a;
    out = (1/i)*st;
    yy(1,i) = out;
    i = i+1;
  
end

% %作图
hold on;
%不带噪声的信号
subplot(3,1,1)
plot(s)      
title('纯净的输入信号')
 %噪声
subplot(3,1,2)
plot(z,'g')     
title('噪声')
 %带噪声的输入信号  
subplot(3,1,3)
plot(x,'c')      
title('带噪声的输入信号')
figure

Three, running results

Insert picture description here
Insert picture description here

Four, remarks

Complete code or writing add QQ 1564658423 review of previous periods
>>>>>>
[Workshop scheduling] Matlab particle swarm-based workshop scheduling [including Matlab source code 013]
[Workshop scheduling] Based on matlab genetic algorithm to solve the workshop scheduling model with GUI [ Include Matlab source code 049 period]
[Workshop scheduling] Based on matlab genetic algorithm to solve shop scheduling [Include Matlab source code 070]
[Workshop scheduling] Based on matlab nsgaII Solve shop scheduling [Contain Matlab source code 071 period]
[Workshop scheduling] Improve leapfrog based on matlab Algorithm to solve shop scheduling problem [including Matlab source code 073]
[Workshop scheduling] Matlab to solve the replacement flow shop scheduling problem [including Matlab source code 176]
[Workshop scheduling] Based on matlab PSO to solve 6X6 shop scheduling problems [including Matlab source code 411 ]
[shop scheduling] based production scheduling matlab particle swarm [with Matlab source code 412]
[shop scheduling] based on matlab genetic algorithm for multi-objective flow shop scheduling [with Matlab source code 443]
[optimization solution] based microgrid matlab PSO's Multi-objective optimization [including Matlab source code 444 period]
[Optimization solution] based on matlab dragonfly algorithm to solve multi-objective optimization problems [including Matlab source code 477 period]
[Optimization algorithm] Marine predator algorithm (MPA) [including Matlab source code 478 period]
[Optimization Algorithm] Black Hole Simulation Algorithm (MVO) [Including Matlab source code 479]
[Optimization algorithm] Improved flower pollination algorithm based on mutation strategy [Including Matlab source code 480]
[Optimization solution] based on matlab particle swarm algorithm to solve hydro-thermal power economic dispatch [including Matlab source code 500 period]
[Optimization solution] based on sparrow search algorithm 3D wireless sensor network (WSN) coverage optimization [including Matlab source code period 599]
[Optimization solution] based on Genetic algorithm to solve the multi-objective distribution network reconstruction model [including Matlab source code 622]
[Optimization algorithm] Improved fixed step and variable step size LMS algorithm [including Matlab source code 629]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/115221222