function v = tdl(I,f,var,SpS)
% tdl - tapped delay line with upsampling
%
% tapped delay line channel model. The input symbols are stored in vector I
% (length N), f contains the L+1 filter coefficients, and var is the noise 
% variance. SpS denotes the number of samples per symbol. If there is more
% than one sample per symbol (SpS>1), then the input data are upsampled by
% inserting SpS-1 zeros between symbols.
%
% v = tdl( I, f, var, N)

% Initialization

N = length(I);
L = length(f) - 1;

% for backwards compatibility, if SpS is not supllied it defaults to 1
if (nargin == 3)
    SpS = 1;
end

% Upsample input
Input = zeros(1, SpS*N);
Input(1:SpS:end) = I;

% Pad input with zeros
v = zeros(1,SpS*N+L);

for nn = 1:L+1
	v = v + f(nn)*[zeros(1,nn-1) Input zeros(1,L-nn+1)];
end

if var > 0
  if sum(abs(imag(v))) > 0 		% Complex data?
    var = var/sqrt(2);
    v = v + i*sqrt(var)*randn(size(v));
  end
  v = v + sqrt(var)*randn(size(v));
  
end