cdma的MATLAB仿真源程序

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

% 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

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4