% This function generates fading channel models with a given power profile 
% and pulse shaped by an srrc pulse. The channels are T/2 spaced.

function [C]=generate_channels(terrain,beta,option);

% [C]=generate_channels(terrain,beta,option);
%
% terrain 1='2 ray'; 2='urban'; 3='hilly terrain'
% beta = roll off factor;
% option 1='real,baud';2='real,frac';3='comp,baud';4='comp,frac';

[profile]=power_profile(terrain);

r=(randn(1,length(profile))+j*randn(1,length(profile)))/sqrt(2);
r=r.*sqrt(profile);

srrc=SRRC(5,beta,4);

C=conv(srrc,r);

C1=C(1:2:length(C));
C=C(2:2:length(C));

if (abs(C1*C1')>abs(C*C'))
C=C1;
end;

if (option==1)
C=real(C);
C=C(2:2:end);
elseif (option==2)
C=real(C);
elseif (option==3)
C=C(2:2:end);
end;

