当前位置:文档之家› 通信原理课程设计—DS-CDMA基带传输系统

通信原理课程设计—DS-CDMA基带传输系统

通信原理课程设计——DS/CDMA 基带传输系统

一、 课程设计要求:

用Matlab 构造一个DS/CDMA 基带传输系统,各用户的二进制数据b 与扩频码c 进行扩频,用户数K 为4个,扩频增益取31,扩频码采用Gold 码,接收端假设理想同步,对各用户通过解扩恢复各自的信息数据。发端基带成型采用滚降因子为0.22的平方根升余弦滚降脉冲(用48阶的FIR 滤波器来实现,每个码片采样16个样点),接收机用码片第8个或第9个样点作为判决点,信噪比大小(SNR )自设,如SNR 可取为20dB 或30dB 。

??

?

1

2

b

二、 DS/CDMA 原理:

三、系统设计:

根升余弦滤波器设计:

irfn = 48; % 滤波器阶数

IPOINT = 4; % 码片速率过采样倍数(4倍

alfs = 0.22; % 滚降因子

[xh] = hrollfcoef(irfn,IPOINT,sr,alfs,1); %发送端根升余弦滤波器系数[xh2] = hrollfcoef(irfn,IPOINT,sr,alfs,0); %接收端根升余弦滤波器系数%根升余弦滤波器

figure('Name','根升余弦滤波器','NumberTitle','on');

% Tx

subplot(211);stem(xh);grid;

xlabel('Bits index');

title('发送端根升余弦滤波器');

% Rx

subplot(212);stem(xh2);grid;

xlabel('Bits index');

title('接收端根升余弦滤波器');

误码率-信噪比关系图

figure; % plot the BER vs. SNR

semilogy(SNR,r,'r-x'),grid;

xlabel('SNR');ylabel('BER');

title('BER vs. SNR');

原始数据,发送和接收的比较

figure('Name','Original Data','NumberTitle','on');

% plot data for a randomly selected user such as user no. 1 before the BPSK mapping Tx and Rx

% Tx

subplot(211);stem(data(cuser,1:20),'filled');grid;

xlabel('Bits index');

title('Transmitted Bits (showing only 20 bits)');

% Rx

subplot(212);stem(data_rm(cuser,1:20),'filled');grid;

xlabel('Bits index');

title('Received Bits (showing only 20 bits)');

BPSK编码后,发送和接收的比较

figure('Name','BPSK Symbols','NumberTitle','on');

% plot data for a randomly selected user such as user no. 1 after the BPSK mapping Tx and Rx

% Tx

subplot(211);stem(data_m(cuser,1:20),'filled');grid;

xlabel('Symbol index');

title('Transmitted BPSK Symbols (showing only 20 Symbol)');

% Rx

subplot(212);stem(data_rs(cuser,1:20),'filled');grid;

xlabel('Symbol index');

title('Received BPSK Symbols (showing only 20 Symbol)');

要发送的数据,各个用户对应位求和的结果

figure('Name','Combined signals','NumberTitle','on');%plot combined signals

%Tx

subplot(211);stem(data_f(1:50),'filled');

title('Combined signals (only 20 symbols)');

xlabel('Index of Combined symbols');

ylabel('Magnitude');

grid;

%Rx

subplot(212);stem(data_ros(1:50),'filled');

title('Combined noisy signals (only 20 symbols)');

xlabel('Index of Combined symbols');

ylabel('Magnitude');

四、程序代码:

% main_DS_CDMA.m

% DS/CDMA通信系统仿真

%扩频码:Gold码

%+++++++++++++++++++++++准备部分+++++++++++++++++++++++++++

clear all; close all; clc;

disp('--------------Calculate Start ...-------------------');

sr = 256000.0; % 符号速率

ml = 2; % 调制阶数

br = sr * ml; % 比特速率

nd = 1000; % 符号数

SNR=-5:1:10; % Eb/No:Eb是指平和比特能量,no是指白噪声的功率谱密度

cuser = 1; % 画图时要显示的用户

%+++++++++++++++++++++滤波器初值设定+++++++++++++++++++++++

irfn = 48; % 滤波器阶数

IPOINT = 4; % 码片速率过采样倍数(4倍

alfs = 0.22; % 滚降因子

[xh] = hrollfcoef(irfn,IPOINT,sr,alfs,1); %发送端根升余弦滤波器系数%%hrollfcoef指

[xh2] = hrollfcoef(irfn,IPOINT,sr,alfs,0); %接收端根升余弦滤波器系数

%++++++++++++++++++++++++扩频码初值设定+++++++++++++++++++

user = 4; % 用户数

%seq = 2; % 1:m序列2:Gold序列3:正交Gold序列

stage = 5; % 序列阶数

ptap1 = [2 5]; % 第一个线性移位寄存器的系数

ptap2 = [1 2 3 5]; % 第二个线性移位寄存器的系数

regi1 = [1 1 1 1 1]; % 第一个线性移位寄存器的初始化

regi2 = [1 1 1 1 1]; % 第二个线性移位寄存器的初始化

%移位寄存器级数3,码长7.

% 5 31

%+++++++++++++++++扩频码的产生+++++++++++++++++

m1 = mseq(stage,ptap1,regi1);

m2 = mseq(stage,ptap2,regi2);

code = [goldseq(m1,m2,user),zeros(user,1)]; %正交Gold序列

code = code * 2 - 1; %双极性

clen = length(code);

data = rand(user,nd) > 0.5;

dlen = length(data);

data_m = data.*2 -1; %QPSK;

data_s=zeros(user,dlen*(2^stage));

for i1=1:1:user %扩频

data_s(i1,:)=kron(data_m(i1,:),code(i1,:));

end

data_os = compoversamp2(data_s,IPOINT); % 过采样

data_f1 = compconv2(data_os,xh); % 滤波

if user == 1

data_f = data_f1;

else

data_f = sum(data_f1);

end

disp('--------------Send Data ...-------------------');

loo=0;

for kk=1:1:length(SNR)

data_n=awgn(data_f,SNR(kk),'measured');%在信号data_f中加入高斯白噪声data_rf = compconv2(data_n,xh2); % 滤波

sampl = irfn * IPOINT + 1;

data_ros = data_rf(:,sampl:IPOINT:IPOINT*nd*clen+sampl-1); %减采样

%++++++++++解扩++++++++

data_rs=zeros(user,dlen);

scused=ones(1,dlen);

for i2=1:1:user

bds=kron(scused,code(i2,:)); %将Gold码矩阵的i2行,复制scused次

ds=bds.*data_ros(1,:); %反哈达玛变换(解扩)

rds=reshape(ds,clen,length(data_ros(1,:))/clen);%对ds重新排列成hl行,length(s)/hl。

%注:(reshape数据排列顺序:从上往下,从左往右)

ou=sum(rds); %对每列求和

t=length(ou);

en=zeros(1,t);

for a=1:t

if ou(a)>1 %抽样判决

en(a)=1;

else

en(a)=-1;

end

end

data_rs(i2,:)=en;

end

%++++++++++++++++++

data_rm=(data_rs+1)./2;%BPSK解调

loo=loo+1;

[n(loo),r(loo)]=symerr(data_m,data_rs); %[number,ratio] = symerr(x,y) end

disp('----------------Calculate Finished-------------------');

disp('----------------Start Plot-------------------');

%根升余弦滤波器

figure('Name','根升余弦滤波器','NumberTitle','on');

% Tx

subplot(211);stem(xh);grid;

xlabel('Bits index');

title('发送端根升余弦滤波器');

% Rx

subplot(212);stem(xh2);grid;

xlabel('Bits index');

title('接收端根升余弦滤波器');

%误码率-信噪比关系图

figure; % plot the BER vs. SNR

semilogy(SNR,r,'r-x'),grid;

xlabel('SNR');ylabel('BER');

title('BER vs. SNR');

%原始数据,发送和接收的比较

figure('Name','Original Data','NumberTitle','on');

% plot data for a randomly selected user such as user no. 1 before the BPSK mapping Tx and Rx

% Tx

subplot(211);stem(data(cuser,1:20),'filled');grid;

xlabel('Bits index');

title('Transmitted Bits (showing only 20 bits)');

% Rx

subplot(212);stem(data_rm(cuser,1:20),'filled');grid;

xlabel('Bits index');

title('Received Bits (showing only 20 bits)');

%BPSK编码后,发送和接收的比较

figure('Name','BPSK Symbols','NumberTitle','on');

% plot data for a randomly selected user such as user no. 1 after the BPSK mapping Tx and Rx

% Tx

subplot(211);stem(data_m(cuser,1:20),'filled');grid;

xlabel('Symbol index');

title('Transmitted BPSK Symbols (showing only 20 Symbol)');

% Rx

subplot(212);stem(data_rs(cuser,1:20),'filled');grid;

xlabel('Symbol index');

title('Received BPSK Symbols (showing only 20 Symbol)');

%要发送的数据,各个用户对应位求和的结果

figure('Name','Combined signals','NumberTitle','on');%plot combined signals

%Tx

subplot(211);stem(data_f(1:50),'filled');

title('Combined signals (only 20 symbols)');

xlabel('Index of Combined symbols');

ylabel('Magnitude');

grid;

%Rx

subplot(212);stem(data_ros(1:50),'filled');

title('Combined noisy signals (only 20 symbols)');

xlabel('Index of Combined symbols');

ylabel('Magnitude');

grid;

disp('----------------Plot Finished-------------------');

相关主题
文本预览
相关文档 最新文档