Are you bothered by speed of the speed of the simulations which you develop in Matlab/Octave? I was not bothered much, till I ran into the Viterbi decoder. If you recall, the Matlab/Octave simulation script for BER computation with hard soft decision Viterbi algorithm provided in post Viterbi with finite survivor state memory took around 10 hours to run.
I knew C was much faster, so I coded the simulation again in C. Of Course, coding in C was much more difficult. I missed many functions (like conv(), rand(), randn() etc), the plotting capabilities and the statistical analysis capabilities of Matlab/Octave.
To have a graphical debug environment for C, I installed KDbg. I already had the gcc compiler installed, and I was all set to go. The C code, executed in 14 seconds !!!
home@home-desktop:$ gcc -g -lm script_ber_bpsk_convolutional_code_viterbi_decode.c script_ber_bpsk_convolutional_code_viterbi_decode.c: In function ‘main’: script_ber_bpsk_convolutional_code_viterbi_decode.c:54: warning: incompatible implicit declaration of built-in function ‘exp10’ home@home-desktop:$ date;./a.out; date Fri Aug 21 05:35:09 IST 2009 |BER for BPSK in AWGN with hard/soft Viterbi decoder |---------------------------------------------- |Eb/N0 | BER (sim) | BER (sim) | BER (theory) | | (dB) | (hard) | (soft) | (uncoded) | |---------------------------------------------- | 0 | 0.198044 | 0.096864 | 0.078650 | | 1 | 0.128787 | 0.045707 | 0.056282 | | 2 | 0.072306 | 0.017853 | 0.037506 | | 3 | 0.032038 | 0.005107 | 0.022878 | | 4 | 0.011104 | 0.001269 | 0.012501 | | 5 | 0.002886 | 0.000277 | 0.005954 | | 6 | 0.000696 | 0.000054 | 0.002388 | | 7 | 0.000100 | 0.000005 | 0.000773 | | 8 | 0.000014 | 0.000000 | 0.000191 | | 9 | 0.000000 | 0.000000 | 0.000034 | Fri Aug 21 05:35:24 IST 2009 home@home-desktop:$
Please click here to download the C code for simulating BER for BPSK with convolutional coding with hard/soft decision Viterbi having finite survivor state memory.
Poll
I created a poll to collect your feedback on the choice of programming language. You can chose any two from Matlab/Octave/C/Scilab/Simulink/Others. If you chose “Others”, please specify some more details of the programming language in the Comments section.
Note: RSS/email subscribers need to visit the site for participating and seeing the results from the poll.
Related posts
- Soft Input Viterbi decoder
- Viterbi decoder
- Viterbi with finite survivor state memory
- dspLog turns two! Happy Birthday!
- Back!
D id you like this article? Make sure that you do not miss a new article by subscribing to RSS feed OR subscribing to e-mail newsletter. Note: Subscribing via e-mail entitles you to download the free e-Book on BER of BPSK/QPSK/16QAM/16PSK in AWGN.

(4 votes, average: 4.50 out of 5)
{ 17 comments… read them below or add one }
Very useful , thanks~!
I think you had something else wrong. The difference shouldn’t be this great.
Krishna,
I downloaded and ran the Matlab simulation – it took 198 seconds to run on my computer. I don’t know why you state in your article it takes 10 hours. Are you using an 8080?
@Randy: Uuugghh! Thanks for pointing this out.
In my desktop (Pentium4, 2.66GHz 512MB RAM, Octave 3.0.1), the simulations took nearly 10 hours. After seeing your comment, I ran the same on laptop (Dell Latitude D620 Core Duo T2400 1.83GHz, 2GB RAM, Matlab R14), the simulations completed in 55 minutes !
Maybe it has to do with the RAM OR it may be that Matlab is better than Octave. Let me do one more trial (run the same on Laptop with Octave) and then update the post.
I don’t know enough about you, but have you ever tried SAGE?
http://www.sagemath.org/
The good thing about it (IMHO) is that the language you use there is Python (which is easy to learn, and also it is a standard language), so you can get your proof of concept working easily.
If you then need speed, you can plug in Cython code (which is some sort of modified Python) giving you already some orders of magnitude of speed. If that’s still not enough, you can write a C module and use in it.
Moreover, you already have a lot of mathematical facilities you can interface with
Regards
@bastianazzo: Thanks for the comment. I have not tried Sage, but will explore.
In the meanwhile, if you are comfortable with Sage, can you consider writing a brief article on it, sharing your experience and example usage to the readers of dsplog.com? It will be of benefit to the community.
Thanks again.
I was told that integration of C code within Matlab is not very difficult. Then, maybe the best option is combining both.
- Matlab to speed up code development.
- C to speed up time consuming processes and the whole simulation.
Keep the good work Krishna. I thank you for sharing your knowledge and make all us learn and improve.
@Newbie: Thanks, I ve been thinking along these lines.
g++ -lm script_ber_bpsk_convolutional_code_viterbi_decode.c
is better. when I use gcc, same warning occurred.
@kaneda: Oh, ok. The warning which came with gcc can be ignored though, I think.
Thanks for this awesome tutorial and sample code. 1 question thou: How come when I simulate the results, the soft decision BER is different as shown on this page? Around 0.49 for 0-9 dB.
@Victor: Well, there should not be much difference… can it be some problem with the rand() number generation?
Hi Krishna Sankar,
Do you have any code in C++ for Viterbi algorithm for Space Time Trellis Code?
Please if you do, kindly help me with it?
Thank you.
@Oluwafemi: Sorry, I have not discussed space time trellis code.
Try to use Component-Pascal (http://www.oberon.ch/blackbox.html) I use this family of languages since more than 15 years, easy to learn, clean, safe, strong typing, fast compilation, run time type check, no dangling pointers, etc
In my opinion one of the best choices to scientific programing.
urgently i need matlab code for convolution coding and viterbi decoding using awgn channel for gmsk……
pls help me
@baljit: I have not done MSK decoding the Viterbi way, however by using two symbols for demodulation, got comparable performance to BPSK. http://www.dsplog.com/2009/06/16/msk-transmitter-receiver/ Hope this helps.