function Out = ofdm (WaveType, RandomSeed, LengthSym, NumSyms)

% ofdm (WaveType, RandomSeed, LengthSym, NumSyms)
%       WaveType        1: all input data random
%                       2: all input data random, except first symbol all 1's
%       RandomSeed      Any integer
%       LengthSym       Number of samples in each symbol
%       NumSyms         Number of symbols in entire output
%
% Generates a vector of OFDM symbols
%
% 2006/02/07  Now has 14 fractional bits
% 2006/02/06  Written


%----- Set this
NumFractionalBits = 14;

%----- Main
rand('state', RandomSeed);              % set state of random num generator

% Build output waveform by appending one symbol at a time
for k=1:NumSyms,
  freq = 2*round(rand(1,LengthSym)) - 1;

  if (k == NumSyms && WaveType == 2)
    freq = ones(1,LengthSym);
  end

  begin = (k-1)*LengthSym + 1;
  endd  = begin + LengthSym - 1;

  Out(begin:endd) = ifft(freq);         % append a symbol
end

% Form output so that there are the correct number of bits to the right
% of the decimal point.
Out = round(Out * 2^NumFractionalBits) / 2^NumFractionalBits;

