No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
LDPC Code Simulation

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.3 | 51 ratings Rate this file 66 Downloads (last 30 days) File Size: 82.6 KB File ID: #8977 Version: 1.0
image thumbnail

LDPC Code Simulation



09 Nov 2005 (Updated )

MATLAB code for LDPC (Low-Density Parity-Check) Codes simulation over the AWGN channel.

| Watch this File

File Information

The zip file contains
1. A 128x256 Regular (3,6) H matrix (if you need to simulate other codes, need to write your own code for generating those parity check matrices). The file '128x256regular_v6.mat' is for those using Matlab 6.5.
2. Files for LDPC code simulation over the AWGN channel.
3. Matlab-based and C-based (C-mex file)implementation of the LDPC decoder. The main simulation script contains the commands for the use of both decoders (there are 2 C-based decoders and one Matlab based). The commands for the decoder that are going to be used need to "uncommented", and those for the other decoder need to be "commented".
3a. To compile the C-mex file, need to install a C compiler (I have used Miscosoft Visual C++ 6.0). Then have to go to the Matlab command window and do
">>mex -setup" (then go through the steps of selecting the desired compiler).
Then do:
">>mex decode_ldpc.cpp" (or ">>mex decode_ldpc_new.cpp"). This will produce a "dll" file by the name of "decode_ldpc.dll" (or "decode_ldpc_new.dll"), and this can then be used by the main script for simulation. I am including already compiled "dll" files which work with Maltab 7.0 (and Matlab 6.5). However if the included "dll" files do not work for you then you have to compile the "*.cpp" files using the method explained above.
3b. The Matlab code uses "Sparse" implementation for the various matrices, and is therefore makes efficient use of memory (this makes some difference if you -like me- use a standard PC for simulation and are using large H matrices that have block length greater than 3000). However if memory and CPU power and not your limitations then the C-based decoder is much faster.
4. The bit errors are counted over the entire code word. The main script needs to be modified for counting bit errors if a systematic matrix is being used.
5. The modulation used is BPSK.

To run a simulation
1. Open the script file by the name of
2. Load a H (parity-check) matrix
3. Set the SNR range
4. Set maximum number of decoder iteration, and maximum number of errored codewords to count for each SNR point (must be at least 30 for reliable estimate, the papers show results for 100-200 codeword errors. OUCH!!!).
5. Select the C-based OR Matlab-based LDPC decoder.
5A. The decoder "decode_ldpc_new" is much faster than "decode_ldpc" (the difference in speed increases with block length).
6. Run the script and wait for the results :) .


This file inspired Message Passing Algorithm For Decoding Binary Ldpc Codes and Yongsk/Bp Decoder.

MATLAB release MATLAB 7 (R14)
Other requirements Microsoft Visual C++ 6.0 (or later version) to compile C-mex file (which is the C-based LDPC decoder).
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (63)
03 May 2016 Moqbel Hamood  
03 Oct 2014 idrissa  
26 May 2014 Rania

Rania (view profile)

14 May 2014 Hasima Mat

how to load Load a H (parity-check) matrix? please email the detail step tq.

Comment only
10 Mar 2014 faisal

faisal (view profile)

Can anybody plz tell me how to do the same using simulink

14 Feb 2014 Lenewsky

thank you so much

Comment only
02 Dec 2013 Sanket Kalamkar  
25 Mar 2013 peng

peng (view profile)

02 Mar 2013 Albashir

I would like to know how you convert m-file function of the decoder to be in mex format. Please verify in steps to be able to convert mine.

03 Jan 2013 djamel

djamel (view profile)

thanks great work and nice work by author
congrats to get good review from all persons
best of luck for ur future work

05 Oct 2012 Surapong  
13 Sep 2012 javad khan

Has anyone tried to modify the (encoder and decoder) code and use random data generator rather than all zero code word?

Comment only
19 Aug 2011 Khandaker Mahmood

Please could anyone tell me the meaning of the inputs in decode_ldpc_matlab.m file.
I know that:
rx_waveform - received vector

No - noise

h - parity check matrix

rows - rows of the parity check matrix(correct me if I am wrong!!)

cols - columns of the parity check matrix(again correct me if I am wrong!!)
max_iter - Maiximum iteartion

BUT I AM NOT SURE WHAT ind,r,c input should be? Anyone, can you tell me?


Thanks in advance.

Comment only
09 Jul 2011 vaggelis1989

very good thanks you !!

05 Apr 2010 subhashini gupta

how the LLR is computed in this code , i cudn't get it please somebody put comments on this

04 Apr 2010 zhao long

very good ,thank you

Comment only
15 Mar 2010 Deep

Deep (view profile)

lovely code sir its awesome

15 Mar 2010 subhashini gupta

its nice ...but i have one problem regarding c simulation .files mex.h and matrix.h is not included in zip file so please send these files to my mail

Comment only
14 Nov 2008 gaddam hemanth

I had problem in simulation of LDPC codes of lengths larger than 10000.My PC is showing insufficient memory.
i am using system with 2GB RAM.
can any one suggest me the solution .If I increase the RAM size will it sort out.If so to what extent do I need to extend? Please mail me on

19 Sep 2008 feng x xiaojing


15 Sep 2008 Lishin Wang

First thank u provide this program.but i have some problem need to understand.first!H matrix's row and column maximum one's numbers are not equal (3,6)??Second!What is the decoder algorithm in accordance with??


great algorithms you are making my name bright brother keep it up

Comment only
30 Jul 2008 kashif malik

good worl but quite complicated

i appreciate your effort

Comment only
10 Jul 2008 Sabah Sewan

God Bless You ..Thnx

12 Jun 2008 xia gj

what decoding algorithms do you use?

27 May 2008 thuyoanh pham  
14 Mar 2008 Hendra setiawan  
06 Mar 2008 kalpesh patel

how to use this in Matlab for Linux ?

Comment only
19 Dec 2007 Jesada Sartthong  
21 Sep 2007 Mo Hoq  
27 Aug 2007 abc edd  
10 Aug 2007 nguyen Danh Khoa  
10 Aug 2007 Nguyen Danh Khoa  
02 Jul 2007 Ma hao

very usefull

02 Apr 2007 santhosh rajiv  
02 Apr 2007 sarada devi

This will work with out any doubt, not only for detecting errors& to plot.For passing image and to detect it also(But he did not mention which decoding algorithem is used)when i am searching i do not know which one i have to kept for this one.

25 Mar 2007 w wj  
21 Mar 2007 Rossi Enrico

The simulator is easy to read and to make it work, and surely helps to understand ho LDPC decoding works. I would like to know if it works even with block up to 20 000, I tried to use it on matrices proposed by MacKay but it seems not to takes to much to do an iteration and at zero SNR cannot find any biterrror, that is strange.

22 Feb 2007 Samuele Bandi

It works perfectly, I really needed a simulator for ldpc to start are saving me a lot of time. I would like to know if this simulator only works for regular ldpc, when are you using the assumption that h is regular?

04 Feb 2007 Mo Wen

My Graduation practice is about LDPC code.
You have given me very big help.Thanks a lot.

12 Jan 2007 qin xing  
17 Nov 2006 Hrishikesh Tapse

I would like to know the method you used for encoding of bits using the H matrix. Did you use the method, where the G matrix is contructed from the H matrix by using gauss-jordan elimination????? Pleas let me know .

12 Nov 2006 shahla motadi

decodes matrix

Comment only
29 Oct 2006 Farzad Talebi

Prepares a milestone step for a student who needs to work on LDPC coding.

09 Oct 2006 hrishikesh tapse

I want to know....which paper have u followed for this simulation....cause different authors have different design perspectives for the H matrix

27 Sep 2006 hi how r u

nice work , the codes similar to the LDPC i.e.Turbo codes,i want implementation for this codes for image transmission.

16 Sep 2006 Rajdeep Singh

Firstly, excellent job.
Now some doubts, the cpp files (decode C++ routines) needs some header files (mex.h & matrix.h) which r not provided in the zip file, if u can mail me those header files plz.
And when i try to simulate codes of around length 4k, and about 2dB, then Matlab stops responding after sometime (while it runs properly upto value of around 1.6dB).
Is there any problem at BERs of the order of 10e-8 in the code? I mean some underflow errors?

15 Sep 2006 xue lian


09 Sep 2006 César Carmona Tapia

Excellent work!! This is one of the best implementations of LDPC decoding i've seen.

22 Jun 2006 Yang Xiao

This program can simulate LDPC decoding, but there are following two problems.
One problem of the program is the LDPC codes, I find that there are Girth-4s in the H matrix, so the BER of the program is not good as many reported results.
Another problem is the decoding algorithm is still complicated, it is difficult to realize the algorithm by DSP hardware.



Comment only
18 Apr 2006 Dai Brian

Thanks in advance!

Comment only
19 Mar 2006 Chhay Kong

why is the parity check matrix H in the file 128x256regular.mat not a regular LDPC code? I thought regular LDPC code means that there are equal number of 1's in each rows and equal number of 1's in each column. Please clearify!!!

19 Feb 2006 Marcos Müller

First of all, this is a great program!
It doesn't matter if the transmitted codeword is the all-zero, since the code is linear and the channel is symmetric. If you want a more realistic simmulation, you can modify the routine to encode and transmit random bits. Just remember that the encoding will not be so easy and the performance will not be improved.

07 Feb 2006 aaron hsieh

this program is not practical because of the codeword is all zero without encoding, could you explain for that?

06 Feb 2006 m khob  
23 Jan 2006 Ahmed Youssof

Great effort and well written code

16 Jan 2006 daner riau

Ok thank for your simulation, but may i ask?, why ur generate random data with zeros data in ur codeword??

Ok.. thank

31 Dec 2005 Cindy Zhang

You did a great job!

31 Dec 2005 Falah Zawahemah

Thank you Faisal for the great contribution.

30 Dec 2005 Alberto Lopes

The Matrix H may be a regular and low density binary matrix with parity check

30 Nov 2005 sudheer reddy  
13 Nov 2005 aravind ramanujam

nice work by author
congrats to get good review from all persons
best of luck for ur future work

13 Dec 2005

The code for LDPC code simulation has now been enhanced. The C-Mex based LDPC decoder is now at least twice as fast as before (the old code is still included).

Contact us