## System Identification Using Least Mean Forth (LMF) and Least Mean Square (LMS) algorithm

Plant identification simulation Author: SHUJAAT KHAN (shujaat123@gmail.com) Please cite: @article{Khan2017FLMFFL, title={FLMF: Fractional least mean fourth algorithm for channel estimation in non-Gaussian environment}, author={Shujaat Khan and Naveed Ahmed and Muhammad Ammar Malik and Imran Naseem and Roberto Togneri and Mohammed Bennamoun}, journal={2017 International Conference on Information and Communication Technology Convergence (ICTC)}, year={2017}, pages={466-470} }

```% *Start*
clc;
clear all;
close all;

N = 1e4;    % Number of samples
Bits = 2;      % For PSK modulation
SNR = 10;      % Noise level

% *Monte Carlo simulations*

% h = [0.9 0.2 0.5 -0.7];         % Plant1 impulse response
% h = [-2:1:2];                   % Plant2 impulse response
h = randn(1,5);                   % Random system

runs=100;
NWDs = 0;
NWDf = 0;
temp3 = 0;
temp4 = 0;
for run = 1:runs % Monte Carlo simulations
% h = randn(1,5);
data = randi([0 (2^Bits)-1],1,N);            % Random index for input data
x = real(pskmod(data,2^Bits));    % Phase shit keying (PSK) modulation
r = filter(h,1,x);              % Input passed trought system(h)
d = awun(r, SNR);               % Addition of white Uniform noise of decined SNR
% d = awgn(r, SNR);               % Addition of white Gaussian noise of decined SNR

% *LMS parameter*
etas = 1e-2;                    % Learning rate for LMS
Wlms = zeros(size(h));          % Initial weights of LMS
Us = zeros(1,length(h));         % Input frame length of LMS

% *LMF parameter*
etaf = 1e-2;                    % Learning rate for LMF
Wlmf = zeros(size(h));          % Initial weights of LMF
Uf = zeros(1,length(h));         % Input frame length of LMF

for n = 1 : N

% *LMS*
Us(1,2:end) = Us(1,1:end-1);  % Shifting of frame window
Us(1,1) = x(n);               % Input of LMS

ys = (Wlms)*Us';                % Output of LMS
es = d(n) - ys;                 % Instantaneous error of LMS
Wlms = Wlms +  etas * es * Us;  % Weight update rule of LMS

% *LMF*
Uf(1,2:end) = Uf(1,1:end-1);  % Shifting of frame window
Uf(1,1) = x(n);               % Input of LMF

yf = (Wlmf)*Uf';                      % Output of LMF
ef = d(n) - yf;                       % Instantaneous error of LMF
Wlmf = Wlmf +  etaf * (ef.^3) * Uf;   % Weight update rule of LMF

% *Normalized weight difference (NWD)*
temp1(n) = norm(Wlms-h)./norm(h);      % Normalized weight difference of LMS
temp2(n) = norm(Wlmf-h)./norm(h);      % Normalized weight difference of LMF
end

% *Accumulating Results*
NWDs = NWDs + temp1;
NWDf = NWDf + temp2;

temp3 = temp3 + Wlms;
temp4 = temp4 + Wlmf;
end
```

## Average Results for (# of runs) of independent trials

```NWDs = NWDs./runs;
NWDf = NWDf./runs;

Wlms = temp3./runs;
Wlmf = temp4./runs;
```

## Cost function plots

```figure
fsize=14; % plot text font size
plot(10*log10(NWDs),'','linewidth',4)
hold on
plot(10*log10(NWDf),'r','linewidth',4)
lgh=legend(strcat('Least mean square (LMS):', int2str(SNR),' (dB)'),strcat('Least mean forth (LMF):', int2str(SNR),' (dB)'),'Location','NorthEast');
grid minor
xlabel('Iterations','FontName','Times New Roman','FontSize',fsize);
ylabel('Normalized weight difference (NWD) in (dB)','FontName','Times New Roman','FontSize',fsize);
title('Cost function (NWD vs epochs iteration)','FontName','Times New Roman','FontSize',6*fsize/5);
set(lgh,'FontName','Times New Roman','FontSize',fsize)
set(gca,'FontName','Times New Roman','FontSize',fsize)
saveas(gcf,strcat('LMS_LMF_Comparision.png'),'png')

[h;Wlms;Wlmf]
```
```ans =

0.3542    0.9466    2.1399   -1.0027   -0.4227
0.3490    0.9456    2.1321   -1.0082   -0.4226
0.3506    0.9441    2.1333   -1.0041   -0.4223

```