% Training based channel equalization
% adpative MMSE equalizer via LMS algorithm
%
% Copyright: Xiaohua(Edward) Li, Assistant Professor
% Department of Electrical and Computer Engineering
% State University of New York at Binghamton
% http://ucesp.ws.binghamton.edu/~xli
% June 2003
%
T=3000; % total number of data
M=2000; % total number of training symbols
dB=25; % SNR in dB value
%%%%%%%%% Simulate the Received noisy Signal %%%%%%%%%%%
N=20; % smoothing length N+1
Lh=5; % channel length = Lh+1
P=round((N+Lh)/2); % equalization delay
h=randn(1,Lh+1)+sqrt(-1)*randn(1,Lh+1); % channel (complex)
h=h/norm(h); % normalize
s=round(rand(1,T))*2-1; % QPSK or 4 QAM symbol sequence
s=s+sqrt(-1)*(round(rand(1,T))*2-1);
% generate received noisy signal
x=filter(h,1,s);
vn=randn(1,T)+sqrt(-1)*randn(1,T); % AWGN noise (complex)
vn=vn/norm(vn)*10^(-dB/20)*norm(x); % adjust noise power with SNR dB value
SNR=20*log10(norm(x)/norm(vn)) % Check SNR of the received samples
x=x+vn; % received signal
%%%%%%%%%%%%% adaptive MMSE equalizer estimation
Lp=T-N; %% remove several first samples to avoid 0 or negative subscript
X=zeros(N+1,Lp); % sample vectors (each column is a sample vector)
for i=1:Lp
X(:,i)=x(i+N:-1:i).';
end
e=zeros(1,M-10); % used to save instant error
f=zeros(N+1,1); % initial condition
mu=0.001; % parameter to adjust convergence and steady error
for i=1:M-10
e(i)=s(i+10+N-P)-f'*X(:,i+10); % instant error
f=f+mu*conj(e(i))*X(:,i+10); % update equalizer estimation
i_e=[i/10000 abs(e(i))] % output information
end
sb=f'*X; % estimate symbols (perform equalization)
% calculate SER
sb1=sb/norm(f); % scale the output
sb1=sign(real(sb1))+sqrt(-1)*sign(imag(sb1)); % perform symbol detection
start=7; % carefully find the corresponding begining point
sb2=sb1-s(start+1:start+length(sb1)); % find error symbols
SER=length(find(sb2~=0))/length(sb2) % calculate SER
if 1
subplot(221),
plot(s,'o'); % show the pattern of transmitted symbols
grid,title('Transmitted symbols'); xlabel('Real'),ylabel('Image')
axis([-2 2 -2 2])
subplot(222),
plot(x,'o'); % show the pattern of received samples
grid, title('Received samples'); xlabel('Real'), ylabel('Image')
subplot(223),
plot(sb,'o'); % show the pattern of the equalized symbols
grid, title('Equalized symbols'), xlabel('Real'), ylabel('Image')
subplot(224),
plot(abs(e)); % show the convergence
grid, title('Convergence'), xlabel('n'), ylabel('Error e(n)')
end