function error_rate=kechengsheji(n,SNR,N_Receiver)
%______________________信源部分________________________%
c_source=rand(n,1);
c_source(c_source==1)=[];%剔除1,强制[0,0.5)和[0.5,1)等概率
c_source(c_source<0.5)=-1;%等概率前提近似取等号,免去信源编码;双极性。
c_source(c_source>=0.5)=1;
n_deng=length(c_source);%重新数出个数
if mod(n_deng,2) ~= 0
c_source(1)=[];
n_deng=n_deng-1;%强制c_source为偶数个
end
c_element=c_source;
c_length=n_deng;%结构体c储存
%
%不进行信道编码,防止对误码性能产生影响
%
%_____________________________________________________%
%____________________QPSK调制_________________________%
%B_map=[1+1i 1-1i -1-1i -1+1i];%%%%B方式调制
n_phase=c_length/2;
c_IQ=reshape(c_element,n_phase,2);%串并转换
c_phase=((c_IQ(:,1)*1i)+(c_IQ(:,2)));%相位映射
%scatterplot(c_phase)
B_jugle=[[1+1i;1+1i],[1+1i;1-1i],[1+1i;-1-1i],[1+1i;-1+1i], ...
[1-1i;1+1i],[1-1i;1-1i],[1-1i;-1-1i],[1-1i;-1+1i], ...
[-1-1i;1+1i],[-1-1i;1-1i],[-1-1i;-1-1i],[-1-1i;-1+1i], ...
[-1+1i;1+1i],[-1+1i;1-1i],[-1+1i;-1-1i],[-1+1i;-1+1i]];
%_____________________________________________________%
%____________________天线发射_________________________%
n_antenna=2;%发射天线数目为二
n_each_antenna=n_phase/n_antenna;
antenna=reshape(c_phase,n_each_antenna,n_antenna);
c_STBC = cell(n_each_antenna,1);%预设大小
%X=cell(n_each_antenna,1);
for i=1:n_each_antenna
c_STBC{i}=[antenna(i,:);[-1*conj(antenna(i,2)),conj(antenna(i,1))]];
%X{i}=antenna(i,:)';
end
%_____________________________________________________%
%______________________分集合并_MRC合并_____________________%
R_comphase_s=zeros(2*n_each_antenna,1);
% Alpha_s=zeros(n_each_antenna,N_Receiver);
H_comphase_s=zeros(2*n_each_antenna,2);
for k=1:N_Receiver
[R_comphase,H_comphase]=pass_rei(n_each_antenna,c_STBC,SNR);
R_comphase_s=R_comphase_s+R_comphase;
% Alpha_s(:,k)=alpha;
H_comphase_s(:,1)=H_comphase_s(:,1)+H_comphase(:,1);
H_comphase_s(:,2)=H_comphase_s(:,2)+H_comphase(:,2);
end
R=cell(n_each_antenna,1);
H=cell(n_each_antenna,1);
for i=1:n_each_antenna
odd=2*i-1;
even=2*i;
R{i}= [R_comphase_s(odd);R_comphase_s(even)];
H{i}= [H_comphase_s(odd,:);H_comphase_s(even,:)];
end
% for i=1:n_each_antenna
% R{i}= [R_comphase_s(2*i-1,:)*Alpha_s(i,:)';conj(R_comphase_s(2*i,:)*Alpha_s(i,:))']/sum(Alpha_s(i,:));
% for k=1:N_Receiver
% H{i}(1,:)=H_comphase_s
% end
% end
%_____________________________________________________%
%_________________________判决________________________%
x=zeros(n_each_antenna,2);%定义大小
for i=1:n_each_antenna
jugle=[norm(R{i}-H{i}*[1+1i;1+1i]),norm(R{i}-H{i}*[1+1i;1-1i]),norm(R{i}-H{i}*[1+1i;-1-1i]),norm(R{i}-H{i}*[1+1i;-1+1i]), ...
norm(R{i}-H{i}*[1-1i;1+1i]),norm(R{i}-H{i}*[1-1i;1-1i]),norm(R{i}-H{i}*[1-1i;-1-1i]),norm(R{i}-H{i}*[1-1i;-1+1i]), ...
norm(R{i}-H{i}*[-1-1i;1+1i]),norm(R{i}-H{i}*[-1-1i;1-1i]),norm(R{i}-H{i}*[-1-1i;-1-1i]),norm(R{i}-H{i}*[-1-1i;-1+1i]), ...
norm(R{i}-H{i}*[-1+1i;1+1i]),norm(R{i}-H{i}*[-1+1i;1-1i]),norm(R{i}-H{i}*[-1+1i;-1-1i]),norm(R{i}-H{i}*[-1+1i;-1+1i])];
x(i,:)=B_jugle(:,jugle==min(jugle))';%%%按书本方式解调
end
x=reshape(x,1,n_phase)';
x_comp=x-c_phase;
x_comp(x_comp~=0)=1;
error_rate=sum(x_comp)/n_phase;%误码率
%_____________________________________________________%
end
function [R_comphase,H_comphase]=pass_rei(n_each_antenna,c_STBC,SNR)
%____________________过瑞利信道_______________________%
%%r=cell(n_each_antenna,1);
%%H=cell(n_each_antenna,1);
n_each_antenna_c2=n_each_antenna*2;
H_comphase=zeros(n_each_antenna_c2,2);
%%R=cell(n_each_antenna,1);
Noise=zeros(n_each_antenna_c2,1);
R_comphase_nn=zeros(n_each_antenna_c2,1);%
R_comphase=zeros(n_each_antenna_c2,1);
P_noise=zeros(n_each_antenna_c2,1);
alpha=zeros(n_each_antenna_c2,1);
for i=1:n_each_antenna
odd=2*i-1;
even=2*i;
chan_1=rayleighchan; %scatterplot(r_rayleigh)
chan_2=rayleighchan;
%%h=[chan_1.PathGains;chan_2.PathGains];
h_comphase=[norm(chan_1.PathGains);norm(chan_2.PathGains)];%同相
%%r{i}=c_STBC{i}*h;
%%H{i}=[chan_1.PathGains,chan_2.PathGains;conj(chan_2.PathGains),-conj(chan_1.PathGains)];
%%R{i}=[awgn(r{i}(1),SNR);conj(awgn(r{i}(2),SNR))]; %scatterplot(r_pro)
%%Noise{i}= [R{i}(1);conj(R{i}(2))]- r{i};
%%R_comphase(2*i-1)=c_STBC{i}(1,:)*h_comphase+Noise{i}(1);
%%R_comphase(2*i)=conj(c_STBC{i}(2,:)*h_comphase+Noise{i}(2));
R_comphase_nn(odd)=c_STBC{i}(1,:)*h_comphase;%
R_comphase_nn(even)=c_STBC{i}(2,:)*h_comphase;%
R_comphase(odd)=awgn(R_comphase_nn(odd),SNR);%同相过后的ri
R_comphase(even)=awgn(R_comphase_nn(even),SNR);%
%Noise{i}= [R_comphase(odd)-R_comphase_nn(odd);R_comphase(even)-R_comphase(even)];%
Noise(odd)=R_comphase(odd)-R_comphase_nn(odd);
Noise(even)=R_comphase(even)-R_comphase_nn(even);
P_noise(odd)=norm(Noise(odd))^2;%噪声功率Nk
P_noise(even)=norm(Noise(even))^2;
R_comphase(even)=conj(R_comphase(even));
%alpha(i)=norm([R_comphase(odd),R_comphase(even)])/P_noise(i);%alpha
alpha(odd)=norm(R_comphase(odd))/P_noise(odd);%%正比于rk/Nk
alpha(even)=norm(R_comphase(even))/P_noise(even);%
% alpha(i)=norm(R_comphase_nn(odd));%奇 偶等大
R_comphase(odd)=R_comphase(odd)*alpha(odd);
R_comphase(even)=R_comphase(even)*alpha(even);
H_comphase(odd,:)=[h_comphase(1),h_comphase(2)]*alpha(odd);
H_comphase(even,:)=[h_comphase(2),-h_comphase(1)]*alpha(even);
end
%_____________________________________________________%
%scatterplot(reshape(cell2mat(r),1,n_phase))
%scatterplot(reshape(cell2mat(R),1,n_phase))
%scatterplot(reshape(cell2mat(R_comphase),1,n_phase))
end
%______________________信源部分________________________%
c_source=rand(n,1);
c_source(c_source==1)=[];%剔除1,强制[0,0.5)和[0.5,1)等概率
c_source(c_source<0.5)=-1;%等概率前提近似取等号,免去信源编码;双极性。
c_source(c_source>=0.5)=1;
n_deng=length(c_source);%重新数出个数
if mod(n_deng,2) ~= 0
c_source(1)=[];
n_deng=n_deng-1;%强制c_source为偶数个
end
c_element=c_source;
c_length=n_deng;%结构体c储存
%
%不进行信道编码,防止对误码性能产生影响
%
%_____________________________________________________%
%____________________QPSK调制_________________________%
%B_map=[1+1i 1-1i -1-1i -1+1i];%%%%B方式调制
n_phase=c_length/2;
c_IQ=reshape(c_element,n_phase,2);%串并转换
c_phase=((c_IQ(:,1)*1i)+(c_IQ(:,2)));%相位映射
%scatterplot(c_phase)
B_jugle=[[1+1i;1+1i],[1+1i;1-1i],[1+1i;-1-1i],[1+1i;-1+1i], ...
[1-1i;1+1i],[1-1i;1-1i],[1-1i;-1-1i],[1-1i;-1+1i], ...
[-1-1i;1+1i],[-1-1i;1-1i],[-1-1i;-1-1i],[-1-1i;-1+1i], ...
[-1+1i;1+1i],[-1+1i;1-1i],[-1+1i;-1-1i],[-1+1i;-1+1i]];
%_____________________________________________________%
%____________________天线发射_________________________%
n_antenna=2;%发射天线数目为二
n_each_antenna=n_phase/n_antenna;
antenna=reshape(c_phase,n_each_antenna,n_antenna);
c_STBC = cell(n_each_antenna,1);%预设大小
%X=cell(n_each_antenna,1);
for i=1:n_each_antenna
c_STBC{i}=[antenna(i,:);[-1*conj(antenna(i,2)),conj(antenna(i,1))]];
%X{i}=antenna(i,:)';
end
%_____________________________________________________%
%______________________分集合并_MRC合并_____________________%
R_comphase_s=zeros(2*n_each_antenna
食肉库玛
- 粉丝: 68
- 资源: 4738
最新资源
- 大模型 AI 训练的数据存储加速-肖文聪
- 个人资源使用不必在意java
- RT-Thread Studio 驱动can组件
- 大模型的三次触动、两个难题、一个参考答案-贾安亚
- qt 实现网络爬虫(小说).zip
- 数据资产管理实践指南(7.0版)
- STM32F407ZGT6笔记13:STM32数据打包并发送-上位机python串口接收并保存为.csv表格文件.rar
- HTML与JS联动WebSocket实现高效实时通信
- 大模型赋能 DevOps,研发全环节提速-唐辉
- 大模型赋能的数据资产平台构建实践-徐流明
- 大模型技术在快手搜索的应用-许坤
- 大模型数据安全:从测评到实时检测的全流程实践-申书恒
- 大模型应用开发新范式-娄双双
- springboot项目javaweb的新能源充电系统.zip
- springboot项目+vue校园求职招聘系统设计和实现.zip
- springboot项目it职业生涯规划系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0