clear

% Run CMA on T/2-spaced modem data 
% with a T/2-spaced equalizer (FSE)

% Load received data
load data2;

% Repeate data for long record
% and normalize to unit power
r=data.';
r=[r r r r r r];
r=r/mean(abs(r).^2);

% Get number of T-spaced symbols
L=length(r)/2;

% Define FSE
Nf=16;
f=zeros(Nf,L);

% Center spike init
f(Nf/2,Nf/2-1)=1;

% Define step-size & dispersion constant
% any number for g will work to open eye
% or rings
mu=0.00001;
g=19.15;

% Define error and equalizer output
e=zeros(1,L);
y=zeros(1,L);

% Run CMA
for k=Nf:2:2*L,

   j=k/2;
   R=r(k:-1:k-Nf+1).';
   y(j)=R.'*f(:,j-1);
   f(:,j)=f(:,j-1)+mu*conj(R)*y(j)*(g-abs(y(j))^2);

end;

% Run new data to get eye diagram
% make sure to get odd samples
ynew=filter(f(:,j),1,r);
ynew=ynew(2:2:length(ynew));
ynew=ynew(100:length(ynew)-100);

% Plot rcvd sequence
figure(1)
plot(data,'.');
axis('square');

% Plot magnitude of parameter trajectories
figure(2)
t=1:10:size(f,2);
plot(t,abs(f(:,t)'));

% Plot eye diagram of output
figure(3);
plot(ynew,'.');
title('FSE eye diagram');
axis('square');
