|
楼主 |
发表于 2006-4-22 11:05
|
显示全部楼层
- f_data=1;
- f_chip=11;
- fc=220;
- fs=3*fc;
- N=fs/f_chip;
- data_length=5000;
- M=2;
- num_of_user=4;
- matches=0;
- errors=0;
- count=1;
- SNRpbit=0;
- SNR=SNRpbit;
- rand('state',sum(100*clock));
- randn('state',sum(100*clock));
- numplot=100;
- msg_unsprd=randsrc(data_length,num_of_user,[0:M-1]);
- PN_seq=randsrc(11,num_of_user,[0:1]);
- for s=1:num_of_user
- j=1;
- for i=1:data_length
- for k=j:j+f_chip-1
- mdg_coded(s,k)=msg_unsprd(i,s);
- end;
- msg_spread(s,[j:(j+f_chip-1)])=xor(msg_coded(s,[j:(j+f_chip-1)])',PN_seq([1:f_chip],s));
- j=f_chip*i+1;
- end;
- end;
- len_of_spread=length(msg_spread);
- msg_tr=zeros(num_of_user,data_length*f_chip*N);
- for s=1:num_of_user
- msg_tr(s,:)=dmod(msg_spread(s,:),fc,f_chip,fs,'psk','M');
- end;
- len_of_tr=length(msg_tr);
- for SNRpbit=0:1:7
- SNR=SNRpbit;
- rand('state',sum(100*clock));
- randn('state',sum(100*clock));
- msg_rec_data=zeros(num_of_user,len_of_tr);
- sum_1=zeros(1,len_of_tr);
- msg_received=zeros(1,len_of_tr);
- for s=1:num_of_user
- msg_rec_data(s,:)=awgn(msg_tr(s,:),SNR-10*log10(N),'measured','dB');
- for i=1:data_length
- sum_1=sum_1+msg_rec_data(s,i);
- msg_received=sum_1;
- end;
- end;
- msg_demoded=ddemod(msg_received,fc,f_chip,fs,'measured','dB');
- j=1;
- for i=1:data_length
- msg_de_spread(j:(j+f_chip-1))=xor(msg_received(j:(j+f_chip-1))',PN_seq(1:f_chip,1));
- j=f_chip*i+1;
- end;
- j=1;
- for i=1:data_length
- sum_2=0;
- for k=j:j+f_chip-1
- sum_2=sum_2+msg_de_spread(k);
- end;
- if(sum_2>=7)
- msg_de_spread(i)=1;
- else
- msg_de_spread(i)=0;
- end;
- j=f_chip*i+1;
- end;
- for i=1:data_length
- if(msg_de_spread(i)==msg_unsprd(i,1))
- matches=matches+1;
- else
- errors=errors+1;
- end;
- end;
- BER_awgn(count)=errors/data_length;
- count=count+1;
- errors=0;
- end;
- end;
- X=[1:8];
- semilogy(X,BER_awgn(count),'-.b*');
- hold on;
- grid on;
复制代码 |
|