°%*************************************************************************************% This fun cti on pertains to the addition of AWGN with mean zero and%parameter 'varia nee' to an in put sig nal.%% AUTHOR: Wenbin Luo% DATE : 04/12/01%% SYNOPSIS: y = awg n(x,var)% x ---> in put sig nal% var ---> varia nee% y > y = x + AWGNQ%****************************************************************************** ***** function y = awg n( x,var)w = randn( 1,le ngth(x));w = w - mea n( w)* on es(size(w));w = sqrt(var)*(w / std(w));x = x(:);w = w(:);y = x + w;^%****************************************************************************** *******% This fun etion does the DS-SS modulation%AUTHOR: Wen bi n LuoDATE : 04/28/01%% SYNOPSIS: y = ds_mod(c,x)% c ---> user code (colu mn vector)% x ---> in put sig nal (row vector)% y ---> tmp = c*x, y = tmp(:) (ds-ss modulated sig nal, colu mnvector) °%*********************************************************************************** function y = ds_mod(c,x) tmp = c*x;y = tmp(:);°%****************************************************************************** *******% This function gen erates ran dom +1/-1 seque nee within depe ndent iden tically% distributed symbols%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% SYNOPSIS: x = bin ge n(L)% L ---> nu mber of ran domsymbols °%*********************************************************************************** function x = bingen(L) %ge nerate L symbols ran domly with value +1 or -1 x =ran d(1,L);x(fi nd(x<0.5)) = -1;x(fin d(x >=0.5)) = 1;°%****************************************************************************** *******% This fun ction does the DS-SS modulation%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% SYNOPSIS: x = ds_demod(c,y)% c ---> user code (colu mn vector)% y ---> tmp = c*x, y = tmp(:) (ds-ss modulated sig nal, colu mn vector)% x ---> in put sig nal (row vector)Q%*********************************************************************************** function x = ds_demod(c,y) tmp = reshape(y, le ngth(c), le ngth(y)/le ngth(c)); tmp = tmp';%x is a colu mn vector x = tmp * c;% convert to row vector x = x';°%*************************************************************************************% This function does the DS-SS modulation%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% SYNOPSIS: y = ds_mod(c,x)% c ---> user code (column vector)% x ---> in put sig nal (row vector)% y ---> tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vector)Q%***********************************************************************************function y = ds_mod(c,x)tmp = c*x;y = tmp(:);°%*********************************************************** % This mfunction gen erates faded en velope and phase % corresponding to Rayleigh fading%% AUTHOR: Wenbin Luo%DATE : 04/27/01%% FUNCTION SYNOPSIS:%[en v,phi] = fade(L,para)% Parameter Descriptio n:% L : nu mber of samples n eeded% varia nee : varia nee°%********************************************************** function [en v,phi] = fade(L,varia nee)% Error checkif variance <= 0error('Positive varia nce n eeded')elseif nargin ~= 2error('I nsufficie nt in put parameters')end% Gen erate bivariate Gaussia n un correlated% ran dom variablesmu = zeros(1,2);C = varia nce*eye(2,2);r = mvnrn d(mu,C,L);% Convert to polar coord inates and compute% magn itude and phasez = r(:,1) + j*r(:,2);env = abs(z); phi = an gle(z);°%********************************************************** °%****************************** *****************************% This mfun ctio n gen erates two cha nn els of faded % en velope and phase corresp onding to% Rayleigh fadi ng%% AUTHOR: Wenbin Luo% DATE : 04/27/01%% FUNCTION SYNOPSIS:% [en v,phi] = fade_diversity(L,para)%% Parameter Descriptio n:% L : nu mber of samples n eeded% varia nee : varia nee°%**********************************************************function [en v1,e nv2] = fade_diversity(L,varia nee)% Error checkif variance <= 0error('Positive varia nce n eeded')elseif nargin ~= 2error('I nsufficie nt in put parameters')end% Gen erate bivariate Gaussia n un correlated% ran dom variablesmu = zeros(1,4);C = varia nce*eye(4,4);r = mvnrn d(mu,C,L);% Convert to polar coord inates and compute% mag nitude and phase z1 = r(:,1) + j*r(:,2);z2 = r(:,3) + j*r(:,4);envl = abs(zl);env2 = abs(z2);°%**********************************************************°%*********************************************************** % This mfun ctio n gen erates freque ncy selective % Rayleigh fadi ng%% AUTHOR: Wenbin Luo% DATE : 05/02/01%% FUNCTION SYNOPSIS: % y = fade_fs(x,L)%% Parameter Descripti on:output sig nal% x : in put sig nalnu mber of in depe ndent Rayleighfadi ng process°%********************************************************** fun ctio n y = fade_fs(x ,L) % Gen erate bivariate Gaussia n un correlated% ran dom variablestmpl = 0:1:(L-1);tmpl = exp(-tmpl);tmp(1:2:2*L-1) = tmpl;tmp(2:2:2*L) = tmpl;mu = zeros(1,2*L);C = 0.5*diag(tmp);x_le n = len gth(x);r = mvn rnd(mu,C,x_le n);% Convert to polar coord in ates and compute magn itudex = x(:);y = zeros(x_le n,1);for i = 1:L,z = r(:,2*i-1) + j*r(:,2*i);env = abs(z); %phi = an gle(z);tmp_y = en v.*x;tmp_y = [zeros(i-1,1); tmp_y(1:x_le n-i+1)];y = y + tmp_y;end°%**********************************************************Q%**********************************************************************% This program computes the average BER of a DS-SS/BPSK% com mun icati on system with binary BCH code in the AWGN cha nnelAUTHOR: Wen bi n Luo % DATE : 04/28/01%% fin al11_extra.m% °%**********************************************************************%fun ctio n Plot_Pe = fin al11_extra() clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 2500;plot_EbNo = -20:2:10;for EbNo = -20:2:10,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);x_org = x;%adds error-correct ing codeenc_N = 15; enc_K = 5; %7/4 or 15/5x(fi nd(x < 0)) = 0;x = en code(x,e nc_N,e nc_K,'bch');x = x';x(fin d(x == 0)) = -1;%DS-SS modulate symbols with user code c = bingen( N); y = ds_mod(c(:),x);%scale by appropriate power factory = sqrt(p)*y;%add AWGN to sig naly = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;%decode error-correct ing codex_de(fi nd(x_de < 0)) = 0;x_de = decode(x_de,e nc_N,e nc_K,'bch');x_de = x_de';x_de(fi nd(x_de == 0)) = -1;% -----------------------------------Pe = len gth(fi nd(x_org - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo% ------------------------------------------- %return;%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/Nosemilogy(plot_EbNo,Plot_Pe,'bo-')xlabel('Eb/No (dB)')ylabel('BER')s=spri ntf('BER versus Eb/No with binary BCH code in the AWGN cha nn el'); title(s);Q%**********************************************************************% This program computes the average BER of a DS-SS/BPSK% com mun icati on system with binary BCH code in the AWGN cha nnel%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% fin al11_extra.m%Q%**********************************************************************%fun ctio n Plot_Pe = fin al11_extra() clear all;%close all;format Io ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 2500; plot_EbNo = -20:2:10; for EbNo = -20:2:10,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m); x_org = x;%adds error-correct ing codeenc_N = 15; enc_K = 5; %7/4 or 15/5 x(fi nd(x < 0)) = 0;x = en code(x,e nc_N,e nc_K,'bch');x = x';x(fin d(x == 0)) = -1;%DS-SS modulate symbols with user code c = bingen( N);y = ds_mod(c(:),x);%scale by appropriate power factor y = sqrt(p)*y;%add AWGN to sig naly = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;%decode error-correct ing codex_de(fi nd(x_de < 0)) = 0;x_de = decode(x_de,e nc_N,e nc_K,'bch');x_de = x_de';x_de(fi nd(x_de == 0)) = -1;% -----------------------------------Pe = len gth(fi nd(x_org - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo% -------------------------------------------%return;% -------------------------------------------%display the calculated Pd and Pfa Plot_Pe%plot Pe versus Eb/No semilogy(plot_EbNo,Plot_Pe,'bo-') xlabel('Eb/No (dB)') ylabel('BER') s=spri ntf('BER versus Eb/No with binary BCH code in the AWGN cha nn el');title(s);°%**********************************************************************% This program computes the average BER of a DS-SS/BPSK% com mun icati on system with binary BCH code in the AWGN cha nnel%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% fin al11_extra.m%Q%**********************************************************************%fun ctio n Plot_Pe = fin al11_extra() clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 2500;plot_EbNo = -20:2:10;for EbNo = -20:2:10,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m); x_org = x;%adds error-correct ing codeenc_N = 15; enc_K = 5; %7/4 or 15/5x(fi nd(x < 0)) = 0;x = en code(x,e nc_N,e nc_K,'bch');x = x';x(fin d(x == 0)) = -1;%DS-SS modulate symbols with user code c = bingen( N);y = ds_mod(c(:),x);%scale by appropriate power factor y = sqrt(p)*y;%add AWGN to sig naly = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;%decode error-correct ing codex_de(fi nd(x_de < 0)) = 0;x_de = decode(x_de,e nc_N,e nc_K,'bch');x_de = x_de';x_de(fi nd(x_de == 0)) = -1;Pe = len gth(fi nd(x_org - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo% -------------------------------------------%return;% -------------------------------------------%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/Nosemilogy(plot_EbNo,Plot_Pe,'bo-')xlabel('Eb/No (dB)')ylabel('BER')s=spri ntf('BER versus Eb/No with binary BCH code in the AWGN cha nn el');title(s);Q%*********************************************************************% This program computes the average BER of a DS-SS/BPSK% com mun icati on system in the prese nee of pulsed no ise jammi ng % and AWGN%% AUTHOR: Wenbin Luo% DATE : 04/28/01fin al12.m°%******************************************************************** %fun ctio n Plot_Pe = fin al12() clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;ro = 0.2; %1,0.4, 0.2x_n um = 10000; plot_EbNo = -20:2:10;for EbNo = -20:2:10,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);%DS-SS modulate symbols with user code c = bingen( N);y = ds_mod(c(:),x);%scale by appropriate power factor y = sqrt(p)*y;%add Pulsed Noise Jammer to sig naly = [awg n(y(1:ro*le ngth(y)),1/ro); y((ro*le ngth(y)+1):le ngth(y))];%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo% -------------------------------------------%return;% -------------------------------------------%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'m*-')xlabel('10log_{10}[(P/J)(W/R)] (dB)')ylabel('BER')s=spri ntf('BER versus 10log_{10}[(P/J)(W/R)] in pulsed n oise jammi ng and AWGN'); title(s);Q%*********************************************************************% This program computes the average BER of a DS-SS/BPSK% com mun icatio n system in barrage no ise jammi ng and AWGN%AUTHOR: Wen bi n LuoDATE : 05/02/01% fin al12_extra.m°%********************************************************************% fun ctio n Plot_Pe = fin al12_extra() clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 10000;% --------------------------------------------------------%con vert back from dBEb_No = 5; % 2, 4, 6 dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;% -------------------------------------------------------- plot_EbNj = 0:2:50; for EbNj = 0:2:50,%con vert back from dBEb_Nj = EbNj; %dBEb_Nj = 10.A(Eb_Nj/10);Nj = Eb / Eb_Nj;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);%DS-SS modulate symbols with user code c = bingen( N);y = ds_mod(c(:),x);%scale by appropriate power factor y = sqrt(p)*y; %add barrage noise jamming and AWGN to signal y = awg n( y,(Nj/2)+1);%y = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo% -------------------------------------------%return;% -------------------------------------------%display the calculated Pd and Pfa Plot_Pe%plot Pe versus Eb/No %subplot(2,1,1)semilogy(plot_EbNj,Plot_Pe,'m*-')xlabel('10log_{10}[(P/J)(W/R)] (dB)')ylabel('BER')and AWGN'); s=spri ntf('BER versus 10log_{10}[(P/J)(W/R)] in barrage no ise jammi ng title(s);grid on;Q%********************************************************************* % This programcomputes the average BER in Rayleigh fadi ng% and AWGN%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% fin al21.m%°%********************************************************************%fun ctio n Plot_Pe = fin al21() clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 10000;plot_EbNo = -30:2:30; %-20:2:10;for EbNo = -30:2:30,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m); x_origi nal = x;x = sqrt(p)*x;%ge nerate Rayleigh fadi ng[en v,phi] = fade(le ngth(x),0.5);%ge nerate faded seque nee x = en v.*x';x = x';%DS-SS modulate symbols with user code e = bingen( N);y = ds_mod(c(:),x);%seale by appropriate power factor %y = sqrt(p)*y;%add AWGN to sig nal y = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x_orig inal - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo% -------------------------------------------%return;% -------------------------------------------%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'r A-')xlabel('Eb/No (dB)')ylabel('BER')s=spri ntf('BER versus Eb/No in Rayleigh fadi ng and AWGN'); title(s); grid on;Q%*********************************************************************% This program simulates a predetecti on selective comb ining% receiver for a Rayleigh fading cha nnel%% AUTHOR: Wenbin Luo% DATE : 04/28/01%fin al21 extra.m°%******************************************************************** clear all; %close all;format Io ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 10000;plot_EbNo = -30:2:20; %-20:2:10;for EbNo = -30:2:20,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10); %assume No = 2;No = 2;Eb = No * Eb_No; %calculate power pTc = 1;Ts = N * Tc; p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m); x_origi nal = x;x = sqrt(p)*x;%ge nerate Rayleigh fadi ng[en v1,e nv2] = fade_diversity(le ngth(x),0.5);%ge nerate faded seque neex_fad1 = en v1.*x';x_fad1 = x_fad1';x_fad2 = en v2.*x';x_fad2 = x_fad2:%DS-SS modulate symbols with user code c = bingen( N);y_fad1 = ds_mod(c(:),x_fad1);y_fad2 = ds_mod(c(:),x_fad2);%scale by appropriate power factor %y = sqrt(p)*y;%add AWGN to sig nal y_fad1 = awg n( y_fad1,1); y_fad2 = awg n( y_fad2,1);%DS-SS demodulate symbols with user code x_de1 = ds_demod(c(:),y_fad1); x_de2 = ds_demod(c(:),y_fad2);%choose branch with larger BENR ind1 = fin d(abs(x_de1) >= abs(x_de2)); ind2 = fin d(abs(x_de1) < abs(x_de2));x_de(i nd1) = x_de1(i nd1);x_de(i nd2) = x_de2(i nd2);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x_orig inal - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo%display the calculated Pd and PfaPlot Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'ro-')xlabel('Eb/No (dB)')ylabel('BER')s=spri ntf('BER versus Eb/No in Rayleigh fadi ng and AWGN'); title(s); grid on;Q%*********************************************************************% This program computes the average BER in Rayleigh fadi ng% and AWGN%% AUTHOR: Wenbin Luo% DATE : 04/28/01%% fin al22.m% °%******************************************************************** clear all; %close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];N = 16;x_n um = 10000;plot_EbNo = -20:2:30; %-20:2:10;for EbNo = -20:2:30,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m); x_origi nal = x;x = sqrt(p)*x;%ge nerate freque ncy selective Rayleigh fading tmp = fade_fs(x,7);x = tmp';%DS-SS modulate symbols with user code c = bingen( N);y = ds_mod(c(:),x);%scale by appropriate power factor %y = sqrt(p)*y;%add AWGN to sig naly = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x_orig inal - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'r*-')xlabel('Eb/No (dB)')ylabel('BER')s=spri ntf('BER versus Eb/No in Rayleigh fadi ng and AWGN'); title(s);grid on;Q%********************************************************************* % This program computes the average BER versus Eb/No of K users% tran smitt ing BPSK symbols at an equal power level using a% DS-CDMA scheme assum ming perfect syn chro nism and orthog onal % codes in AWGN%% AUTHOR: Wenbin Luo% DATE : 04/29/01%% fin al31.m% °%******************************************************************** clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];K = 16;N = 32;x_n um = 5000; plot_EbNo = -20:3:10; for EbNo = -20:3:10,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);%DS-SS modulate symbols with user codeUserCode = hadamard(N);c = UserCode(1,:);y = ds_mod(c(:),x);%add other users' sig nal as in terfere neefor t = 2:1:K,tmp_x =bingen(x_nu m);tmp = UserCode(t,:);tmp_y =ds_mod(tmp(:),tmp_x);y = y + tmp_y;end % t%seale by appropriate power factor y = sqrt(p)*y;%add AWGN to sig naly = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'m*-')xlabel('Eb/No (dB)')ylabel('BER')title('BER versus Eb/No using DS-CDMA: perfect synchronism between users'); grid on; Q%********************************************************************** % This program computes the average BER versus Eb/No of K users% tran smitt ing BPSK symbols at an equal power level using a% slow FH-MA scheme assum ming perfect synchronism and orthogo nal % codes in AWGNAUTHOR: Wen bi n Luo % DATE : 05/01/01%% fin al31_fh.m°%********************************************************************* clear all; %close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];K = 16; %4,8,16N = 32;x_n um = 5000;plot_EbNo = -20:3:10;for EbNo = -20:3:10,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);%DS-SS modulate symbols with user codeUserCode = fh(N,K);c = UserCode(1,:);y = ds_mod(c(:),x);%add other users' sig nal as in terfere neefor t = 2:1:K,tmp_x =bingen(x_nu m);tmp = UserCode(t,:);tmp_y =ds_mod(tmp(:),tmp_x);y = y + tmp_y;end % t%scale by appropriate power factory = sqrt(p)*y;%add AWGN to sig nal y = awg n_complex(y,1);%DS-SS demodulate symbols with user code x_de = real(ds_demod(conj(c(:)),y));%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'m*-')xlabel('Eb/No (dB)')ylabel('BER') title('BER versus Eb/No using slow FH-MA: perfect synchronism betwee n users');grid on;°%*********************************************************************% This program computes the average BER versus Eb/No of K users% tran smitt ing BPSK symbols at an equal power level using a% DS-CDMA scheme assum ming a ran dom asynchronism betwee n users %% AUTHOR: Wenbin Luo% DATE : 04/29/01%% fin al32.m%°%******************************************************************** clear all;%close all;%set up the threshold VtVt = 0;Plot_Pe =[];K = 4;N = 32;x_n um = 30000;%ge nerates a ran dom asynchronism betwee n users asyn = ran d(1,K)*6; %as yn = floor(as yn);asyn = floor(as yn) + 1;plot_EbNo = -20:3:50;for EbNo = -20:3:50,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);%DS-SS modulate symbols with user codeUserCode = hadamard(N);c = UserCode(1,:);y = ds_mod(c(:),x);%add other users' sig nal as in terfere neefor t = 2:1:K,tmp_x = bingen(x_nu m);tmp = UserCode(t,:);tmp_y = ds_mod(tmp(:),tmp_x);tmpY_le n = len gth(tmp_y);tmp_y = [tmp_y((as yn( t)+1):tmpY_le n); tmp_y(1:as yn( t))];y = y + tmp_y;end % t%scale by appropriate power factory = sqrt(p)*y;%add AWGN to sig naly = awg n(y,1);%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);%decisi on x_de(fi nd(x_de < 0)) = -1;x_de(fi nd(x_de >=0)) = 1;Pe = len gth(fi nd(x - x_de))/x_ num;Plot_Pe = [Plot_Pe Pe];end %e nd for EbNo%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,'bs-')xlabel('Eb/No (dB)')ylabel('BER')title('BER versus Eb/No using DS-CDMA: a ran dom asynchronism betwee n users'); grid on;Q%************************************************************************ % This program computes the average BER versus Eb/No of K users% tran smitt ing BPSK symbols at an equal power level using a% slow FH-MA scheme assum ming a ran dom asynchronism betwee n users%% AUTHOR: Wenbin Luo % DATE : 04/29/01final32 fh.m°%************************************************************************ clear all;%close all;format lo ng;%set up the threshold VtVt = 0;Plot_Pe =[];K = 32;N = 32;x_n um = 10000;%ge nerates a ran dom asynchronism betwee n users asyn = ran d(1,K)*6;%as yn = floor(as yn);asyn = floor(as yn) + 1;plot_EbNo = -20:3:50;for EbNo = -20:3:50,%con vert back from dBEb_No = EbNo; %dBEb_No = 10.A(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%ge nerate BPSK symbols ran domly with value +1 or -1 x = bingen(x_nu m);%DS-SS modulate symbols with user codeUserCode = fh(N,K);c = UserCode(1,:);y = ds_mod(c(:),x);%add other users' sig nal as in terfere nee for t = 2:1:K,tmp_x = bingen(x_nu m); tmp = UserCode(t,:);tmp_y = ds_mod(tmp(:),tmp_x);tmpY_le n = len gth(tmp_y);tmp_y = [tmp_y((as yn( t)+1):tmpY_le n); tmp_y(1:as yn( t))];y = y + tmp_y;end % t。