MATLAB TO C/C++ Part2

Dora Boukari
05.08.2021
|
1137
implementation of MATLAB to C/C++ conversion and MEX-functions and simulation method Monte Carlo

Implementation environment and A Real-life Sample

In the previous paper, we highlighted the assets of MATLAB to C/C++ conversion and MEX-functions. They are crucial tools that are used to implement simulation in scientific researches. Simulation methods, such as Monte Carlo, are considered among the most useful approaches to evaluate specific implementations and algorithms. Specific implementation has to be done in specific circumstances. So, we will focus at first on the hardware and software components required for a convenient the implementation.

Then we will go deeper by discussing a real implementation of MEX-functions on a telecommunication model simulated by MATLAB. This model relies on a well-known simulation method ‘Monte Carlo’. The use of MATLAB coder and MEX-function here aims to raise its level of performance and gain execution time for real-life implementation.

Implementation environment

All the implementations in this perspective are done under specific circumstances (Hardware and Software). This is why we insist that time performance can vary for the same algorithm while using different equipments.

Hardware

This is a list of the technical characteristics of the personal computer used for this paper and the previous one:

  1. Processor/Chipset
    Processor:		   Intel (R) Core (TM ) i3-4005U
    Central Process Unit CPU:  AMD A9 9420
    Turbo speed:		   3GHz
    Max Turbo speed:	   3.6GHz
    64-bit Computing	   YES
    
  2. Memory:
    Random Access Memory RAM:	  4,00GB DDR4 SDRAM
    Memory Specification Compliance:  PC4-17000
    Cache memory:			  1MB
    RAM Memory Speed:		  2133 MHz

Software

Operating System:	Windows 7 Professional 64-bit Edition –English
Simulation program:	MATLAB 2014a 
Required tool N°1:	Microsoft .NET Framework 4.5 SDK
Required tool N°2:	Microsoft Visual C++ 2008 Redistributable
Required tool N°3:	Microsoft Visual Studio Professional 2013
Required tool N°4:	Microsoft Windows SDK for Windows 7 (7.1)

Hardware and software combined

We are interested in measuring the capacity of hardware and software while running the considered implementation on the personal computer. This information is provided by the ‘Performance index’. It is a number that varies between 1,0 and 7,9 .This scale rates the hardware/software configuration performance on the PC you work on. A high score generally means that the computer has a certain good performance that can be observed while executing advanced tasks that require several resources, compared to other computers with lower scores.

The performance index of the PC we work on is 4.5, which means a medium performance convenient to realize the demanded test but could demand some extra time to execute advanced and hard tasks.

A Real-life use case

In this paragraph, we will discuss the implantation of the Monte Carlo method as it raises a real issue that concerns a wide category of telecommunication models generally ,and our discussed example specifically .

Implementation of Monte Carlo

To study technological equipment or any system, it is very important to get precise specifications and results about every phenomenon observed. However, to maintain accurate numbers and precise interpretations we have to overcome the difficulties of non-explicit calculations, especially when we are dealing with electromagnetic waves. Here come Monte-Carlo Methods to re-use experiments many times in order to have a more convenient result while comparing the outputs. In fact, The name of this simulation method is inspired by Monte Carlo, a place known for its casinos and gambling machines where machines and games run randomly. This simulation is widely used throughout scientific projects.

According to several researchers ‘Monte-Carlo method’ is a family that gathers algorithmic methods that aim to calculate the closest digital value. It uses a random process called ‘Stochastic process’ which is the mathematical object that puts a collection of random variables to use in technics based on ‘The Laws of Mathematical Probabilities’ such as : Uniform law, Poisson distribution, Binominal law, Gaussian law, geometric law, the classical method of Box-Muller, etc.

The Studied Model

In our example, Monte Carlo is applied on Uniform Linear Array to study theoretically the reception of a signal sent by an antenna S(t), during the time, from a uniform linear array with N antennas. The signal follows countless paths to be reached by an antenna as is illustrated in Figure(1). These multi-paths occur because of the several obstacles that face the signal.

Illustration of the studied model

While discussing this case, we can see clearly how many repetitive tasks are required in the global algorithm to detect a target (S(t)). These iterative tasks make execution very heavy and enlarge the time consumption. Thus, to optimize the algorithm we are asked to work on the ‘heavy parts’.

Optimization of the Model with MEX-function

In this part, we put the spot of light on the inner consumption of time in the predicted global program on MATLAB. Before the execution of MEX-files, we need to find out all the heaviest parts in the script.

The major consumption of time lies basically in:

  • The loop going from 0 to N-1 to calculate the signal for each element of the ULA
  • The loop going from 0 to Np-1 that gathers becoming signals in S(t) from Np paths
  • The loop for performance evaluation: Monte-Carlo. It requires a repetitive implementation since it looks for getting many results relative to various parameters, each time.

Important remarks:

  • It is not always convenient to copy MEX files and to execute them on other computers with other versions of MATLAB ,because MEX files are not compatible with all versions of MATLAB. Each time you want to get MEX file that corresponds to a C file, you have to compile it on the used plateform
  • It is allowed to compile a MEX file in a specific version while changing some proprieties of compilation .For example, if you are targeting a 64-bit version, you can insert ‘mex –win64 multiply.c’ to get the file multiply.mexw64

More stories

css box model examples
Building Blocks of CSS – The Box Model

Use the CSS box model to design the placement and flow of elements in relation to one another on a webpage.

Read more
Kubernetes to expand cloud possibilities
Kubernetes - The Ideal Cloud Platform Choice

Google’s Kubernetes cloud-based app deployment platform as an optimal solution for developers and businesses due to the framework’s versatile architecture and features like scalability, immutability and separation of concern.

Read more
Creating Applications Using Flutter For iOS and Android
Creating Multi-Functional Hybrid Applications Using Flutter For iOS and Android

If you have an app for your business, you must know how difficult it can be to keep your iOS and Android apps consistent and up-to-date with each other. We think Flutter will revolutionize the app in the maintenance process.

Read more
The Best Python Libraries for Deep Learning

5 best Python libraries for deep learning

Read more
Data wrangling in Python
Data Wrangling in Python

A real-life implementation example, using the Monte Carlo simulation method, to demonstrate MATLAB to C/C++ conversion and MEX-functions

Read more
GPS in Android as a Library Module
GPS in Android as a Library Module Published on Jitpack via Github. Part 2

Part 2 of how to create a GPS library model in android and add Java class to implement GPS, which includes methods to test created library in app.

Read more

Algo uses cookies for personalization and other purposes. Learn more about cookies use. Algo supports the Digital Advertising Alliance principles. By interacting with this site, you agree to our use of cookies.