% UMMSE_FSE       Designs Unbiased MMSE T/2-spaced feedforward equalizer (FSE) 
%                 for a T/2-spaced complex FIR channel at a certain 
%                 SNR (dB) of AWGN and a unit power iid source given 
%                 (note: it optimizes the delay as well)
% 
%                 [f,delta,UMSE] = ummse_fse(h,snrdb,Nf);
%   
%                 returns:
%                            f      :   FSE          
%                            delta  :   best delay 
%                            umse   :   Unbiased Mean Square Error
%                                       (i.e. design is scaled so that
%                                        cursor is set to unity)
%                 given:    
%                            h      :   channel
%                            snrdb  :   SNR in dB
%                            Nf     :   FSE length


function [f,delta,umse] = ummse_fse(h,snrdb,Nf)


% Get SNR from SNR in dB
% and NSR=lambda
snr=10^(snrdb/10);
lambda=1/snr;

% Set up convolution matrix
if (size(h,1)<size(h,2))
   h=h';
end;
HH=convmtx(h,Nf);
H=HH(1:2:size(HH,1),:);

% Find MMSE-FSE+DFE
I=eye(size(H,2));
F=inv(H'*H+lambda*I)*H';
[mse,delta]=min(abs(diag(1-H*F)));

% Unbias MMSE-FSE+DFE to get UMMSE-FSE+DFE
f=F(:,delta);
t=H*f;
f=f/max(t);
t=H*f;
td=zeros(size(H,1),1);
td(delta)=1;
umse=norm(t-td)^2+lambda*norm(f)^2;
