📄 dscdma_no_diversity.m
字号:
% Simulation program to realize DS-CDMA system
%
%
function [dscdma_no_diversity_ber]=dscdma_no_diversity(snr_in_dB)
%******************** Preparation part **********************
sr=256000.0; % Symbol rate
ml=1; % Number of modulation levels
br=sr.*ml; % Bit rate (=symbol rate in this case)
nd = 1;
N=nd;% Number of symbols that simulates in each loop
ebn0=snr_in_dB; % Eb/N0
IPOINT=8; % Number of oversamples
%******************* Filter initialization ********************
irfn=21; % Number of filter taps
alfs=0.5; % Rolloff factor
[xh] = hrollfcoef(irfn,IPOINT,sr,alfs,1); %Transmitter filter coefficients
[xh2] = hrollfcoef(irfn,IPOINT,sr,alfs,0); %Receiver filter coefficients
m=31; %扩频码的码片数目
%********************** Spreading code initialization **********************
user = 1; % number of users
seq = 1; % 1:M-sequence 2:Gold 3:Orthogonal Gold
stage = 5; % number of stages
ptap1 = [1 3]; % position of taps for 1st
ptap2 = [2 3]; % position of taps for 2nd
regi1 = [1 1 1 1 1]; % initial value of register for 1st
regi2 = [1 1 1 1 1]; % initial value of register for 2nd
%******************** Generation of the spreading code *********************
switch seq
case 1 % M-sequence
code = mseq(stage,ptap1,regi1,user);
case 2 % Gold sequence
m1 = mseq(stage,ptap1,regi1);
m2 = mseq(stage,ptap2,regi2);
code = goldseq(m1,m2,user);
case 3 % Orthogonal Gold sequence
m1 = mseq(stage,ptap1,regi1);
m2 = mseq(stage,ptap2,regi2);
code = [goldseq(m1,m2,user),zeros(user,1)];
end
code = code * 2 - 1;
code=code';
clen = length(code);
%**************************** START CALCULATION ****************************
nloop = 10000; % simulation number of times
noe = 0;
nod = 0;
for iii=1:nloop
%****************************** Transmitter ********************************
%data0 = rand(1,nd*ml) > 0.5;
data0 = randint;
%data=data0.*2-1; %————————测试点————————
data=pskmod(data0,2);
%data1=(spread(data,code(1,:)))'
data1=data*code;
%[data2] = oversamp( data1, N*m , IPOINT) %128 -1,0,1
%[data3] = conv(data2,xh) % conv: built in function--------测试点 295
%******************产生空间路径衰落系数矩阵*******************
%******************产生空间路径衰落系数矩阵*******************
%Nr=1;
%Nt=2;
%t=1;
%h=mimo_channel(Nr,Nt,t); %********2 x 1 天线********
%receiver1=1/sqrt(2)*(h(1,1)*data1+h(1,2)*data_1); %------16复数
h=randn(1,1)+randn(1,1)*j;
receiver1=h*data1;
%****************** Attenuation Calculation *****************
spow=sum(data1.*data1)/nd;
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%************ Add White Gaussian Noise (AWGN) ***************
inoise=(randn(1,length(data1)).*attn)' ; % randn: built in function
data4=receiver1+inoise;
%data5=conv(data4,xh2) % conv: built in function ---------462复数
%sampl=irfn*IPOINT+1;
%data6 = data5(sampl:8:8*nd+sampl-1) %-------2个复数
%****************************解扩信号************************
data_7=code'*data4; %;
%data7=despread(data4,code(1,:)) %---------2复数
%data8=despread(data4,code(2,:)) %-----同上
%data9=conj(h(1,1))*data7+conj(h(1,2))*data8 %--------2复数
%data_9=1/sqrt(2)*((abs(h(1,1)))^2+(abs(h(1,2)))^2)*data+(conj(h(1,1))*code(1,:)+conj(h(1,2))*code(2,:))*inoise'
%******************** BPSK Demodulation *********************
demodata=pskdemod(data_7,2);
%******************** Bit Error Rate (BER) ******************
% count number of instantaneous errors
noe2=sum(abs(data0-demodata)); % sum: built in function
% count number of instantaneous transmitted data
nod2=length(data); % length: built in function
noe=noe+noe2;
nod=nod+nod2;
%fprintf('%d\t%e\n',iii,noe2/nod2)
end % for iii=1:nloop
%********************** Output result ***************************
dscdma_no_diversity_ber = noe/nod;
fprintf('%d\t%d\t%d\t%e\n',snr_in_dB,noe,nod,noe/nod);
%******************** end of file ***************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -