% Adaptive equalization % Simulate some (useful) signal to be transmitted a = (randn(5000,1)>0) *2-1; % Random bipolar (-1,1) sequence; % CHANNEL MODEL W=2.9; h= [ 0, 0.5 * (1+cos(2*pi/W*(-1:1))) ]; ah=conv(h,a); v= sqrt(0.001)*randn(5000,1); % Gaussian noise with variance 0.001; u=ah(1:5000)+v; % First 500 samples are used to design the equalizer % Next 4500 samples are used to validate the performance of equalizer % Least Squares design of equalizer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Different data windowing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % A1 or A2: Covariance method (Use all data in the training set) % You may try to build A row-wise but it takes a long time A1=[]; for i=12:500 uvec=u((i-1):(-1):(i-11)); A1=[A1; uvec']; end % Or you may try to build A column-wise, much faster A2=[]; for i=1:11 uvec=u((12-i):(500-i)); A2=[A2 uvec]; end % Is it A1 equal to A2 ? A1_not_eq_A2=sum(sum(A1~=A2)) Phi1=A1'*A1; d1=a(5:493); psi1=A1'*d1; w1= Phi1\psi1 %%% This is LS solution for covariance windowing % A3 Pre- and Post - windowing A3=[]; for i=1:11 uvec=[ zeros(i-1,1); u ; zeros(11-i,1) ]; A3=[A3 uvec]; end %Check the size of A3 and comment the result. Phi3=A3'*A3; d3=[zeros(6,1); a ; zeros(4,1)]; psi3=A3'*d3; w3= Phi3\psi3 %%% This is LS solution for pre- and post- windowing % A4 Pre- windowing A4=[]; for i=1:11 uvec=[ zeros(i-1,1); u(1:(500-i)) ]; A4=[A4 uvec]; end Phi4=A4'*A4; d4=[zeros(6,1); a(1:493) ]; psi4=A4'*d4; w4= Phi4\psi4 %%% This is LS solution for pre- windowing [w1 w3 w4] % Different ways to compute LS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % We use only covariance method % Solving the system of equations using matlab \ operator % (Gaussian elimination) w1se= Phi1\psi1; % Use of inverse matrix function w1im=inv(Phi1)*psi1; % Use of QR decomposition w1QR=A1\d1; dif_w1= w1se-w1im % Check what is the difference dif_w2= w1se-w1QR % Check what is the difference % Evaluation of the performance over the validation set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Filter the signal u(t) with the filter w1 % You may use a for loop for finding the filter output A1=[]; for i=512:5000 uvec=u((i-1):(-1):(i-11)); y1(i)=w1'*uvec; end % Or you may use a faster way, computing the data matrix A2=[]; for i=1:11 uvec=u((512-i):(5000-i)); A2=[A2 uvec]; end y2=A2*w1; % Compute the thresholded output, and scale it from {0,1} to {-1,1} y_binary=(y2>0)*2-1; d1=a(505:4993); % Compare it with the desired signal n_errors= sum(y_binary~=d1) % Filter the signal u(t) with the filter w3 (Pre- and post- windowing) % Compute using the data matrix A2=[]; for i=1:11 uvec=u((512-i):(5000-i)); A2=[A2 uvec]; end y3=A2*w3; % Compute the thresholded output, and scale it from {0,1} to {-1,1} y_binary=(y3>0)*2-1; d1=a(505:4993); % Compare it with the desired signal n_errors= sum(y_binary~=d1) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Adaptive equalization with LMS and RLS algorithms % Simulate some (useful) signal to be transmitted a = (randn(5010,1)>0) *2-1; % Random bipolar (-1,1) sequence; % CHANNEL MODEL W1=2.9;W2=3.3; h1= [ 0, 0.5 * (1+cos(2*pi/W1*(-1:1))) ]'; h2= [ 0, 0.5 * (1+cos(2*pi/W2*(-1:1))) ]'; Aa=[]; for i=1:3 avec=a((4-i):(5010-i)); Aa=[Aa avec]; end ah=Aa(1:250,:)*h1(2:4); ah=[ah ; Aa(251:5000,:)*h2(2:4)]; v= sqrt(0.01)*randn(5000,1); % Gaussian noise with variance 0.001; u=ah(1:5000)+v; % First 500 samples are used to design the equalizer % Next 4500 samples are used to validate the performance of equalizer % LMS design of equalizer mu= 0.075; wlms=zeros(11,1); for i=12:500 y(i)=wlms'*u((i-1):(-1):(i-11)); e(i)=a(i-7)-y(i); wlms=wlms+mu*e(i)*u((i-1):(-1):(i-11)); Jlms(i)=e(i)^2; end % end wlms % Recursive Least Squares design of equalizer dlta=1000.; lambda=1;wrls=zeros(11,1); P=dlta * eye(11); % Initialize P for i=12:500 uvec=u((i-1):(-1):(i-11)); pivec=uvec'*P; gamma= lambda + pivec* uvec; kvec=pivec'/gamma; err=a(i-7)- wrls'*uvec; wrls=wrls+kvec*err; Pprime=kvec*pivec; P=(P-Pprime)/lambda; Jrls(i)=err^2; end % w_lms_rls_ls= [wlms wrls wls] w_lms_rls= [wlms wrls] plot(1:500,Jrls,'g',1:500,Jlms,'r') % Evaluation of the performance over the validation set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Filter the signal u(t) with the LMS filterresulted after 500 iterations A=[]; for i=1:11 uvec=u((512-i):(5000-i)); A=[A uvec]; end ylms=A*wlms; % Compute the thresholded output, and scale it from {0,1} to {-1,1} y_binary_lms=(ylms>0)*2-1; d1=a(505:4993); % Compare it with the desired signal n_errors_lms= sum(y_binary_lms~=d1) % Filter the signal u(t) with the RLS filter obtained after 500 iterations A=[]; for i=1:11 uvec=u((512-i):(5000-i)); A=[A uvec]; end yrls=A*wrls; % Compute the thresholded output, and scale it from {0,1} to {-1,1} y_binary_rls = (yrls>0)*2-1; d1=a(505:4993); % Compare it with the desired signal n_errors_rls = sum(y_binary_rls~=d1)