📄 pr7_39.m
字号:
%Problem 7.39;
%Simulating asynchronous CDMA based on time-offset m-sequence signatures;
K=25; %maximal number of users;
mmax=80; %maximal delay;
n=ceil(log2(K*(mmax+1))); %memory of m-sequence;
a1=1-2*bmsq(n); %basic m-sequence ready;
N=169; %bit duration;
S=a1(1:N); %first signature within one bit interval;
Ka=20; sgn=0; maip=0; Pe=0; %number of active users, useful signal and mai power and BER initialization;
taui=(mmax+1)*[1:Ka-1]; %nominal delays of side signatures;
Yp=[]; Zp=[]; %initialization of arrays for plotting;
M=5000; %number of trials;
for k=1:M
tau=unidrnd(mmax+1,1,Ka-1)-1; %random delays of all side signatures;
tau1=taui-tau; %summary delays of side signatures;
S1=zeros(Ka-1,N); %side signatures initialization;
for s=1:Ka-1
S1(s,:)=[randsrc*a1(1+tau1(s):1+taui(s)),randsrc*a1(2+taui(s):N+tau1(s))]; %side signatures delayed and bibary data modulated;
Y=sum([S;S1]); %group signal;
end; %end forming group signal;
z=Y*S'; %correlation;
if k<8 Yp(k,:)=Y; %array for plotting group signal;
Zp(k,:)=cumsum(Y.*S); %array for plotting accumulated correlation;
end;
sgn=sgn+z; %signal accumulation;
maip=maip +z^2; %MAI estimation accumulation;
b=sign(z); %demodulation;
Pe=Pe+(1-b)/2; %accumulating BER;
end; %end cycle in k;
sgn=sgn/M; maip=maip/M-sgn^2; Pe=Pe/M; %estimates of average signal, average MAI power and BER;
Sir=sgn/sqrt(maip); %estimated SIR;
disp(' SIR SIRt BER BERt');
disp([Sir,sqrt(N/(Ka-1)),Pe,1-normcdf(sqrt(N/(Ka-1)))]); %displays experimental and theoretic SIR and bit error rate;
subplot(211);
ym=max(max(Yp)); zm=max(max(Zp)/(S*S')); %for convenient scaling of plot;
plot([0:N-1],Yp); ylim([-1.2,1.2]*ym); grid; xlim([0,N-1]); ylabel('group signal'); %plot exemplary group signals;
subplot(212);
plot([0:N-1],Zp/(S*S')); ylim([-0.2,1.2]*zm); grid; xlim([0,N-1]); ylabel('correlation'); xlabel('t/\Delta'); %plot exemplary accumulated correlation;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -