OpenCores
URL https://opencores.org/ocsvn/gng/gng/trunk

Subversion Repositories gng

[/] [gng/] [trunk/] [matlab/] [icdf_gen.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 guangxi.li
/*
2
 * Generate inverse of the normal cumulative distribution function
3
 *
4
 * The calling syntax is:
5
 *     x = icdf_gen(r)
6
 *
7
 * Input:
8
 *     z: pseudorandom numbers
9
 *
10
 * Output:
11
 *     x: Gaussian random numbers, n x 1 vector of 32-bit integer (s<16,11>)
12
 */
13
 
14
/*
15
 * Copyright (C) 2014, Guangxi Liu <guangxi.liu@opencores.org>
16
 *
17
 * This source file may be used and distributed without restriction provided
18
 * that this copyright statement is not removed from the file and that any
19
 * derivative work contains the original copyright notice and the associated
20
 * disclaimer.
21
 *
22
 * This source file is free software; you can redistribute it and/or modify it
23
 * under the terms of the GNU Lesser General Public License as published by
24
 * the Free Software Foundation; either version 2.1 of the License,
25
 * or (at your option) any later version.
26
 *
27
 * This source is distributed in the hope that it will be useful, but
28
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
29
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
30
 * License for more details.
31
 *
32
 * You should have received a copy of the GNU Lesser General Public License
33
 * along with this source; if not, download it from
34
 * http://www.opencores.org/lgpl.shtml
35
 */
36
 
37
 
38
#include "mex.h"
39
#include "icdf.h"
40
 
41
 
42
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
43
{
44
    /* Local variables */
45
    unsigned long long *r;
46
    unsigned len;
47
    long *x;
48
    unsigned i;
49
 
50
    /* Check for proper number of arguments */
51
    if (nrhs != 1)
52
        mexErrMsgTxt("One input arguments required.");
53
 
54
    if (!mxIsUint64(prhs[0]) || (mxGetN(prhs[0]) != 1))
55
        mexErrMsgTxt("icdf_gen requires that r be a column vector of unsigned 64-bit integer.");
56
 
57
    len = mxGetM(prhs[0]);
58
    if (len < 1)
59
        mexErrMsgTxt("icdf_gen requires that vector length be a positive integer.");
60
 
61
    /* Create a vector for the return argument */
62
    plhs[0] = mxCreateNumericMatrix(len, 1, mxINT32_CLASS, 0);
63
 
64
    /* Assign pointers to the various parameters */
65
    r = (unsigned long long*)mxGetData(prhs[0]);
66
    x = (long*)mxGetData(plhs[0]);
67
 
68
    /* Call function icdf and assign return value */
69
    for (i = 0; i < len; i++)
70
        x[i] = icdf(r[i]);
71
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.