一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【优化算法】可变步长LMS算法(VSS-LMS)【含Matlab源码 317期】
获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、简介
最小均方(LMS, Least Mean Squares)是最基本的自适应滤波算法。
LMS算法是自适应滤波器中常用的一种算法与维纳算法不同的是其系统的系数随输入序列而改变。维纳算法中截取输入序列自相关函数的一段构造系统的最佳系数。而LMS算法则是对初始化的滤波器系数依据最小均方误差准则进行不断修正来实现的。因此理论上讲LMS算法的性能在同等条件下要优于维纳。但是LMS是在初始值下逐步调整的,因此在系统稳定前,会有一段调整时间,调整时间受步长因子的控制,一定范围内,步长因子越大,调整时间越小,步长因子的最大取值为R的迹。LMS采用平方误差最小的原则代替均方误差最小的原则,信号基本关系如下:
三、部分源代码
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Matlab Code for LMS and Variable Step-Size LMS Algorithms
%% Default commands!
clc;
clear all;
close all;
%% Desired System (link: http://www.firsuite.net/FIR/AKSOY08_NORCHIP_G40)
sys_desired = [86 -294 -287 -262 -120 140 438 641 613 276 -325 -1009 -1487 -1451 -680 856 2954 5206 7106 8192 8192 7106 5206 2954 856 -680 -1451 -1487 -1009 -325 276 613 641 438 140 -120 -262 -287 -294 86] * 2^(-15);
%% Ergodic Process
% Note that the uploaded Figure is obtained for itr=500
for itr=1:100
%% Defining input and initial Model Coefficients
%input
x=randn(1,60000);
% Model for the LMS Algorithm
model_coeff = zeros(1,length(sys_desired));
% Model for the VSS-LMS Algorithm
model_coeff_vss = zeros(1,length(sys_desired));
%% Initial Values of Model Tap
model_tap = zeros(1,length(sys_desired));
%% System Output where a 40 dB Noise floor is added
noise_floor = 40;
sys_opt = filter(sys_desired,1,x)+awgn(x,noise_floor)-x;
%% Lower and Upper Bounds of Learning Rate
%%%%%%%% These above informations can be accessed from this paper:
%%% R. H. Kwong and E. W. Johnston, "A variable step size LMS algorithm," in IEEE Transactions on Signal Processing, vol. 40, no. 7, pp. 1633-1642, July 1992.
%%%doi: 10.1109/78.143435
%%%%%%%%%%%%%%%%%%
%input variance
input_var = var(x);
% upper bound = 1/(filter_length * input variance)
mu_max = 1/(input_var*length(sys_desired));
%learning rate for LMS algorithm
mu_LMS = 0.0004;
% lower bound = learning rate for LMS algorithm
mu_min = mu_LMS;
%%%%%%%%%%%%%%% NOTE %%%%%%%%%%%%%%%%%%%%%%%%%
% If the difference between mu_max and mu_min is not sufficient
% Error Curves for both LMS and VSS LMS algorithms would be IDENTICAL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Defining initial parameters for VSS-LMS algorithm
mu_VSS(1)=1; %initial value of mu for VSS
alpha = 0.97;
gamma = 4.8e-4;
%Note that these values were defined in the above paper
%% Execution of Both LMS and VSS-LMS algorithms
for i=1:length(x)
%% LMS Algorithm
% model tap values (shifting of tap values by one sample to right)
model_tap=[x(i) model_tap(1:end-1)];
% model output
model_out(i) = model_tap * model_coeff';
%error
%Updating the coefficients
model_coeff = model_coeff + mu_LMS * e_LMS(i) * model_tap;
%% VSS LMS Algorithm
% model output
model_out_vss(i) = model_tap * model_coeff_vss';
% error
e_vss(i) = sys_opt(i) - model_out_vss(i);
%Updating the coefficients
model_coeff_vss = model_coeff_vss + mu_VSS(i) * e_vss(i) * model_tap;
%Updating the mu value using the VSS algorithm
mu_VSS(i+1) = alpha * mu_VSS(i) + gamma * e_vss(i) * e_vss(i) ;
%% Checking the constraints of mu as given in the paper
if (mu_VSS(i+1)>mu_max)
mu_VSS(i+1)=mu_max;%max
elseif(mu_VSS(i+1)<mu_min)
mu_VSS(i+1)= mu_min;
else
mu_VSS(i+1) = mu_VSS(i+1) ;
end
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.