% general script for non-systematic LDPC simulation
% Things to Remember - Steps to follow ALWAYS !!!!!!!!
% 0. This file is good for non-systematic H only (errors calculated for all n)
% 1. Load H
% 2. Define SNR Range
% 3. Set Maximum number of iterations
% 4. Set Maximum number of codeword-errors for which to run simulation
% 5. Select decoder - Matlab or C-based
clear all
close all
clc
tic
%get H from somewhere , change R accordingly !!
load 128x256regular.mat H
% load 128x256regular_v6.mat %for users of Matlab 6.5
ind=find(H==1);
[r,c]=ind2sub(size(H),ind);
[rows,cols]=size(H);
h=sparse(H); % for use with Matlab-based LDPC Decoder
n=cols;
k=n-rows;
% Find
% 1: maximum check degree
% 2: column indeces in each row which contain '1'
% 3: maximum variable degree
% 4: find column indeces in each row which contain '1'
[max_check_degree,check_node_ones,BIGVALUE_COLS,max_variable_degree,variable_node_ones,BIGVALUE_ROWS]=one_finder(H);
rand('seed',584);
randn('seed',843);
dB=[0:6]; % range of SNR values in dB
SNRpbit=10.^(dB/10); % Eb/No conversion from dB to decimal
No_uncoded=1./SNRpbit; % since Eb=1
R=k/n; % code rate
No=No_uncoded./R;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
max_iter=10; %maximum number of decoder iterations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
maximum_error=1e2; % maximum errors per SNR point
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
blockerrors=0;
biterrors=0;
block=0;
FER=zeros(1,length(dB)); % array for Frame Error Rate
BER=zeros(1,length(dB)); % array for Channel Error Rate
block_array=zeros(1,length(dB));
for z=1:length(SNRpbit), % loop for testing over range of SNR values
biterrors=0;
biterrors_uncoded=0;
blockerrors=0;
block=0;
cnt=0;
while(block<1e5) %while loop
%%%%%%%%%%%%%%% u is the codeword to be transmitted %%%%%%%%%%%%%%%%%%%
amp=1;
s=round(rand(1, cols-rows));
%使用H矩阵进行LDPC编码
%原理是将H矩阵转化为G矩阵,进行过列交换的序列的位置存储下来
[u,P,rearranged_cols]=ldpc_encode(s,H);
% u=zeros(1,cols); %%all zero codeword
tx_waveform=bpsk(u);
sigma=sqrt(No(z)/2);
rx_waveform=tx_waveform + sigma*randn(1,length(tx_waveform));
%%%%%%%%%%%%%%%%% Use Matlab-based LDPC Decoder %%%%%%%%%%%%%%
demo = (sign(rx_waveform)+1)/2;
%
[vhat,iteration]=decode_ldpc_matlab(rx_waveform,No(z),h,rows,cols,ind,r,c,max_iter,rearranged_cols);
uhat=vhat;
s_decode = vhat(129:end);
% vhat=u;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Errors=zeros(1,length(s));
Errors(find(s_decode~=s))=1;
Errors_uncoded = zeros(1,length(demo));
Errors_uncoded (find(u~=demo))=1;
biterrors=biterrors+sum(Errors);
biterrors_uncoded=biterrors_uncoded+sum(Errors_uncoded);
block=block+1;
if biterrors>maximum_error
break;
end
end %while loop
block_array(z)=block; %counting blocks per SNR point
BER(z)=biterrors/(block*n*R);
BER_uncode(z)=biterrors_uncoded/(block*n);
fprintf(1,'\n\n Simulation finished for SNR: %d \n',dB(z))
% save results.mat dB BER FER block_array
end % loop for testing over range of SNR values
semilogy(dB,BER,'b-o')
hold on
dB_uncode = dB + 10*log10(R);
semilogy(dB_uncode,BER_uncode,'r-*')
legend('BPSK+LDPC-BER','BPSK-BER')
ylabel('BER')
xlabel('Eb/N0 (dB)')
grid
% Copyright (c) 2005 by Shaikh Faisal Zaheer, faisal.zaheer@gmail.com
% $Revision: 3.0 $ $Date: 26/12/2005 $
ldpc(128,256)+bpsk_信道编码 matlab
版权申诉
5星 · 超过95%的资源 87 浏览量
2022-09-21
03:02:46
上传
评论
收藏 44KB ZIP 举报
APei
- 粉丝: 64
- 资源: 1万+
最新资源
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
- 基于Java和LCN分布式事务框架的设计源码 - tx-lcn
- 基于Java和JavaScript的茶叶评级管理系统设计源码 - tea
- IMG_5680.JPG
- IMG_0437.jpg
- 基于Java的JAVA项目分析工具设计源码 - JAVAProjectAnalysis
- top888.json
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论2