cdma的MATLAB仿真源程序

更新时间:2023-11-11 20:54:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

%*************************************************************************************

% This function pertains to the addition of AWGN with mean zero and % parameter 'variance' to an input signal. %

% AUTHOR: Wenbin Luo % DATE : 04/12/01 % % SYNOPSIS: y = awgn(x,var) % x ---> input signal % var ---> variance

% y ---> y = x + AWGN

%***********************************************************************************

function y = awgn(x,var) w = randn(1,length(x)); w = w - mean(w)*ones(size(w)); w = sqrt(var)*(w / std(w)); x = x(:); w = w(:); y = x + w;

%*************************************************************************************

% 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 ---> input signal (row vector)

% y ---> tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vector)

%***********************************************************************************

function y = ds_mod(c,x) tmp = c*x; y = tmp(:);

%*************************************************************************************

% This function generates random +1/-1 sequence with independent identically % distributed symbols %

% AUTHOR: Wenbin Luo

% DATE : 04/28/01 % % SYNOPSIS: x = bingen(L)

% L ---> number of random symbols

%***********************************************************************************

function x = bingen(L)

%generate L symbols randomly with value +1 or -1 x = rand(1,L);

x(find(x<0.5)) = -1; x(find(x >=0.5)) = 1;

%*************************************************************************************

% This function does the DS-SS modulation %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % SYNOPSIS: x = ds_demod(c,y) % c ---> user code (column vector)

% y ---> tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vector) % x ---> input signal (row vector)

%***********************************************************************************

function x = ds_demod(c,y)

tmp = reshape(y, length(c), length(y)/length(c)); tmp = tmp';

%x is a column 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 ---> input signal (row vector)

% y ---> tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vector)

%***********************************************************************************

function y = ds_mod(c,x) tmp = c*x; y = tmp(:);

%*********************************************************** % This mfunction generates faded envelope and phase % corresponding to Rayleigh fading %

% AUTHOR: Wenbin Luo % DATE : 04/27/01 %

% FUNCTION SYNOPSIS: % [env,phi] = fade(L,para) %

% Parameter Description:

% L : number of samples needed % variance : variance

%********************************************************** function [env,phi] = fade(L,variance) % Error check if variance <= 0

error('Positive variance needed') elseif nargin ~= 2

error('Insufficient input parameters') end

% Generate bivariate Gaussian uncorrelated % random variables mu = zeros(1,2);

C = variance*eye(2,2); r = mvnrnd(mu,C,L);

% Convert to polar coordinates and compute % magnitude and phase z = r(:,1) + j*r(:,2);

env = abs(z); phi = angle(z);

%********************************************************** %*********************************************************** % This mfunction generates two channels of faded % envelope and phase corresponding to % Rayleigh fading %

% AUTHOR: Wenbin Luo % DATE : 04/27/01

%

% FUNCTION SYNOPSIS:

% [env,phi] = fade_diversity(L,para) %

% Parameter Description:

% L : number of samples needed % variance : variance

%********************************************************** function [env1,env2] = fade_diversity(L,variance) % Error check if variance <= 0

error('Positive variance needed') elseif nargin ~= 2

error('Insufficient input parameters') end

% Generate bivariate Gaussian uncorrelated % random variables mu = zeros(1,4);

C = variance*eye(4,4); r = mvnrnd(mu,C,L);

% Convert to polar coordinates and compute % magnitude and phase z1 = r(:,1) + j*r(:,2); z2 = r(:,3) + j*r(:,4); env1 = abs(z1); env2 = abs(z2);

%********************************************************** %*********************************************************** % This mfunction generates frequency selective % Rayleigh fading %

% AUTHOR: Wenbin Luo % DATE : 05/02/01 %

% FUNCTION SYNOPSIS: % y = fade_fs(x,L) %

% Parameter Description: % y : output signal % x : input signal % L : number of independent Rayleigh % fading process

%********************************************************** function y = fade_fs(x,L)

% Generate bivariate Gaussian uncorrelated % random variables tmp1 = 0:1:(L-1); tmp1 = exp(-tmp1); tmp(1:2:2*L-1) = tmp1; tmp(2:2:2*L) = tmp1;

mu = zeros(1,2*L); C = 0.5*diag(tmp); x_len = length(x);

r = mvnrnd(mu,C,x_len);

% Convert to polar coordinates and compute magnitude x = x(:);

y = zeros(x_len,1); for i = 1:L,

z = r(:,2*i-1) + j*r(:,2*i);

env = abs(z); %phi = angle(z); tmp_y = env.*x;

tmp_y = [zeros(i-1,1); tmp_y(1:x_len-i+1)]; y = y + tmp_y; end

%**********************************************************

%********************************************************************** % This program computes the average BER of a DS-SS/BPSK % communication system with binary BCH code in the AWGN channel %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final11_extra.m %

%**********************************************************************

%function Plot_Pe = final11_extra()

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 2500;

plot_EbNo = -20:2:10; for EbNo = -20:2:10,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num); x_org = x;

-ds error-correcting code

enc_N = 15; enc_K = 5; %7/4 or 15/5 x(find(x < 0)) = 0;

x = encode(x,enc_N,enc_K,'bch'); x = x';

x(find(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;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Tcode error-correcting code x_de(find(x_de < 0)) = 0;

x_de = decode(x_de,enc_N,enc_K,'bch'); x_de = x_de';

x_de(find(x_de == 0)) = -1;

%-------------------------------------

Pe = length(find(x_org - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end 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=sprintf('BER versus Eb/No with binary BCH code in the AWGN channel'); title(s);

%********************************************************************** % This program computes the average BER of a DS-SS/BPSK % communication system with binary BCH code in the AWGN channel %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final11_extra.m %

%**********************************************************************

%function Plot_Pe = final11_extra()

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 2500;

plot_EbNo = -20:2:10; for EbNo = -20:2:10,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num); x_org = x;

-ds error-correcting code

enc_N = 15; enc_K = 5; %7/4 or 15/5 x(find(x < 0)) = 0;

x = encode(x,enc_N,enc_K,'bch'); x = x';

x(find(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;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Tcode error-correcting code x_de(find(x_de < 0)) = 0;

x_de = decode(x_de,enc_N,enc_K,'bch'); x_de = x_de';

x_de(find(x_de == 0)) = -1;

%-------------------------------------

Pe = length(find(x_org - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end 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=sprintf('BER versus Eb/No with binary BCH code in the AWGN channel'); title(s);

%********************************************************************** % This program computes the average BER of a DS-SS/BPSK % communication system with binary BCH code in the AWGN channel %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final11_extra.m %

%**********************************************************************

%function Plot_Pe = final11_extra()

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 2500;

plot_EbNo = -20:2:10;

for EbNo = -20:2:10,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num); x_org = x;

-ds error-correcting code

enc_N = 15; enc_K = 5; %7/4 or 15/5 x(find(x < 0)) = 0;

x = encode(x,enc_N,enc_K,'bch'); x = x';

x(find(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;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code

x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Tcode error-correcting code x_de(find(x_de < 0)) = 0;

x_de = decode(x_de,enc_N,enc_K,'bch'); x_de = x_de';

x_de(find(x_de == 0)) = -1;

%-------------------------------------

Pe = length(find(x_org - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end 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=sprintf('BER versus Eb/No with binary BCH code in the AWGN channel'); title(s);

%********************************************************************* % This program computes the average BER of a DS-SS/BPSK % communication system in the presence of pulsed noise jamming % and AWGN %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final12.m %

%********************************************************************

%function Plot_Pe = final12()

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

ro = 0.2; %1, 0.4, 0.2 x_num = 10000;

plot_EbNo = -20:2:10; for EbNo = -20:2:10,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num);

%DS-SS modulate symbols with user code c = bingen(N); y = ds_mod(c(:),x);

%scale by appropriate power factor y = sqrt(p)*y;

-d Pulsed Noise Jammer to signal

y = [awgn(y(1:ro*length(y)),1/ro); y((ro*length(y)+1):length(y))];

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1;

x_de(find(x_de >=0)) = 1;

Pe = length(find(x - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%--------------------------------------------- %return;

%---------------------------------------------

%display the calculated Pd and Pfa Plot_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=sprintf('BER versus 10log_{10}[(P/J)(W/R)] in pulsed noise jamming and AWGN'); title(s);

%********************************************************************* % This program computes the average BER of a DS-SS/BPSK % communication system in barrage noise jamming and AWGN %

% AUTHOR: Wenbin Luo % DATE : 05/02/01 % % final12_extra.m %

%********************************************************************

% function Plot_Pe = final12_extra()

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 10000;

%---------------------------------------------------------- %convert back from dB Eb_No = 5; % 2, 4, 6 dB Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%----------------------------------------------------------

plot_EbNj = 0:2:50; for EbNj = 0:2:50,

%convert back from dB Eb_Nj = EbNj; ?

Eb_Nj = 10.^(Eb_Nj/10); Nj = Eb / Eb_Nj;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num);

%DS-SS modulate symbols with user code c = bingen(N); y = ds_mod(c(:),x);

%scale by appropriate power factor y = sqrt(p)*y;

-d barrage noise jamming and AWGN to signal y = awgn(y,(Nj/2)+1); %y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x - x_de))/x_num;

Plot_Pe = [Plot_Pe Pe]; end %end 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')

s=sprintf('BER versus 10log_{10}[(P/J)(W/R)] in barrage noise jamming and AWGN'); title(s); grid on;

%********************************************************************* % This program computes the average BER in Rayleigh fading % and AWGN %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final21.m %

%********************************************************************

%function Plot_Pe = final21()

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 10000;

plot_EbNo = -30:2:30; %-20:2:10; for EbNo = -30:2:30,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num); x_original = x; x = sqrt(p)*x;

%generate Rayleigh fading [env,phi] = fade(length(x),0.5);

%generate faded sequence x = env.*x'; x = x';

%DS-SS modulate symbols with user code c = bingen(N); y = ds_mod(c(:),x);

%scale by appropriate power factor %y = sqrt(p)*y;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x_original - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%--------------------------------------------- %return;

%---------------------------------------------

%display the calculated Pd and Pfa Plot_Pe

%plot Pe versus Eb/No %subplot(2,1,1)

semilogy(plot_EbNo,Plot_Pe,'r^-') xlabel('Eb/No (dB)') ylabel('BER')

s=sprintf('BER versus Eb/No in Rayleigh fading and AWGN'); title(s); grid on;

%********************************************************************* % This program simulates a predetection selective combining % receiver for a Rayleigh fading channel %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final21_extra.m %

%********************************************************************

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 10000;

plot_EbNo = -30:2:20; %-20:2:10; for EbNo = -30:2:20,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10);

%assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num); x_original = x; x = sqrt(p)*x;

%generate Rayleigh fading

[env1,env2] = fade_diversity(length(x),0.5);

%generate faded sequence x_fad1 = env1.*x'; x_fad1 = x_fad1';

x_fad2 = env2.*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;

-d AWGN to signal y_fad1 = awgn(y_fad1,1); y_fad2 = awgn(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 = find(abs(x_de1) >= abs(x_de2)); ind2 = find(abs(x_de1) < abs(x_de2));

x_de(ind1) = x_de1(ind1);

x_de(ind2) = x_de2(ind2);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x_original - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%display the calculated Pd and Pfa Plot_Pe

%plot Pe versus Eb/No %subplot(2,1,1)

semilogy(plot_EbNo,Plot_Pe,'ro-') xlabel('Eb/No (dB)') ylabel('BER')

s=sprintf('BER versus Eb/No in Rayleigh fading and AWGN'); title(s); grid on;

%********************************************************************* % This program computes the average BER in Rayleigh fading % and AWGN %

% AUTHOR: Wenbin Luo % DATE : 04/28/01 % % final22.m %

%********************************************************************

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

N = 16;

x_num = 10000;

plot_EbNo = -20:2:30; %-20:2:10;

for EbNo = -20:2:30,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num); x_original = x; x = sqrt(p)*x;

%generate frequency 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;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x_original - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%display the calculated Pd and Pfa

%DS-SS modulate symbols with user code UserCode = hadamard(N); c = UserCode(1,:); y = ds_mod(c(:),x);

-d other users' signal as interference for t = 2:1:K,

tmp_x = bingen(x_num); tmp = UserCode(t,:);

tmp_y = ds_mod(tmp(:),tmp_x);

tmpY_len = length(tmp_y);

tmp_y = [tmp_y((asyn(t)+1):tmpY_len); tmp_y(1:asyn(t))];

y = y + tmp_y; end % t

%scale by appropriate power factor y = sqrt(p)*y;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%display the calculated Pd and Pfa Plot_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 random asynchronism between users');

grid on;

%************************************************************************ % This program computes the average BER versus Eb/No of K users % transmitting BPSK symbols at an equal power level using a % slow FH-MA scheme assumming a random asynchronism between users %

% AUTHOR: Wenbin Luo % DATE : 04/29/01 % % final32_fh.m %

%************************************************************************

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

K = 32; N = 32;

x_num = 10000;

%generates a random asynchronism between users asyn = rand(1,K)*6; %asyn = floor(asyn); asyn = floor(asyn) + 1;

plot_EbNo = -20:3:50; for EbNo = -20:3:50,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num);

%DS-SS modulate symbols with user code UserCode = fh(N,K); c = UserCode(1,:); y = ds_mod(c(:),x);

-d other users' signal as interference for t = 2:1:K,

tmp_x = bingen(x_num); tmp = UserCode(t,:);

tmp_y = ds_mod(tmp(:),tmp_x);

tmpY_len = length(tmp_y);

tmp_y = [tmp_y((asyn(t)+1):tmpY_len); tmp_y(1:asyn(t))];

y = y + tmp_y; end % t

%scale by appropriate power factor y = sqrt(p)*y;

-d AWGN to signal y = awgn_complex(y,1);

%DS-SS demodulate symbols with user code x_de = real(ds_demod(conj(c(:)),y));

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%display the calculated Pd and Pfa Plot_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 slow FH-MA: a random asynchronism between users'); grid on;

Plot_Pe

%plot Pe versus Eb/No %subplot(2,1,1)

semilogy(plot_EbNo,Plot_Pe,'r*-') xlabel('Eb/No (dB)') ylabel('BER')

s=sprintf('BER versus Eb/No in Rayleigh fading and AWGN'); title(s); grid on;

%********************************************************************* % This program computes the average BER versus Eb/No of K users % transmitting BPSK symbols at an equal power level using a % DS-CDMA scheme assumming perfect synchronism and orthogonal % codes in AWGN %

% AUTHOR: Wenbin Luo % DATE : 04/29/01 % % final31.m %

%********************************************************************

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

K = 16; N = 32;

x_num = 5000;

plot_EbNo = -20:3:10; for EbNo = -20:3:10,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No;

êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num);

%DS-SS modulate symbols with user code UserCode = hadamard(N); c = UserCode(1,:); y = ds_mod(c(:),x);

-d other users' signal as interference for t = 2:1:K,

tmp_x = bingen(x_num); tmp = UserCode(t,:);

tmp_y = ds_mod(tmp(:),tmp_x); y = y + tmp_y; end % t

%scale by appropriate power factor y = sqrt(p)*y;

-d AWGN to signal y = awgn(y,1);

%DS-SS demodulate symbols with user code x_de = ds_demod(c(:),y);

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%display the calculated Pd and Pfa Plot_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;

%********************************************************************** % This program computes the average BER versus Eb/No of K users % transmitting BPSK symbols at an equal power level using a % slow FH-MA scheme assumming perfect synchronism and orthogonal % codes in AWGN %

% AUTHOR: Wenbin Luo % DATE : 05/01/01 % % final31_fh.m %

%*********************************************************************

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

K = 16; %4,8,16 N = 32;

x_num = 5000;

plot_EbNo = -20:3:10; for EbNo = -20:3:10,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1

x = bingen(x_num);

%DS-SS modulate symbols with user code UserCode = fh(N,K); c = UserCode(1,:); y = ds_mod(c(:),x);

-d other users' signal as interference for t = 2:1:K,

tmp_x = bingen(x_num); tmp = UserCode(t,:);

tmp_y = ds_mod(tmp(:),tmp_x); y = y + tmp_y; end % t

%scale by appropriate power factor y = sqrt(p)*y;

-d AWGN to signal y = awgn_complex(y,1);

%DS-SS demodulate symbols with user code x_de = real(ds_demod(conj(c(:)),y));

Tcision

x_de(find(x_de < 0)) = -1; x_de(find(x_de >=0)) = 1;

Pe = length(find(x - x_de))/x_num; Plot_Pe = [Plot_Pe Pe]; end %end for EbNo

%display the calculated Pd and Pfa Plot_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 between users'); grid on;

%********************************************************************* % This program computes the average BER versus Eb/No of K users

% transmitting BPSK symbols at an equal power level using a % DS-CDMA scheme assumming a random asynchronism between users %

% AUTHOR: Wenbin Luo % DATE : 04/29/01 % % final32.m %

%********************************************************************

clear all; %close all;

format long;

%set up the threshold Vt Vt = 0;

Plot_Pe = [];

K = 4; N = 32;

x_num = 30000;

%generates a random asynchronism between users asyn = rand(1,K)*6; %asyn = floor(asyn); asyn = floor(asyn) + 1;

plot_EbNo = -20:3:50; for EbNo = -20:3:50,

%convert back from dB Eb_No = EbNo; ?

Eb_No = 10.^(Eb_No/10); %assume No = 2; No = 2;

Eb = No * Eb_No; êlculate power p Tc = 1; Ts = N * Tc; p = Eb / Ts;

%generate BPSK symbols randomly with value +1 or -1 x = bingen(x_num);

本文来源:https://www.bwwdw.com/article/pokv.html

Top