A.
N_Trials=300; N_number=100; N_snr=10; N_users=2; N_path=2; Delay=1; Q=16; N_samples=N_number*Q; E_M=0; for trials=1:N_Trials trials noise=randn(N_users.*N_path,Q*N_number)+j.*randn(N_users*N_path,Q*N_number); s10=round(rand(N_users,N_number)); ss_user=s10*2-1; % without consideration of delayed path pn01=round(rand(N_users,Q)); pn=(pn01.*2-1)./sqrt(Q); S_spread=[]; for user=1:N_users s=kron(ss_user(user,:), pn(user,:)); S_spread=[S_spread; s]; end S_multipath=[]; for user=1:N_users s_user=S_spread(user,:); Suser_delayed=[zeros(1,Delay), s_user(1,1:(N_samples-Delay))]; S_multipath=[S_multipath; [s_user;Suser_delayed]]; end %___________the following is to generate Rayleigh fading coefficients N=N_users.*N_path; fad_c=fading(8,0.005,N_samples, N); fad=fad_c.'; % only use the amplitude; %phase is not used, which is equivalent to have an ideal phase %compensation by using channel equalization S_spread=S_multipath.*fad; %S_spread is the signal matrix of size users x N_number sgma=1; Error_M=[ ]; for snr_db=0:1:N_snr snr=10.^(snr_db./10)/2; %Evaluate the SNR from SNR in dB N0=2*sgma.^2; Eb=snr.*N0; yy=sqrt(Eb./2)*S_spread+noise; %received spread signals in the baseband Error_v_user=[]; for user=1:N_users y_path1=yy((user-1).*N_path+1, :); y_path_temp=yy((user-1).*N_path+2, :); y_path2=[y_path_temp(1,Delay+1:N_samples), zeros(1,Delay)]; Y_M_path1=[ ]; Y_M_path2=[]; for k=1:N_number ym1=y_path1(1,(k-1)*Q+1:k*Q); ym2=y_path2(1,(k-1)*Q+1:k*Q); Y_M_path1=[Y_M_path1;ym1]; Y_M_path2=[Y_M_path2;ym2]; end % Y_M is a matrix of size N_number x Q, each row correspinding to a % BPSK symbol ys=Y_M_path1*pn(user,:).'+Y_M_path2*pn(user,:).'; %despreading for a user y=ys.'; y_real=real(y); s_e=sign(y_real); s_e10=(s_e+1)./2; Error_snr=sum(abs(s10(user,:)-s_e10)); Error_v_user=[Error_v_user;Error_snr./N_number]; %A BER collumn vector for all the users and for each snr end %for user Error_M=[Error_M,Error_v_user]; %BER matrix for all users and for all the SNRs end % end for snr E_M=E_M+Error_M ; end % end for trials BER=E_M./N_Trials; BER_T=[ ]; for snr_db=0:1:N_snr snr=10.^(snr_db./10); temp=sqrt(snr./(1+snr)); BER_THEROY=(1-temp)/2; BER_T=[BER_T,BER_THEROY]; end i=0:1:N_snr; semilogy(i,BER(1,:),'-r',i,BER(2,:),'ob',i,BER_T ,'*g'); xlabel('E_b/N_0(dB)') ylabel('BER') legend('User1 RAKE','User2 RAKE', 'Theoretical flat fading');