1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.50 out of 5)
Loading ... Loading ...
Print Print

Matlab or C for Viterbi Decoder?

by Krishna Sankar on August 21, 2009

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.

Which programming language do you prefer? (can chose any two)

View Results

Loading ... Loading ...

Note: RSS/email subscribers need to visit the site for participating and seeing the results from the poll.

Related posts

  1. Soft Input Viterbi decoder
  2. Viterbi decoder
  3. Viterbi with finite survivor state memory
  4. dspLog turns two! Happy Birthday!
  5. 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.

{ 17 comments… read them below or add one }

1 Wig August 21, 2009 at 10:52 am

Very useful , thanks~!

Reply

2 Randy September 1, 2009 at 2:34 am

I think you had something else wrong. The difference shouldn’t be this great.

Reply

3 Randy September 2, 2009 at 9:47 pm

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? :)

Reply

4 Krishna Sankar September 8, 2009 at 5:39 am

@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. :)

Reply

5 bastianazzo September 15, 2009 at 1:56 pm

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

Reply

6 Krishna Sankar September 18, 2009 at 5:40 am

@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.

Reply

7 Newbie September 18, 2009 at 11:23 pm

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.

Reply

8 Krishna Sankar September 22, 2009 at 5:42 am

@Newbie: Thanks, I ve been thinking along these lines.

Reply

9 kaneda October 15, 2009 at 11:17 am

g++ -lm script_ber_bpsk_convolutional_code_viterbi_decode.c

is better. when I use gcc, same warning occurred.

Reply

10 Krishna Sankar October 17, 2009 at 4:03 am

@kaneda: Oh, ok. The warning which came with gcc can be ignored though, I think.

Reply

11 Victor October 28, 2009 at 2:10 am

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.

Reply

12 Krishna Sankar November 8, 2009 at 7:38 am

@Victor: Well, there should not be much difference… can it be some problem with the rand() number generation?

Reply

13 Oluwafemi November 3, 2009 at 4:49 pm

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.

Reply

14 Krishna Sankar November 8, 2009 at 8:41 am

@Oluwafemi: Sorry, I have not discussed space time trellis code.

Reply

15 Walter Gallegos December 31, 2009 at 12:32 am

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.

Reply

16 baljit April 26, 2010 at 10:37 am

urgently i need matlab code for convolution coding and viterbi decoding using awgn channel for gmsk……
pls help me

Reply

17 Krishna Sankar April 27, 2010 at 4:56 am

@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.

Reply

Leave a Comment

Previous post:

Next post: