Mercurial > hg > emotion-detection-top-level
comparison Code/Descriptors/yin/private/src/interp_inplace.c @ 0:ea0c737c6323
first commit
author | Dawn Black <dawn.black@eecs.qmul.ac.uk> |
---|---|
date | Thu, 26 Jul 2012 14:46:25 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ea0c737c6323 |
---|---|
1 /* | |
2 * interp_inplace.c | |
3 * linear interpolation | |
4 * | |
5 * Alain de Cheveigné, CNRS/Ircam | |
6 * (c) 2003 CNRS | |
7 */ | |
8 | |
9 #include <math.h> | |
10 #include "mex.h" | |
11 | |
12 /* #define MWRAP */ | |
13 #include "mwrap_check.h" | |
14 | |
15 /* Input Arguments */ | |
16 #define X_IN prhs[0] | |
17 #define IDX_IN prhs[1] | |
18 | |
19 /* Output Arguments */ | |
20 | |
21 static void interp_inplace( | |
22 double *xp, /* input vector */ | |
23 double *idxp, /* index vector */ | |
24 int m, /* rows input vector */ | |
25 int midx /* rows index vector */ | |
26 ) | |
27 { | |
28 int j,idxi; | |
29 double a,b,idx,idxf; | |
30 | |
31 | |
32 for (j=0;j<midx;j++) { /* for each index */ | |
33 idx=GET(idxp[j]); | |
34 idxi=floor(idx); | |
35 idxf=idx-idxi; | |
36 if (idxi<0) { | |
37 a=GET(xp[0]); | |
38 b=GET(xp[1]); | |
39 SET(idxp[j]) = a + idx*(b-a); | |
40 } else if (idxi>=m) { | |
41 a=GET(xp[m-2]); | |
42 b=GET(xp[m-1]); | |
43 SET(idxp[j]) = b + (idx-m+1)*(b-a); | |
44 } else { | |
45 a=GET(xp[idxi]); | |
46 b=GET(xp[idxi+1]); | |
47 SET(idxp[j]) = a + idxf*(b-a); | |
48 } | |
49 } | |
50 | |
51 return; | |
52 } | |
53 | |
54 void mexFunction( | |
55 int nlhs, mxArray *plhs[], | |
56 int nrhs, const mxArray *prhs[] | |
57 ) | |
58 { | |
59 double *xp, *idxp; | |
60 int nx, mx, nidx, midx; | |
61 | |
62 /* Check for proper number of arguments */ | |
63 if (nrhs !=2 ) { | |
64 mexErrMsgTxt("INTERP_INPLACE takes 2 input arguments"); | |
65 } | |
66 | |
67 /* Check type of input */ | |
68 if (!mxIsNumeric(X_IN) || mxIsComplex(X_IN) || | |
69 mxIsSparse(X_IN) || !mxIsDouble(X_IN) ) { | |
70 mexErrMsgTxt("INTERP_INPLACE: X should be doubles"); | |
71 } | |
72 if (!mxIsNumeric(IDX_IN) || mxIsComplex(IDX_IN) || | |
73 mxIsSparse(IDX_IN) || !mxIsDouble(IDX_IN) ) { | |
74 mexErrMsgTxt("INTERP_INPLACE: Y should be doubles"); | |
75 } | |
76 mx=mxGetM(X_IN); /* rows */ | |
77 nx=mxGetN(X_IN); /* columns */ | |
78 midx=mxGetM(IDX_IN); | |
79 nidx=mxGetN(IDX_IN); | |
80 | |
81 if (nx>1 || nidx>1) { | |
82 mexErrMsgTxt("INTERP_INPLACE: X and IDX should be column vectors"); | |
83 } | |
84 if (mx<1) { | |
85 mexErrMsgTxt("INTERP_INPLACE: X should have at least two samples"); | |
86 } | |
87 | |
88 xp = mxGetPr(X_IN); | |
89 idxp = mxGetPr(IDX_IN); | |
90 | |
91 checkin_matrix((mxArray *) IDX_IN); | |
92 checkin_matrix((mxArray *) X_IN); | |
93 | |
94 /* Do the actual computations in a subroutine */ | |
95 interp_inplace(xp,idxp,mx,midx); | |
96 | |
97 checkout_matrix((mxArray *) X_IN); | |
98 checkout_matrix((mxArray *) IDX_IN); | |
99 return; | |
100 } | |
101 |