⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdma codes.txt

📁 this is the code for orthogonal code divison multiple access
💻 TXT
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function outvec = ovsf(sf, code)
% outvec = ovsf(class, code)
% HADAMARD SEQUENCES.
% sf = spreading factor of the code.
% Class = log of the spreading factor of the OVSF code:- ie, Class = log2(SF).
% Code = code number from the particular branch.
% ----------------- Completed By Charan Litchfield --------------------------------
% ------------------------- 6/10/03 -----------------------------------------------
% ---------------------------17:27-------------------------------------------------
% ---------------------------------------------------------------------------------

if nargin ~= 2
    error('Must have two input arguments');
end
class = log2(sf);
[m, n] = size(class);
if (m~=1 | n~= 1)
    error('First input argument must be a scalar');
end
if (fix(class) ~= class | class < 1 | class > 12)
    error('First input argument must be an integer between 1 and 12');
end
[m, n] = size(code);
if (m~=1 | n~= 1)
    error('Second input argument must be a scalar');
end
if (fix(code) ~= code | code < 0 | code > pow2(class)-1)
    error('Second input argument must be an integer between 0 and pow2(class)-1.');
end
h = 1;
for i = 1:class
    h = [h h; h -h];
end
outvec = h(code+1, :);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function outvec = dllsc(scgroup, pgroup, sgroup, alt)
% outvec = dllsc(scgroup, pgroup, sgroup, alt).
% Gold Code Generator.
% scgroup must be 0...63.
% pgroup must be 0...7.
% sgroup must be 0...15.
% alt selects the scrambling code for the downlink operation.
% ------------------------ written by Charan Litchfield ---------------------------
% --------------------------------6/10/03------------------------------------------
% --------------------------------18:10--------------------------------------------
if nargin ~= 4
    error('Need to input four arguments: scgroup (0..63), pgroup (0..7), sgroup (0..15) and alt (0..2).');
end
[m, n] = size(scgroup);
if (m~=1 | n~= 1)
    error('Input arguments must be scalar');
end
if (scgroup<0 | scgroup>63)
    error('scgroup is outside the range 0..63');
end
[m, n] = size(pgroup);
if (m~=1 | n~= 1)
    error('Input arguments must be scalar');
end
if (pgroup<0 | pgroup>7)
    error('pgroup is outside the range 0..7');
end
[m, n] = size(sgroup);
if (m~=1 | n~= 1)
    error('Input arguments must be scalar');
end
if (sgroup<0 | sgroup>15)
    error('sgroup is outside the range 0..15');
end
[m, n] = size(alt);
if (m~=1 | n~= 1)
    error('Input arguments must be scalar');
end
switch alt
case 0
   n = 16.*(8.*scgroup+pgroup)+sgroup;          % no compressed mode, code number = 0..8191
case 1
    n = 16.*(8.*scgroup+pgroup)+sgroup+8192;    % compressed mode left alternative, code number = 8192..16383
case 2
    n = 16.*(8.*scgroup+pgroup)+sgroup+16384;   % compressed mode right alternative, code number = 16384..24575
otherwise
    error('alt is outside the range 0..2');
end
x = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];      % initialize x shift register
y = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];      % initialize y shift register

% we need x(i+n), so run x free for n chips
for i=1:n
    temp = x(18);
    x(18) = (x(1)|x(8)) &~(x(1)&x(8));      % faster than xor(x(1), x(8))
    x(1:16) = x(2:17);
    x(17) = temp;
end

% now generate first 38400 chips of downlink long scrambling code
outvec(1:38400) = 1+1i;                                 % mem preallocation to speed up
for i = 1:38400
    rl = (x(1)|y(1)) & ~(x(1)&y(1));
    temp = y(6)+y(7)+y(9)+y(10)+y(11)+y(12)+y(13)+y(14)+y(15)+y(16)+x(5)+x(7)+x(16);
    temp = temp - 2.*fix(temp./2);
    outvec(i) = complex(1-2.*rl, 1-2.*temp);            % output as a complex number
    temp = x(18);
    x(18) = (x(1)|x(8)) & ~(x(1)&x(8));
    x(1:16) = x(2:17);
    x(17) = temp;
    temp = y(18);
    y(18) = y(1) + y(6) + y(8) + y(11);
    y(18) = y(18) - 2.*fix(y(18)./2);
    y(1:16) = y(2:17);
    y(17) = temp;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spreading::::::::::::::::::::
%%%%  Generate data/modulation Vector - called d %%%%%%%%%%%%%%
for n = 1:length(d)
    Spreaded_Data(:,1+(n-1)*length(code):n*length(code)) = d(:,n)*code;
end
% Scramble
Y = Spreaded_Data.*Scrambling_Code(1:length(Spreaded_Data));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Despreading %%%%%%%%%%%%%%%%%%%%
X = Y.*Scrambling_Code(1:length(Spreaded_Data));  % Descramble First
for n = 1:length(d)
    Despread(:,n) = code*X(:,1+(n-1)*length(code):n*length(code))';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -