|
楼主 |
发表于 2006-4-19 16:12
|
显示全部楼层
<P>f_data=1;<BR>f_chip=11;<BR>fc=220;<BR>fs=3*fc;<BR>N=fs/f_chip;<BR>data_length=5000;<BR>M=2;<BR>num_of_user=4;<BR>matches=0;<BR>errors=0;<BR>count=1;<BR>SNRpbit=0;<BR>SNR=SNRpbit;</P>
<P>rand('state',sum(100*clock));<BR>randn('state',sum(100*clock));<BR>numplot=100;<BR>msg_unsprd=randsrc(data_length,num_of_user,[0:M-1]);%生成原始用户数据<BR>PN_seq=randsrc(11,num_of_user,[0:1]);%生成每个用户的扩频序列</P>
<P>for s=1:num_of_user<BR> j=1;<BR> for i=1:data_length<BR> for k=j:j+f_chip-1<BR> mdg_coded(s,k)=msg_unsprd(i,s);%编码,将每个数据变为11位<BR> end;<BR> msg_spread(s,[j:(j+f_chip-1)])=xor(msg_coded(s,[j:(j+f_chip-1)])',PN_seq([1:f_chip],s));%将每个用户实现扩频<BR> j=f_chip*i+1;<BR> end;<BR>end;<BR>len_of_spread=length(msg_spread);</P>
<P>msg_tr=zeros(num_of_user,data_length*f_chip*N);<BR>for s=1:num_of_user<BR> msg_tr(s,:)=dmod(msg_spread(s,:),fc,f_chip,fs,'psk','M');%调制,这句有错<BR>end;<BR>len_of_tr=length(msg_tr);</P>
<P>for SNRpbit=0:1:7<BR> SNR=SNRpbit;<BR> rand('state',sum(100*clock));<BR> randn('state',sum(100*clock));<BR> <BR>msg_rec_data=zeros(num_of_user,len_of_tr);<BR>sum_1=zeros(1,len_of_tr);<BR>msg_received=zeros(1,len_of_tr);</P>
<P>for s=1:num_of_user<BR> msg_rec_data(s,:)=awgn(msg_tr(s,:),SNR-10*log10(N),'measured','dB');%加高斯噪声,这句有错<BR> for i=1:data_length<BR> sum_1=sum_1+msg_rec_data(s,i);<BR> msg_received=sum_1;<BR> end;<BR>end;</P>
<P> msg_demoded=ddemod(msg_received,fc,f_chip,fs,'measured','dB');%解调,有错</P>
<P> j=1;<BR> for i=1:data_length<BR> msg_de_spread(j:(j+f_chip-1))=xor(msg_received(j:(j+f_chip-1))',PN_seq(1:f_chip,1));%解扩,以第一个用户为期望用户<BR> j=f_chip*i+1;<BR> end;</P>
<P> j=1;<BR> for i=1:data_length<BR> sum_2=0;<BR> for k=j:j+f_chip-1<BR> sum_2=sum_2+msg_de_spread(k);%解密<BR> end;<BR> if(sum_2>=7)<BR> msg_de_spread(i)=1;<BR> else<BR> msg_de_spread(i)=0;<BR> end;<BR> j=f_chip*i+1;<BR> end;</P>
<P> for i=1:data_length<BR> if(msg_de_spread(i)==msg_unsprd(i,1))<BR> matches=matches+1;<BR> else<BR> errors=errors+1;<BR> end;<BR> end;<BR> BER_awgn(count)=errors/data_length;%计算误码率<BR> count=count+1;<BR> errors=0;<BR> end;<BR>end;<BR> X=[1:8];<BR> semilogy(X,BER_awgn(count),'-.b*');%画图<BR> hold on;<BR> grid on;<BR><BR>拜托了!</P> |
|