Code covered by the BSD License  

Highlights from
Comparison between RLS and LMS algos in Designing digital equalizer in noisy nonlinear channel

image thumbnail

Comparison between RLS and LMS algos in Designing digital equalizer in noisy nonlinear channel

by

 

Comparison between RLS and LMS algos in Designing digital equalizer in noisy nonlinear channel.

Non_linear_Channel_equalizer_RLSnLMS_compare.m
clear all;
clc;
tic;
% DESIGN OF NOVEL DIGITAL EQUALIZERS FOR NOISY NONLINEAR CHANNEL USING RLS
% and LMS and campare
% By Y.Yella Reddy, 08EE01015, SES, IIT Bhubaneswar.

%---------------Channel or Filter "Intialization"-----------------------%
Select=input('Enter the channel u want select.. select 1 for CH1 otherwise 2 :');
if(Select==1)
Channel_Weights=[0.26 0.93 0.26] ; % Transfer function coefficients
else
Channel_Weights=[0.3040 0.9030 0.3040];
end

%---------------Transmission data "Intialization"------------------------%
N=input('Enter the no of the iterations/input samples: '); %input number of samples.
Transmit_Data= rand(1,N);  % input to the plant.

%Changing Transmitted data into digital bits of amplitude 1 and -1.
for i=1:1:N
if (Transmit_Data(i)>0.5)
    Transmit_Data(i)=1;
else
    Transmit_Data(i)=-1;
end
end

%zeros are padded for later use in the algorithm.
Transmit_Data=[0 0 Transmit_Data];

%------------------------Equalizer "Intialization"------------------------%
Equalizer_Weights=zeros(1,8);
Equalizer_Weights1=zeros(1,8);
Learning_Rate=input('Enter the Learning Parameter value:'); % Learning rate of the model

%Signal Power to noise power
SNR=input('Enter the snr value : ');

%Signal Power and Noise Power
sp=var(Transmit_Data);
np =(sp)*power(10,-(SNR/10)); 

%Noise to be added
Noise=sqrt(np)*(rand(1,N)-0.5);

%Received output after delay
 for i=1:1:4
 Delayed_Input(i)=0;
end

%---------------------Desired output------------------------------------%
Delayed_Input=[Delayed_Input(1:4) Transmit_Data];
Desired_Output=Delayed_Input;

 % adding non-linearity ..select any values of the given
Select_nonlinear=input('Enter the value(1,2,3) of function which u want to be function of non linearity:');

 for j=1:1:N     
  % Finding the channel filter output
 Filter_Output(j)=(Channel_Weights(1)*Transmit_Data(j+2))+(Channel_Weights(2)*Transmit_Data(j+1))+(Channel_Weights(3)*Transmit_Data(j));

%selecting type of non linearity and as well finding the Equalizer input.
if (Select_nonlinear==1)
        Equalizer_Input(j)=tanh(Filter_Output(j));
else if (Select_nonlinear==2)
        Equalizer_Input(j)= Filter_Output(j)+ 0.1*Filter_Output(j)^2 - 0.2*Filter_Output(j)^3;
     else
        Equalizer_Input(j) = Filter_Output(j)+ 0.1*Filter_Output(j)^2 - 0.2*Filter_Output(j)^3+0.5*cos(pi*Filter_Output(j));
     end
end
end
%adding noise to the equalizer input
%Equalizer_Input_with_noise=awgn(Equalizer_Input,SNR);
Equalizer_Input_with_noise=Equalizer_Input+ Noise;
Equalizer_Input_with_noise=[0 0 0 Equalizer_Input_with_noise];

%Intialization of Equalizer outputs
Equalizer_Output=zeros(1,N);
Equalizer_Output1=zeros(1,N);

%Intialization of Rinverse
R_inverse=100*eye(8);

for k=1:1:N-4

%finding equalizer output.
for j=1:8
       Equalizer_Output(k)=Equalizer_Output(k)+ Equalizer_Input_with_noise(k+j-1)*Equalizer_Weights(j);
       Equalizer_Output1(k)=Equalizer_Output1(k)+ Equalizer_Input_with_noise(k+j-1)*Equalizer_Weights1(j);
end

%finding error
Error(k)=Desired_Output(k+6)-Equalizer_Output(k);
Error1(k)=Desired_Output(k+6)-Equalizer_Output1(k);

    %RLS Parameters
    filtered_infrmn_vect=R_inverse*Equalizer_Input_with_noise(k:k+7)';
    norm_error_power=Equalizer_Input_with_noise(k:k+7)*filtered_infrmn_vect;
    gain_constant=1/(1+ norm_error_power);
    norm_filtered_infrmn_vect= gain_constant*filtered_infrmn_vect';
    
    %updating weight values of equalizer.
    %Weight Update using RLS algorithm
    Equalizer_Weights=Equalizer_Weights + Error(k)*norm_filtered_infrmn_vect;%(2*Learning_Para*Input_Model(i:-1:i-2)*error(i));
    
    %Updating R inverse
    R_inverse= R_inverse-norm_filtered_infrmn_vect'*norm_filtered_infrmn_vect;
    
    %Weight Update using LMS algorithm
    for m=1:8
        Equalizer_Weights1(m)= Equalizer_Weights1(m)+(2*Learning_Rate*Equalizer_Input_with_noise(k+m-1)*Error1(k));
end

end




%-------------------Testing of the Equalizer------------------------------%
n=input('Enter the no of test samples :');% no of test samples
ber=zeros(1,15);
ber1=zeros(1,15);
Test_Equalizer_Input=zeros(1,n);

for snr=2:2:30
    
Test_Input= rand(1,n);  % input to the plant.
for m=1:1:n
    if (Test_Input(m)>0.5)
    Test_Input(m)=1;
else
    Test_Input(m)=-1;
    end
end
Test_Input1=[0 0 Test_Input];
Delayed_Test_Output=[0 0 0 0 Test_Input1];


%Signal Power and Noise Power
SP=var(Test_Input1);
NP =(sp)*power(10,-(snr/10)); 

%Noise to be added
noise=sqrt(NP)*(rand(1,n)-0.5);

 for j=1:1:n     
 Test_Filter_Output(j)=Channel_Weights(1)*Test_Input1(j+2)+Channel_Weights(2)*Test_Input1(j+1)+Channel_Weights(3)*Test_Input1(j);    
     %selecting type of non linearity and as well finding the Equalizer input.
if (Select_nonlinear==1)
        Test_Equalizer_Input(j)=tanh(Test_Filter_Output(j));
else if (Select_nonlinear==2)
        Test_Equalizer_Input(j)= Test_Filter_Output(j)+ 0.1*Test_Filter_Output(j)^2 - 0.2*Test_Filter_Output(j)^3;
     else
        Test_Equalizer_Input(j) =Test_Filter_Output(j)+ 0.1*Test_Filter_Output(j)^2 - 0.2*Test_Filter_Output(j)^3+0.5*cos(pi*Test_Filter_Output(j));
    end
end 
 end
 %adding noise
    %Test_Equalizer_Input_with_noise=awgn(Test_Equalizer_Input,snr);
    Test_Equalizer_Input_with_noise=Test_Equalizer_Input+noise;
    Test_Equalizer_Input_with_noise=[0 0 0 Test_Equalizer_Input_with_noise];
    Test_Equalizer_Output=zeros(1,n);
    Test_Equalizer_Output1=zeros(1,n);
% Calculating the final equalizer output
for k=1:1:n-4 
for j=1:8
       Test_Equalizer_Output(k)=Test_Equalizer_Output(k)+ Test_Equalizer_Input_with_noise(k+j-1)*Equalizer_Weights(j);
       Test_Equalizer_Output1(k)=Test_Equalizer_Output1(k)+ Test_Equalizer_Input_with_noise(k+j-1)*Equalizer_Weights1(j);
end

%Converting the Output into digital bits of 1 and -1 for RLS
if (Test_Equalizer_Output(k)>0.5)
    Test_Equalizer_Output(k)=1;
else
    Test_Equalizer_Output(k)=-1;
end

%Converting the Output into digital bits of 1 and -1 for LMS
if (Test_Equalizer_Output1(k)>0.5)
    Test_Equalizer_Output1(k)=1;
else
    Test_Equalizer_Output1(k)=-1;
end

%Calculation of BER-RLS
if (Test_Input1(k+2)~= Test_Equalizer_Output(k))
    ber(snr/2)=ber(snr/2)+1;%it will give cunt of errors
end

%Calculation of BER-RLS
if (Test_Input1(k+2)~= Test_Equalizer_Output1(k))
    ber1(snr/2)=ber1(snr/2)+1;%it will give cunt of errors
end

end
 
end

z=size(Error);
t=1:1:z(2);

y=1:1:15;
%-------------------------Plots---------------------%
plot(y,log10(ber/n),'r-',y,log10(ber1/n),'g-');
legend('log of BER');
title('Plot of log of BER Vs SNR Value');
ylabel('iterations');
xlabel('SNR value');

figure,
plot(t,power(Error,2),'r-',t,power(Error1,2),'g-');
legend('error square');
title('Plot of error square Vs no of iterations');
ylabel('iterations');
xlabel('error square');

figure,
plot(y,log10(ber),'r-',y,log10(ber1),'g-');
legend('BER');
title('Plot of log of BER Vs SNR Value');
ylabel('BER');
xlabel('SNR value');

figure,
plot(y,ber,'r-',y,ber1,'g-');
legend('errors');
title('Plot of no of errors Vs SNR Value');
ylabel('No of errors');
xlabel('SNR value')
toc;

Contact us