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

📄 cdma_codes产生扩频码随机、h、.m

📁 这是个扩频仿真的有关程序
💻 M
字号:
%cdma_codes.m	create a matrix of spreading codes 
%产生扩频码
%returns	C : L X K matrix of spreading codes
%
%
%given		L : spreading gain扩频增益
%		K_in : in-cell users蜂窝内的用户%		
%     K_out : out-of-cell users蜂窝外的用户
%		code_type : 0 = random 1 = hadamard
%     2 = gold  码型选择0随机、1哈德马德、2GOLD码
%		code_seed : seed for random gen of codes
function [C]=cdma_codes(K_in,K_out,code_type,L,code_seed)


K=K_in+K_out;
c=zeros(L,K);

switch code_type
  case 0,	%random
     rand('state',code_seed);
     c=2*round(rand(L,K))-1;
  case 1,	%hadamard
     if rem(L,4)
       error('Spreading gain must be modulo 4 for hadamard codes');
     else
       codes=hadamard(L);
       if K_in<=L
	      c=codes(:,1:K_in);
       else
      	for i=1:floor(K_in/L)
	        c(:,(i-1)*L+1:i*L)=codes(:,1:L)
         end;
         c(:,floor(K_in/L)*L+1:K_in)=codes(:,1:K_in-floor(K_in/L)*L);
       end; 
       rand('state',code_seed);		%ditribution of out-cell
       c=[c codes(:,ceil(L*rand(1,K_out)))];
     end;
  case 2,	%gold
     if L<=127
        codes=goldlow(L,K_in+K_out);
     else
       n=log2(L+1);
       codes=gold(n,L);
     end;
     if K_in<=L
        c=codes(:,1:K_in);
     else
        for i=1:floor(K_in/L)
	        c(:,(i-1)*L+1:i*L)=codes(:,1:L)
        end;
        c(:,floor(K_in/L)*L+1:K_in)=codes(:,1:K_in-floor(K_in/L)*L);
     end; 
     rand('state',code_seed);		%ditribution of out-cell
     c=[c codes(:,ceil(L*rand(1,K_out)))];
   otherwise
     error(['Code_type ', num2str(code_type),' is invalid']);
end;

for i=1:K		%normalize the codes
   C(:,i)=c(:,i);%/norm(c(:,i));
end





⌨️ 快捷键说明

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