%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 实现功能:
% 0. 生成Gallager生成矩阵
% 1. bpsk调制,经过高斯白噪声信道
% 2. 采用对数域的和积译码算法
% 3. 计算BER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%生成生成Gallager矩阵
clear all
close all
clc
tic
miu=3;wr=4;wc=3; % 矩阵H的尺寸为:[miu*wc,miu*wr],行数:miu*wc,列数:miu*wr,这里的H为[9 18]矩阵
[H,rows,cols] = Gallager_gen_LDPC(miu,wr,wc); % 调用函数Gallager_gen_LDPC生成Gallager生成矩阵
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[rows,cols]=size(H); %矩阵行与列的大小
n=cols;
k=n-rows;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%初始化
dB=[0:5]; % 定义信噪比的范围单位为dB
SNRpbit=10.^(dB/10); % Eb/No conversion from dB to decimal将dB的单位变成十进制的
N0 = 1./SNRpbit; % Eb=1 求出噪声的单边功率谱密度,单边功率谱密度告诉我们在信号的1赫兹带宽中加入的噪声的功率
R = k/n; % 码率
iteration = 50; % 设置最大迭代次数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = round(10^3/n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BER=zeros(1,length(dB)); % array for Channel Error Rate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Errors=zeros(1,length(N*n));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for z=1:length(dB) %对每个信噪比进行仿真
%%%%%%%%%%%%%%% BPSK调制 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for m=1:N
v = round(rand(1,k));
[G,valid,t]=H2G(H); % 由校验矩阵生成生成矩阵
u=mod(v*G,2);% 由生成矩阵生成码字
tx_waveform=bpsk(u); % 调用BPSK函数,经过BPSK调制为全-1
sigma=sqrt(N0(z)/2); % 因为N0=2*sigma^2
rx_waveform=tx_waveform + sigma*randn(1,length(tx_waveform)); % rx_waveform为接收到的波形,产生一个服从N(0,1)分布的量,然后用它乘上sigma就表示服从N(0,sigma^2)分布
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%译码
vhat = decodeLogDomain(rx_waveform, H, sigma, iteration);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%计算BER
Errors(n*(m-1)+find(u~=vhat))=1; %将译出的码字与传输的码字比较,将对应不相等的位
end
BER(z)=sum(Errors)/(N*n); %计算比特错误率
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
semilogy(dB,BER,'-o'); %画图
title('Bit Error Rate');
ylabel('BER');
xlabel('Eb/No (dB)');
grid on;
toc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
阿里matlab建模师
- 粉丝: 4237
- 资源: 2840
最新资源
- 项目4 旅行信息分享应用
- 基于SpringBoot的学生信息管理系统(前后端源码+数据库+文档+运行截图)
- 【java毕业设计】智慧社区信息集成站(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区智慧服务网(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区智慧服务台(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区智慧信息窗(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区智慧管理门(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区智慧生活网(源代码+论文+PPT模板).zip
- MATLAB代码:基于模型预测算法的含储能微网双层能量管理模型 关键词:储能优化 模型预测控制MPC 微网 优化调度 能量管理 参考文档:A Two-layer Energy Managemen
- 【java毕业设计】智慧社区智慧信息站(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区智慧服务总站(源代码+论文+PPT模板).zip
- 【java毕业设计】智慧社区教育服务门户.zip
- 【java毕业设计】智慧社区健康监测平台.zip
- 【java毕业设计】智慧社区文化娱乐门户.zip
- Java高分大作业-基于SpringBoot的学生信息管理系统(前后端源码+数据库+文档+运行截图)
- 【java毕业设计】智慧社区养老服务平台.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页