[Optimization algorithm] Improved fixed step length and variable step length LMS algorithm [with Matlab source code 629 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

clear all
clc              
t=0:1/1000:100-1/1000;
s=15*sin(0.15*pi*t);
snr=10;
s_power=var(s);              %var函数: 返回方差值
linear_snr=10^(snr/10);
factor=sqrt(s_power/linear_snr);
noise=randn(1,length(s))*factor;
%noise=wgn(1,length(s),factor);
x=s+noise;                   %由SNR计算随机噪声
x1=noise;                    %噪声源输入
x2=noise;
%x3=noise;
w1=0;                       %权系数初值
w2=0;
%w3=0;
e=zeros(1,length(x));
error=zeros(1,length(x));
y=0;
%mu=0;
mu=0.000009;                 
for i=1:100000                 %定步长LMS算法
    y=w1*x1(i)+w2*x2(i);%+w3*x3(i);
    e(i)=x(i)-y;
    error(i)=s(i)-e(i);
 %   ee=error^2;
 %   mu=xuanze(mu,ee);
    w1=w1+mu*e(i)*x1(i);
    w2=w2+mu*e(i)*x2(i);
  %  w3=w3+mu*e(i)*x3(i);
end
figure(1)
subplot(4,1,1)
plot(t,s);
title('纯正弦信号')
subplot(4,1,2)
plot(t,x);
title('带噪声正弦信号')
axis([0 100 -30 30]);
subplot(4,1,3)
plot(t,noise);
title('噪声信号')
axis([0 100 -30 30]);
subplot(4,1,4)
plot(t,e);
title('定步长LMS算法自适应噪声对消器')
axis([0 100 -30 30]);
wu=error;
figure(2)
subplot(3,1,1);
plot(wu);
title('定步长LMS算法收敛过程')







%自适应噪声对消器
clear all
clc              
t=0:1/1000:100-1/1000;
s=15*sin(0.15*pi*t);
snr=10;
s_power=var(s);              %var函数: 返回方差值
linear_snr=10^(snr/10);
factor=sqrt(s_power/linear_snr);
noise=randn(1,length(s))*factor;
x=s+noise;                   %由SNR计算随机噪声
x1=noise;                    %噪声源输入
x2=noise;
w1=0;                       %权系数初值
w2=0;
e=zeros(1,length(x));
error=zeros(1,length(x));
y=0;
mu=0;
%mu=0.05;                 
for i=1:100000                 %变步长LMS算法
    y=w1*x1(i)+w2*x2(i);
    e(i)=x(i)-y;
     error(i)=s(i)-e(i);
    ee=error(i)^2;
    if ee>0.0005;
        ee=0.0005;
    end
    mu=xuanze(mu,ee);
    w1=w1+mu*e(i)*x1(i);
    w2=w2+mu*e(i)*x2(i);   
end
figure(3)
subplot(4,1,1)
plot(t,s);
title('纯正弦信号')
subplot(4,1,2)
plot(t,x);
title('带噪声正弦信号')
axis([0 100 -30 30]);
subplot(4,1,3)
plot(t,noise);
title('噪声信号')
axis([0 100 -30 30]);
subplot(4,1,4)
plot(t,e);
title('变步长LMS算法自适应噪声对消器')
axis([0 100 -30 30]);
wu=error;
figure(2)
subplot(3,1,2);
plot(wu);
title('变步长LMS算法收敛过程')





%自适应噪声对消器
clear all
clc              
t=0:1/1000:100-1/1000;
s=15*sin(0.15*pi*t);
snr=10;
s_power=var(s);              %var函数: 返回方差值
linear_snr=10^(snr/10);
factor=sqrt(s_power/linear_snr);
noise=randn(1,length(s))*factor;
x=s+noise;                   %由SNR计算随机噪声
x1=noise;                    %噪声源输入
x2=noise;
w1=0;                       %权系数初值
w2=0;
e=zeros(1,length(x));
error=zeros(1,length(x));
y=0;
mu=0;
%mu=0.05;                 
for i=1:100000                 %改进变步长LMS算法
    y=w1*x1(i)+w2*x2(i);
    e(i)=x(i)-y;
    
   ee=exp(abs(error(i))^3)-1;
 %  ee=error^4; 
   
      
   end    
    mu=xuanze(mu,ee);
    w1=w1+mu*e(i)*x1(i);
    w2=w2+mu*e(i)*x2(i);   
end
figure(4)
subplot(4,1,1)
plot(t,s);
title('纯正弦信号')
subplot(4,1,2)
plot(t,x);
title('带噪声正弦信号')
axis([0 100 -30 30]);
subplot(4,1,3)
plot(t,noise);
title('噪声信号')
axis([0 100 -30 30]);
subplot(4,1,4)
plot(t,e);
title('改进变步长LMS算法自适应噪声对消器')
axis([0 100 -30 30]);

Three, running results

Insert picture description here
Insert picture description here
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]

Guess you like

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