%% Generating the channel impulse response of a time-varying
%% channel according to a Jake's doppler channel model
%% Channel is the Hiperlan/2 channel model to use (1=A,2=B,3=C,5=E)
%% v is the terminal speed (m/s) with carrier frequency 5.2GHz
%%
%% October 2000. Bertrand Muquet, Sebastien Simoens, Shengli Zhou
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% genh.m                                                       %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% %-------------------- genh.m --------------------%
%% Generating a single fading coefficient with the `sum of sinusoids'
%% Jakes Model. 
%% I = frame length
%% v = terminal speed in m/s

function fadingcoeff=genh(I,v)

  fc = 5.2e9; 			% Carrier frequency in Herz
  c  = 3e8; 			% speed of light in meters/second
  
  fdmax=(v*fc)/c;		% Maximum Doppler frequency
  lambda=c/fc;			% The wavelength corresponding to fc
  
  N=100;			    	% Number of incident waves
  t=4e-6:4e-6:4e-6*I;      	% The time variable
				% The symbol duration in HIPERLAN is 4 us
  len=length(t);
  theta=rand(1,N)*2*pi;       	% Generating the uniform phases
  fd=cos(2*pi*((1:N)/N))*fdmax; % Generating uniformly spaced frequencies from
			    	% -fdmax to +fdmax
  E=exp(j.*(2*pi*fd(:)*t(:)'+repmat(theta(:),1,len)));
  E=E/sqrt(N);
  fadingcoeff=sum(E);
  %plot(t,abs(fadingcoeff))
  %xlabel('time (seconds)');ylabel('Envelope of the fading coefficient');

