📄 mt_cdma.m
字号:
clear all;
%close all;
format long;
%set up the threshold Vt
Vt = 0;
Plot_Pe = [];
K = 10;
N = 128;%扩频码长度
carry_num = 32;
x_num = 24000;%为处理方便,取N的整数倍
fft_size = 32;%2^N
%block = x_num.*N./fft_size;
block = x_num/carry_num;
plot_EbNo = 0:1:5;
for EbNo = 0:1:5,
%convert back from dB
Eb_No = EbNo; %dB
Eb_No = 10.^(Eb_No/10);
%assume No = 2;
No = 2;
Eb = No * Eb_No;
%calculate power p
Tc = 0.5;%码片周期
Ts = N * Tc;
p = Eb / Ts;
%generate BPSK symbols randomly with value +1 or -1
x = bingen(x_num);
%串并
x = reshape(x,carry_num,block);%carry_num*(x_num/carry_num)
%IFFT
%y = ifft(x,fft_size,2)*sqrt(fft_size);
y = ifft(x)*sqrt(fft_size);%carry_num*(x_num/carry_num)
%并串
y = reshape(y,1,[]);%1*x_num
%DS-SS modulate symbols with user code
UserCode = rand(1,N);
UserCode(find(UserCode<0.5)) = 0;
UserCode(find(UserCode>=0.5)) = 1;
y = ds_mod(UserCode(:),y);%(N*x_num)*1
y = sqrt(p)*y;
%add other users' signal as interference
%tmp_y = [];
for t = 2:1:K,
tmp_x = bingen(x_num);
%串并
tmp_x = reshape(tmp_x,carry_num,block);
%IFFT
tmp_y = ifft(tmp_x)*sqrt(fft_size);
%并串
tmp_y = reshape(tmp_y,1,[]);
%扩频
%tmp = rand(1,N);
%tmp(find(tmp<0.5)) = 0;
%tmp(find(tmp>=0.5)) = 1;
tmp_y = ds_mod(UserCode(:),tmp_y);
tmp_y = sqrt(p)*tmp_y;
%信号叠加
tmp_y=tmp_y/10;
y = y + tmp_y;
end % t
%scale by appropriate power factor
%y = sqrt(p)*y;
%多径
r=6; %多径数
%a=[0.123 0.3 0.4 0.5 0.7 0.8]; %多径的幅度
a=[0.1 0.2 0.3 0.4 0.5 0.6 ];
%d=[2 3 4 5 7 10 13 16]; %各径的延迟
%d=[4 6 8 10 12 15 18];
%d=[8 12 16 20 24 28 32];
%d=[8 10 12 14 17 20 23];
d=[2 3 4 5 7 10];
y = ch_multipath(y,r,a,d);
%add AWGN to signal
y = awgn_complex(y,2);
%%%
%解扩
receive_data = ds_demod(UserCode(:),y);
%串并
receive_data = reshape(receive_data,carry_num,[]);
%FFT
%x_de = fft(receive_data,fft_size,2)./sqrt(fft_size);
x_de = fft(receive_data)./sqrt(fft_size);
%并串
%x_de = reshape(receive_data,1,[]);
%decision
x_de(find(x_de < 0)) = -1;
x_de(find(x_de >=0)) = 1;
Pe = length(find(x - x_de))/x_num;
Plot_Pe = [Plot_Pe Pe];
end
%display the calculated Pd and Pfa
Plot_Pe
%plot Pe versus Eb/No
semilogy(plot_EbNo,Plot_Pe,'ko-')
grid on;
hold on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -