?? cdma_codes.m
字號:
%G:擴頻增益
%K_in:小區用戶數
%K_out:小區外用戶數
%code_type:0=random 1=hadamard 2=Gold
% coed_seed:seed for random gen of codes
function [C]=cdma_codes(K_in,K_out,code_type,G,code_seed)
% K_in=1;
% K_out=0;
% code_type=2;
% G=31;
% code_seed=rand('state');
K=K_in+K_out;
c=zeros(G,K);
switch code_type
case 0,%random
rand('state',code_seed);
c=2*round(rand(G,K))-1;
case 1,%hadamard
if rem(G,4)
error('Spreading gain must be modulo 4 for hadamard codes');
else
codes=hadamard(G);
if K_in<=G
c=codes(:,1:K_in);
else
for i=1:floor(K_in/G)%floor(a)是取a整數最近的數值
c(:,(i-1)*G+1:i*G)=codes(:,1:G)
end;
c(:,floor(K_in/G)*G+1:K_in)=codes(:,1:K_in-floor(K_in/G)*G);
end;
rand('state',code_seed);
c=[c codes(:,ceil(G*rand(1,K_out)))];
end
case 2,%Gold
if G<=127
codes=GoldLow(G,K_in+K_out);
else
n=log2(G+1);
codes=Gold(n,G);
end
if K_in<=G
c=codes(:,1:K_in);
else
for i=1:floor(K_in/G)
c(:,(i-1)*G+1:i*G)=codes(:,1:G)
end;
c(:,floor(K_in)*G+1:K_in)=codes(:,1:K_in-floor(K_in/G)*G);
end;
rand('state',code_seed);
c=[c codes(:,ceil(G*rand(1,K_out)))];
otherwise
error([Code_type',num2str(code_type),'is invalid']);
end
for i=1:K
C(:,i)=c(:,i);%/norm(c(:,i));
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -