收藏 分享(赏)

cdma的MATLAB仿真源程序.doc

上传人:HR专家 文档编号:11560015 上传时间:2020-06-24 格式:DOC 页数:50 大小:85KB
下载 相关 举报
cdma的MATLAB仿真源程序.doc_第1页
第1页 / 共50页
cdma的MATLAB仿真源程序.doc_第2页
第2页 / 共50页
cdma的MATLAB仿真源程序.doc_第3页
第3页 / 共50页
cdma的MATLAB仿真源程序.doc_第4页
第4页 / 共50页
cdma的MATLAB仿真源程序.doc_第5页
第5页 / 共50页
点击查看更多>>
资源描述

1、%*% This function pertains to the addition of AWGN with mean zero and % parameter variance to an input signal. % AUTHOR: Wenbin Luo% DATE : 04/12/01% SYNOPSIS: y = awgn(x,var)% x - input signal% var - variance% y - y = x + AWGN %*function y = awgn(x,var) w = randn(1,length(x); w = w - mean(w)*ones(s

2、ize(w); w = sqrt(var)*(w / std(w); x = x(:); w = w(:); y = x + w; %*% This function does the DS-SS modulation% AUTHOR: Wenbin Luo% DATE : 04/28/01% SYNOPSIS: y = ds_mod(c,x)% c - user code (column vector)% x - input signal (row vector)% y - tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vecto

3、r)%*function y = ds_mod(c,x)tmp = c*x;y = tmp(:);%*% This function generates random +1/-1 sequence with independent identically % distributed symbols% AUTHOR: Wenbin Luo% DATE : 04/28/01% SYNOPSIS: x = bingen(L)% L - number of random symbols %*function x = bingen(L)%generate L symbols randomly with

4、value +1 or -1x = rand(1,L);x(find(x=0.5) = 1;%*% This function does the DS-SS modulation% AUTHOR: Wenbin Luo% DATE : 04/28/01% SYNOPSIS: x = ds_demod(c,y)% c - user code (column vector)% y - tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vector)% x - input signal (row vector)%*function x = d

5、s_demod(c,y)tmp = reshape(y, length(c), length(y)/length(c);tmp = tmp;%x is a column vectorx = tmp * c;% convert to row vectorx = x;%*% This function does the DS-SS modulation% AUTHOR: Wenbin Luo% DATE : 04/28/01% SYNOPSIS: y = ds_mod(c,x)% c - user code (column vector)% x - input signal (row vector

6、)% y - tmp = c*x, y = tmp(:) (ds-ss modulated signal, column vector)%*function y = ds_mod(c,x)tmp = c*x;y = tmp(:);%*% This mfunction generates faded envelope and phase % corresponding to Rayleigh fading% AUTHOR: Wenbin Luo% DATE : 04/27/01% FUNCTION SYNOPSIS: % env,phi = fade(L,para)% % Parameter D

7、escription: % L : number of samples needed % variance : variance %*function env,phi = fade(L,variance)% Error checkif variance = 0 error(Positive variance needed)elseif nargin = 2 error(Insufficient input parameters)end% Generate bivariate Gaussian uncorrelated % random variablesmu = zeros(1,2);C =

8、variance*eye(2,2);r = mvnrnd(mu,C,L);% Convert to polar coordinates and compute % magnitude and phase z = r(:,1) + j*r(:,2);env = abs(z); phi = angle(z);%*%*% This mfunction generates two channels of faded % envelope and phase corresponding to% Rayleigh fading% AUTHOR: Wenbin Luo% DATE : 04/27/01% F

9、UNCTION SYNOPSIS: % env,phi = fade_diversity(L,para)% % Parameter Description: % L : number of samples needed % variance : variance %*function env1,env2 = fade_diversity(L,variance)% Error checkif variance = 0 error(Positive variance needed)elseif nargin = 2 error(Insufficient input parameters)end%

10、Generate bivariate Gaussian uncorrelated % random variablesmu = zeros(1,4);C = variance*eye(4,4);r = mvnrnd(mu,C,L);% Convert to polar coordinates and compute % magnitude and phase z1 = r(:,1) + j*r(:,2);z2 = r(:,3) + j*r(:,4);env1 = abs(z1); env2 = abs(z2);%*%*% This mfunction generates frequency s

11、elective % Rayleigh fading% AUTHOR: Wenbin Luo% DATE : 05/02/01% FUNCTION SYNOPSIS: % y = fade_fs(x,L)% % Parameter Description: %y : output signal% x : input signal % L : number of independent Rayleigh %fading process %*function y = fade_fs(x,L)% Generate bivariate Gaussian uncorrelated % random va

12、riablestmp1 = 0:1:(L-1);tmp1 = exp(-tmp1);tmp(1:2:2*L-1) = tmp1;tmp(2:2:2*L) = tmp1;mu = zeros(1,2*L);C = 0.5*diag(tmp);x_len = length(x);r = mvnrnd(mu,C,x_len);% Convert to polar coordinates and compute magnitudex = x(:);y = zeros(x_len,1);for i = 1:L, z = r(:,2*i-1) + j*r(:,2*i); env = abs(z); %ph

13、i = angle(z); tmp_y = env.*x; tmp_y = zeros(i-1,1); tmp_y(1:x_len-i+1); y = y + tmp_y;end%*%*% This program computes the average BER of a DS-SS/BPSK %communication system with binary BCH code in the AWGN channel% % AUTHOR: Wenbin Luo% DATE : 04/28/01%final11_extra.m% %*%function Plot_Pe = final11_ex

14、tra()clear all;%close all;format long;%set up the threshold Vt Vt = 0;Plot_Pe = ;N = 16;x_num = 2500;plot_EbNo = -20:2:10;for EbNo = -20:2:10, %convert back from dBEb_No = EbNo; %dBEb_No = 10.(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%generate

15、BPSK symbols randomly with value +1 or -1x = bingen(x_num);x_org = x;%adds error-correcting codeenc_N = 15; enc_K = 5; %7/4 or 15/5x(find(x 0) = 0;x = encode(x,enc_N,enc_K,bch);x = x;x(find(x = 0) = -1;%DS-SS modulate symbols with user codec = bingen(N);y = ds_mod(c(:),x);%scale by appropriate power

16、 factory = sqrt(p)*y;%add AWGN to signaly = awgn(y,1);%DS-SS demodulate symbols with user codex_de = ds_demod(c(:),y);%decisionx_de(find(x_de =0) = 1;%decode error-correcting codex_de(find(x_de 0) = 0;x_de = decode(x_de,enc_N,enc_K,bch);x_de = x_de;x_de(find(x_de = 0) = -1;%-Pe = length(find(x_org -

17、 x_de)/x_num;Plot_Pe = Plot_Pe Pe;end %end for EbNo%-%return;%-%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/Nosemilogy(plot_EbNo,Plot_Pe,bo-)xlabel(Eb/No (dB)ylabel(BER)s=sprintf(BER versus Eb/No with binary BCH code in the AWGN channel);title(s);%*% This program computes the average

18、BER of a DS-SS/BPSK %communication system with binary BCH code in the AWGN channel% % AUTHOR: Wenbin Luo% DATE : 04/28/01%final11_extra.m% %*%function Plot_Pe = final11_extra()clear all;%close all;format long;%set up the threshold Vt Vt = 0;Plot_Pe = ;N = 16;x_num = 2500;plot_EbNo = -20:2:10;for EbN

19、o = -20:2:10, %convert back from dBEb_No = EbNo; %dBEb_No = 10.(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%generate BPSK symbols randomly with value +1 or -1x = bingen(x_num);x_org = x;%adds error-correcting codeenc_N = 15; enc_K = 5; %7/4 or 15

20、/5x(find(x 0) = 0;x = encode(x,enc_N,enc_K,bch);x = x;x(find(x = 0) = -1;%DS-SS modulate symbols with user codec = bingen(N);y = ds_mod(c(:),x);%scale by appropriate power factory = sqrt(p)*y;%add AWGN to signaly = awgn(y,1);%DS-SS demodulate symbols with user codex_de = ds_demod(c(:),y);%decisionx_

21、de(find(x_de =0) = 1;%decode error-correcting codex_de(find(x_de 0) = 0;x_de = decode(x_de,enc_N,enc_K,bch);x_de = x_de;x_de(find(x_de = 0) = -1;%-Pe = length(find(x_org - x_de)/x_num;Plot_Pe = Plot_Pe Pe;end %end for EbNo%-%return;%-%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/Nosemi

22、logy(plot_EbNo,Plot_Pe,bo-)xlabel(Eb/No (dB)ylabel(BER)s=sprintf(BER versus Eb/No with binary BCH code in the AWGN channel);title(s);%*% This program computes the average BER of a DS-SS/BPSK %communication system with binary BCH code in the AWGN channel% % AUTHOR: Wenbin Luo% DATE : 04/28/01%final11

23、_extra.m% %*%function Plot_Pe = final11_extra()clear all;%close all;format long;%set up the threshold Vt Vt = 0;Plot_Pe = ;N = 16;x_num = 2500;plot_EbNo = -20:2:10;for EbNo = -20:2:10, %convert back from dBEb_No = EbNo; %dBEb_No = 10.(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power

24、pTc = 1;Ts = N * Tc;p = Eb / Ts;%generate BPSK symbols randomly with value +1 or -1x = bingen(x_num);x_org = x;%adds error-correcting codeenc_N = 15; enc_K = 5; %7/4 or 15/5x(find(x 0) = 0;x = encode(x,enc_N,enc_K,bch);x = x;x(find(x = 0) = -1;%DS-SS modulate symbols with user codec = bingen(N);y =

25、ds_mod(c(:),x);%scale by appropriate power factory = sqrt(p)*y;%add AWGN to signaly = awgn(y,1);%DS-SS demodulate symbols with user codex_de = ds_demod(c(:),y);%decisionx_de(find(x_de =0) = 1;%decode error-correcting codex_de(find(x_de 0) = 0;x_de = decode(x_de,enc_N,enc_K,bch);x_de = x_de;x_de(find

26、(x_de = 0) = -1;%-Pe = length(find(x_org - x_de)/x_num;Plot_Pe = Plot_Pe Pe;end %end for EbNo%-%return;%-%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/Nosemilogy(plot_EbNo,Plot_Pe,bo-)xlabel(Eb/No (dB)ylabel(BER)s=sprintf(BER versus Eb/No with binary BCH code in the AWGN channel);title

27、(s);%*% This program computes the average BER of a DS-SS/BPSK %communication system in the presence of pulsed noise jamming%and AWGN% % AUTHOR: Wenbin Luo% DATE : 04/28/01%final12.m% %*%function Plot_Pe = final12()clear all;%close all;format long;%set up the threshold Vt Vt = 0;Plot_Pe = ;N = 16;ro

28、= 0.2; %1, 0.4, 0.2x_num = 10000;plot_EbNo = -20:2:10; for EbNo = -20:2:10, %convert back from dBEb_No = EbNo; %dBEb_No = 10.(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%generate BPSK symbols randomly with value +1 or -1x = bingen(x_num);%DS-SS m

29、odulate symbols with user codec = bingen(N);y = ds_mod(c(:),x);%scale by appropriate power factory = sqrt(p)*y;%add Pulsed Noise Jammer to signaly = awgn(y(1:ro*length(y),1/ro); y(ro*length(y)+1):length(y);%DS-SS demodulate symbols with user codex_de = ds_demod(c(:),y);%decisionx_de(find(x_de =0) =

30、1;Pe = length(find(x - x_de)/x_num;Plot_Pe = Plot_Pe Pe;end %end for EbNo%-%return;%-%display the calculated Pd and PfaPlot_Pe%plot Pe versus Eb/No%subplot(2,1,1)semilogy(plot_EbNo,Plot_Pe,m*-)xlabel(10log_10(P/J)(W/R) (dB)ylabel(BER)s=sprintf(BER versus 10log_10(P/J)(W/R) in pulsed noise jamming an

31、d AWGN);title(s);%*% This program computes the average BER of a DS-SS/BPSK %communication system in barrage noise jamming and AWGN% % AUTHOR: Wenbin Luo% DATE : 05/02/01%final12_extra.m% %*% function Plot_Pe = final12_extra()clear all;%close all;format long;%set up the threshold Vt Vt = 0;Plot_Pe =

32、;N = 16;x_num = 10000;%-%convert back from dBEb_No = 5; % 2, 4, 6 dB Eb_No = 10.(Eb_No/10);%assume No = 2;No = 2;Eb = No * Eb_No;%calculate power pTc = 1;Ts = N * Tc;p = Eb / Ts;%-plot_EbNj = 0:2:50; for EbNj = 0:2:50, %convert back from dBEb_Nj = EbNj; %dBEb_Nj = 10.(Eb_Nj/10);Nj = Eb / Eb_Nj; %gen

33、erate BPSK symbols randomly with value +1 or -1x = bingen(x_num);%DS-SS modulate symbols with user codec = bingen(N);y = ds_mod(c(:),x);%scale by appropriate power factory = sqrt(p)*y;%add barrage noise jamming and AWGN to signaly = awgn(y,(Nj/2)+1);%y = awgn(y,1);%DS-SS demodulate symbols with user codex_de = ds_demod(c(:),y);%decisionx_de(find(x_de =0) = 1;Pe = length(find(x - x_de)/x_num;Plot_Pe = Plot_Pe Pe;end %end for EbNo%-

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 网络科技 > 计算机原理

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报