• Research - MATLAB/C-MEX

  • Whats the raising trend?

    Raising trend for Big data applications is the well known massive parallel processing tools such as CPUs, GPUs, FPGAs scattered across the computing clusters. Regardless of what software is on, this massively parallel hardware architectures call for different software implementations to beneft from clusters' simultaneous processing capabilities. Thus, two important and interesting trends regarding Matlab's MEX code development environment became
    1. Multi Threaded Mex Code Development. (Uses CPU cores for parallel implementation. More to follow later.)
    2. MATLAB/GPU/C-MEX Code Development. (Uses GPU cores for parallel implementation.)

  • Fundamentals about MEX files:

    This page is in essense maintained to serve developersin an attempt to assist on using/compiling mex files for MATLAB as if they are written matlab function i.e., higher level m-files. Engineers of Mathworks develop optimized mex files to write matlab functions.

  • Preface:

  • Matlab Codes in *.m files becomes slower as if we use more loops in our code. Vectorization is one option to speed up the run. C/C++ languages are actually compile the code thus are much more effective in handling loops in the code. C-MEX on the other hand is a C based matlab code compiled by Matlab itself to accelarate Matlab *.m codes.
    In what follows I drop some *.m files and C-MEX files for general communication and coding theory. The letter is way faster than their *.m correspondances

  • How to compile *.mex files? - OS: Windows platform. 
  • First you need to set up your compiler in Matlab command line: mex -setup.
  • mex -setup
    Please choose your compiler for building external interface (MEX) files: 
    Would you like mex to locate installed compilers [y]/n? y
    Select a compiler: 
    [1] Digital Visual Fortran version 6.0 in C:\Program Files\Microsoft Visual Studio 
    [2] Lcc C version 2.4 in C:\MATLAB7\sys\lcc 
    [3] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio 
    [0] None 
    Compiler: 3
    Please verify your choices: 
    Compiler: Microsoft Visual C/C++ 6.0 
    Location: C:\Program Files\Microsoft Visual Studio 
    Are these correct?([y]/n): y
    Try to update options file: C:\Users\Shapo\Application Data\MathWorks\MATLAB\R14\mexopts.bat 
    From template: C:\MATLAB7\BIN\WIN32\mexopts\msvc60opts.bat 

    Done . . .

    You also can have more info using help mex option. Then, you can simply call Matlab compiler to compile mex files. The final output is corresponding *.dll file for OS Windows. Then it is going to be ready for use as if it is written as an m file:
    >> mex deneme.c

    On the other hand, probably the most popular question "How to easily convert *.m files to *.mex files?" has an answer from my side. The command mcc built on Matlab developpers does not help you at all in new versions. Although there are arguments on net that mcc –x deneme.c will work out the conversion is far from representing the truth. Although stand alone *.exe files are possible with mex -mmex -x is no longer supported by new versions and does not give you desirable results on old versions. Please use help mcc to have more information on that. All in all, I strongly advice you to start coding in C or C++/C# with #include "mex.h" in your script, then crate your gateway function/s on behalf of main subroutine in a standard C program. Finally compile it using mex command.
    More on Mex tutorial click here!

    Gateway function/s have a special structure and are basically in a known format. You can have some oppinion in your review of the following functions found in this web page.

    There are also commercial products sold as one-button conversion tool from Matlab to C or C-MEX files.Agility is one of them. For more info: click here!. So far as I am concerned there are also simulink based MEX file creation procedures, yet I am barely concerned with extra wrapper files which can complicate the process even more. One additional note: If you have problems with already built in Matlab Lcc, then try Borland C/C++ compiler.

  • Functions/Scripts:

    Following function is written to give a glipse of C-MEX structure and relationship to a simple C functions/codes. It also includes "call from a Matlab function" that is written in *.m file format. Other functions are for specific purpose and subject oriented.
  • Basic Operations:
    Includes calling matlab *.m files from a C-MEX content, decimal to binary conversion and bubble sort.cfunctions. 

    CRC appendance and generator polynomial evaluation. Also available here!

    Source Encoding:
    Spiht - by Mustafa Sakalli at RIT. (web site)
    Entropy Encoding:

  • Channel Encoding Decoding: 
    Popular Viterbi Algorithm, compatible with Matlab trellis structure(poly2trellis). 

    List Viterbi algorithm. This implements the complex list Viterbi by parallely constructing lists of best paths. 
    STBC and MIMO related:

    Cooperative Communications: - Amplify and Forward (AF) and Decode and Forward(DF) Protocols

Coding Theory: Zyablov Bound (MTLB code).

Rateless Codes: Optimization of Degree Distribution for LT codes (linear program -MTLB)

Reliability Theory: MEL Algorithm (MTLB code) [3]

Implementations of several journals of mine: Concatenated Coding and GLT for UEP