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);
正在阅读:
cdma的MATLAB仿真源程序11-11
关于城市与农村中小学教师流动问题的思考07-22
车用气瓶安装质量保证手册10-14
2019年金融系统反洗钱知识考试多选题100题及答案05-25
网球正手击球教案111-27
通信工程安全操作知识手册(线路手册)05-11
双联总结t Word 文档(3)06-18
公路建设工程安全标准化管理手册04-09
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 源程序
- 仿真
- MATLAB
- cdma
- 2五年级下试卷二
- 浅谈员工忠诚度的影响因素及提升策略
- 三明市人民政府关于印发进一步提高行政机关工作效率若干规定的通知
- 《高级语言程序设计》在线测试15、16、17章内容
- 医院财务管理习题及答案
- 稽查部岗位职责及管理条例
- 计算机组成原理期末试卷含答案(A)(15春)
- 15.01.18 延长石油形势任务教育材料(第二稿)
- 中国旅游资源
- 河三小-陈林-课堂研究阶段性小结
- Microsoft - Excel - 规划求解的说明
- 员工利润分享与事业合伙人计划 方案
- 浅谈网络计划施工管理技术的应用
- 隧道锚杆支护施工方案
- 工程水文学试题-考试专用复习(客观题)
- 列车自动驾驶
- 旅游地理学-教案(保继刚第二版)
- 精选最新版2019年大学生职业生涯规划完整考试题库300题(含标准答案)
- 飞机空调车操作维护维修手册 - 图文
- 组织培养实验一1