C library for mvnrnd and randn

1 visualización (últimos 30 días)
Jane Jean
Jane Jean el 3 de Abr. de 2012
Hello,
does anybody know a library which provides more or less the same functions as mvnrnd and randn of Matlab? The library must be also usable in within a mexFunction.
Thank you!
  2 comentarios
Titus Edelhofer
Titus Edelhofer el 3 de Abr. de 2012
Hi Jane,
I'm getting curious your mexFunction questions: why do you need all the things MATLAB provides as mex functions? Or are the mex functions needed to compare MATLAB and your hand written C code? If the latter is the case, you might want to take a look at MATLAB Coder (www.mathworks.com/products/matlab-coder) instead of writing everything by hand ...
Titus
Jane Jean
Jane Jean el 3 de Abr. de 2012
Hi, thanks for the reply.
I am porting algorithm written in Matlab into C so that when the program is delivered to the client, the algorithm is kept secret. Therefore all code must be written in C. Furthermore, the client's matlab version might not contain mvnrnd function.
I thought of using Coder but I don't have this tool at my workplace. So I was wondering if it's possible to just use a C library which provides these functions.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 3 de Abr. de 2012
For randn see e.g. Knuth v2, 3rd ed, p122.,
U1 and U2 are uniform on (0,1), then
X = Variance * cos(2*pi*U1) * sqrt(-2*ln(U2)) + Mean;
Or the same for SIN instead of COS.
You will find more resources by asking your favorite internet search engine.
Converting everything into C requires a lot of time for coding and testing. Buying the Coder might be cheaper in total. P-coding is even cheaper and it hides the source code efficiently. On the other hand each call to each toolbox function can be tracked by using the debugger. E.g. this cannot be hidden successfully:
if strcmp(input('Password', 's'), 'Password1')
granted=true;
end
x = rand(3, 4);
y = sin(x);
z = sum(y, 2);
This is just a meaningless example. It will need less than a minute to reveal this code when it is P-coded.
  5 comentarios
Titus Edelhofer
Titus Edelhofer el 3 de Abr. de 2012
One thing to notice about MATLAB Coder: it can also generate a MEX file that runs the generated C code. Doing this is a good way to check if the generated C code and the MATLAB code lead to the same results (up to numerical roundoff, of course).
And a fact that might give some confidence in the quality of the code: although MATLAB Coder came out with R2011a the first time, the technology behind has a longer history as "emlc" being a part of Real-Time Workshop (today Simulink Coder).
Jan
Jan el 3 de Abr. de 2012
@Jane: The tracking of toolbox functions is easy in P-files, but much more complicated in the Coder-created files.

Iniciar sesión para comentar.

Más respuestas (1)

Titus Edelhofer
Titus Edelhofer el 3 de Abr. de 2012
Hi Jane,
if protecting IP is your concern, you might want to try pcode: it comes with MATLAB and encrypcts the algorithm as well ...
Titus
  1 comentario
Jane Jean
Jane Jean el 3 de Abr. de 2012
Thanks for the suggestion. I'll talk to my boss about this and see if he still wants to convert everything into C.

Iniciar sesión para comentar.

Categorías

Más información sobre DSP Algorithm Acceleration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by