K = 10; % Number of users
L = 3; % Number of multipath fingers for each user
M = 100; % Number of symbols transmitted by each user in each frame
G = 64; % Spreading gain = Chip rate / Symbol rate
sampleTime = 2.0e-006;
maxDopplerShift = 200; % = v*f/c [Hz]
maxDelay = 0.16;
%delayVec = 1.0e-006 * [0 0.04 0.08]; % delays of three-path channel
delayVec = 1.0e-004 * rand([K L-1]) * maxDelay; % create avg. path delays for each user (each has 3 paths)
delayVec = [zeros(K,1) delayVec]; % First path is direct path, hence 0 delay for all users
%gainVec = [0 -3 -6];
gainVec = -delayVec*10^6; % average path delays [dB], decay exponentially with delay (linearly in dB)
%%
% Modulation
hMod = comm.BPSKModulator;
bitsPerFrame = M; % Number of bits transmitted per frame = M , due to BPSK modulation
S = zeros(bitsPerFrame,K); % Create data matrix for K users, each having M symbols
modulated_S = zeros(bitsPerFrame,K); % Modulated data matrix
nFrames = 100; % Number of frames
% Create K impulse responses for each user
for i=1:K
h(i) = rayleighchan(sampleTime, maxDopplerShift, delayVec(i,:), gainVec(i,:));
h(i).StoreHistory = 1; %
h(i).ResetBeforeFiltering = 0; % preserve the continuity of fading process
for n=1:nFrames
S(:,i) = randi([0 1],bitsPerFrame,1); % Create the message bits for i-th user
modulated_S(:,i) = step(hMod, S(:,i)); % Modulate the message of i-th user into BPSK symbols
Y(:,i) = filter(h(i),modulated_S(:,i)); % Apply the channel of i-th user to the modulated message
end
end