idamnjanovic@51
|
1 /**************************************************************************
|
idamnjanovic@51
|
2 *
|
idamnjanovic@51
|
3 * File name: ompmex.c
|
idamnjanovic@51
|
4 *
|
idamnjanovic@51
|
5 * Ron Rubinstein
|
idamnjanovic@51
|
6 * Computer Science Department
|
idamnjanovic@51
|
7 * Technion, Haifa 32000 Israel
|
idamnjanovic@51
|
8 * ronrubin@cs
|
idamnjanovic@51
|
9 *
|
idamnjanovic@51
|
10 * Last Updated: 18.8.2009
|
idamnjanovic@51
|
11 *
|
idamnjanovic@51
|
12 *************************************************************************/
|
idamnjanovic@51
|
13
|
idamnjanovic@51
|
14 #include "ompcore.h"
|
idamnjanovic@51
|
15 #include "omputils.h"
|
idamnjanovic@51
|
16 #include "mexutils.h"
|
idamnjanovic@51
|
17
|
idamnjanovic@51
|
18
|
idamnjanovic@51
|
19 /* Input Arguments */
|
idamnjanovic@51
|
20
|
idamnjanovic@51
|
21 #define IN_D prhs[0]
|
idamnjanovic@51
|
22 #define IN_X prhs[1]
|
idamnjanovic@51
|
23 #define IN_DtX prhs[2]
|
idamnjanovic@51
|
24 #define IN_G prhs[3]
|
idamnjanovic@51
|
25 #define IN_T prhs[4]
|
idamnjanovic@51
|
26 #define IN_SPARSE_G prhs[5]
|
idamnjanovic@51
|
27 #define IN_MSGDELTA prhs[6]
|
idamnjanovic@51
|
28 #define IN_PROFILE prhs[7]
|
idamnjanovic@51
|
29
|
idamnjanovic@51
|
30
|
idamnjanovic@51
|
31 /* Output Arguments */
|
idamnjanovic@51
|
32
|
idamnjanovic@51
|
33 #define GAMMA_OUT plhs[0]
|
idamnjanovic@51
|
34
|
idamnjanovic@51
|
35
|
idamnjanovic@51
|
36 /***************************************************************************************/
|
idamnjanovic@51
|
37
|
idamnjanovic@51
|
38
|
idamnjanovic@51
|
39 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[])
|
idamnjanovic@51
|
40
|
idamnjanovic@51
|
41 {
|
idamnjanovic@51
|
42 double *D, *x, *DtX, *G, msgdelta;
|
idamnjanovic@51
|
43 int gmode, profile, T;
|
idamnjanovic@51
|
44 mwSize m, n, L; /* D is n x m , X is n x L, DtX is m x L */
|
idamnjanovic@51
|
45
|
idamnjanovic@51
|
46
|
idamnjanovic@51
|
47 /* check parameters */
|
idamnjanovic@51
|
48
|
idamnjanovic@51
|
49 checkmatrix(IN_D, "OMP", "D");
|
idamnjanovic@51
|
50 checkmatrix(IN_X, "OMP", "X");
|
idamnjanovic@51
|
51 checkmatrix(IN_DtX, "OMP", "DtX");
|
idamnjanovic@51
|
52 checkmatrix(IN_G, "OMP", "G");
|
idamnjanovic@51
|
53
|
idamnjanovic@51
|
54 checkscalar(IN_T, "OMP", "T");
|
idamnjanovic@51
|
55 checkscalar(IN_SPARSE_G, "OMP", "sparse_g");
|
idamnjanovic@51
|
56 checkscalar(IN_MSGDELTA, "OMP", "msgdelta");
|
idamnjanovic@51
|
57 checkscalar(IN_PROFILE, "OMP", "profile");
|
idamnjanovic@51
|
58
|
idamnjanovic@51
|
59
|
idamnjanovic@51
|
60 /* get parameters */
|
idamnjanovic@51
|
61
|
idamnjanovic@51
|
62 x = D = DtX = G = 0;
|
idamnjanovic@51
|
63
|
idamnjanovic@51
|
64 if (!mxIsEmpty(IN_D))
|
idamnjanovic@51
|
65 D = mxGetPr(IN_D);
|
idamnjanovic@51
|
66
|
idamnjanovic@51
|
67 if (!mxIsEmpty(IN_X))
|
idamnjanovic@51
|
68 x = mxGetPr(IN_X);
|
idamnjanovic@51
|
69
|
idamnjanovic@51
|
70 if (!mxIsEmpty(IN_DtX))
|
idamnjanovic@51
|
71 DtX = mxGetPr(IN_DtX);
|
idamnjanovic@51
|
72
|
idamnjanovic@51
|
73 if (!mxIsEmpty(IN_G))
|
idamnjanovic@51
|
74 G = mxGetPr(IN_G);
|
idamnjanovic@51
|
75
|
idamnjanovic@51
|
76 T = (int)(mxGetScalar(IN_T)+1e-2);
|
idamnjanovic@51
|
77 if ((int)(mxGetScalar(IN_SPARSE_G)+1e-2)) {
|
idamnjanovic@51
|
78 gmode = SPARSE_GAMMA;
|
idamnjanovic@51
|
79 }
|
idamnjanovic@51
|
80 else {
|
idamnjanovic@51
|
81 gmode = FULL_GAMMA;
|
idamnjanovic@51
|
82 }
|
idamnjanovic@51
|
83 msgdelta = mxGetScalar(IN_MSGDELTA);
|
idamnjanovic@51
|
84 profile = (int)(mxGetScalar(IN_PROFILE)+1e-2);
|
idamnjanovic@51
|
85
|
idamnjanovic@51
|
86
|
idamnjanovic@51
|
87 /* check sizes */
|
idamnjanovic@51
|
88
|
idamnjanovic@51
|
89 if (D && x) {
|
idamnjanovic@51
|
90 n = mxGetM(IN_D);
|
idamnjanovic@51
|
91 m = mxGetN(IN_D);
|
idamnjanovic@51
|
92 L = mxGetN(IN_X);
|
idamnjanovic@51
|
93
|
idamnjanovic@51
|
94 if (mxGetM(IN_X) != n) {
|
idamnjanovic@51
|
95 mexErrMsgTxt("D and X have incompatible sizes.");
|
idamnjanovic@51
|
96 }
|
idamnjanovic@51
|
97
|
idamnjanovic@51
|
98 if (G) {
|
idamnjanovic@51
|
99 if (mxGetN(IN_G)!=mxGetM(IN_G)) {
|
idamnjanovic@51
|
100 mexErrMsgTxt("G must be a square matrix.");
|
idamnjanovic@51
|
101 }
|
idamnjanovic@51
|
102 if (mxGetN(IN_G) != m) {
|
idamnjanovic@51
|
103 mexErrMsgTxt("D and G have incompatible sizes.");
|
idamnjanovic@51
|
104 }
|
idamnjanovic@51
|
105 }
|
idamnjanovic@51
|
106 }
|
idamnjanovic@51
|
107
|
idamnjanovic@51
|
108 else if (DtX) {
|
idamnjanovic@51
|
109 m = mxGetM(IN_DtX);
|
idamnjanovic@51
|
110 L = mxGetN(IN_DtX);
|
idamnjanovic@51
|
111
|
idamnjanovic@51
|
112 n = T; /* arbitrary - it is enough to assume signal length is T */
|
idamnjanovic@51
|
113
|
idamnjanovic@51
|
114 if (mxGetN(IN_G)!=mxGetM(IN_G)) {
|
idamnjanovic@51
|
115 mexErrMsgTxt("G must be a square matrix.");
|
idamnjanovic@51
|
116 }
|
idamnjanovic@51
|
117 if (mxGetN(IN_G) != m) {
|
idamnjanovic@51
|
118 mexErrMsgTxt("DtX and G have incompatible sizes.");
|
idamnjanovic@51
|
119 }
|
idamnjanovic@51
|
120 }
|
idamnjanovic@51
|
121
|
idamnjanovic@51
|
122 else {
|
idamnjanovic@51
|
123 mexErrMsgTxt("Either D and X, or DtX, must be specified.");
|
idamnjanovic@51
|
124 }
|
idamnjanovic@51
|
125
|
idamnjanovic@51
|
126
|
idamnjanovic@51
|
127 /* Do OMP! */
|
idamnjanovic@51
|
128
|
idamnjanovic@51
|
129 GAMMA_OUT = ompcore(D, x, DtX, 0, G, n, m, L, T, 0, gmode, profile, msgdelta, 0);
|
idamnjanovic@51
|
130
|
idamnjanovic@51
|
131 return;
|
idamnjanovic@51
|
132 }
|
idamnjanovic@51
|
133
|