- Preface:
- Matlab Codes written in *.m file format becomes slower if one uses more loops in the 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.cOn 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 -m, mex -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:
toolkit.c- Includes calling matlab *.m files from a C-MEX content, decimal to binary conversion and bubble sort.cfunctions.
toolkit.dll
Channel Encoding Decoding:
viterbialg.c
- Popular Viterbi Algorithm, compatible with Matlab trellis structure(poly2trellis).
viterbialg.dlllistVAharddecode.m
listviterbi.c
- List Viterbi algorithm. This implements the complex list Viterbi by parallely constructing lists of best paths.
listviterbi.dll
STBC and MIMO related:
alamouti.m
Cooperative Communications: - Amplify and Forward(AF) and Decode and Forward(DF) Protocols
- References:Notes:
Based on my experience, if written mex code when executed on Matlab command line causes your program to exit: It might be that you put exit(); command somewhere in your source code. The other deadly reason could be because of a memory allocation problem in the code. Inproper memory allocation may cause system mulfunction or damage. The codes found here or quoted in some way in this web page does not refrain the user from any damage or malicious outcome in case of misuse. You use it at your own risk.
[1] J. G. Proakis, Digital Communications, 3rd edition, New York: McGraw Hill, 1995.
[2] Shu Lin and Daniel J. Costello Jr., ``Error Control Coding", Second Edition, Prentice Hall,
No comments:
Post a Comment