function ChannelEst = EstChannel( Received, Training, Order, SpS)
% EstChannel - estimate channel coefficients from training sequence
%
% Least squares estimate of channel impulse response from received signal
% and training sequence. 
%
% Received - received signal due to training sequence (SpS samples/symbol)
% Training - Training Sequence (1 sample/symbol)
% Order    - Number of filter coefficients
% SpS      - number of samples per sample

% upsample training sequence
TrainingSPS            = zeros(1, length(Received) );
TrainingSPS(1:SpS:end) = Training;

% make into a Toepliz matrix, such that T*h is convolution
TrainMatrix = toeplitz( TrainingSPS, [Training(1) zeros(1, Order-1)]);

ChannelEst = Received * conj( TrainMatrix) * ...
    inv(TrainMatrix' * TrainMatrix);
