cdma_codes.m
资源名称:Rake.rar [点击查看]
上传用户:pjcrystal
上传日期:2007-08-24
资源大小:5k
文件大小:2k
源码类别:
matlab例程
开发平台:
Matlab
- %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