Pārlūkot izejas kodu

cmVectOpsTemplateHdr/Code.h : Add MeanM2() and Interp1().

master
Kevin Larke 10 gadus atpakaļ
vecāks
revīzija
be7b8819c7
2 mainītis faili ar 54 papildinājumiem un 2 dzēšanām
  1. 42
    0
      vop/cmVectOpsTemplateCode.h
  2. 12
    2
      vop/cmVectOpsTemplateHdr.h

+ 42
- 0
vop/cmVectOpsTemplateCode.h Parādīt failu

235
   return dp;
235
   return dp;
236
 }
236
 }
237
 
237
 
238
+VECT_OP_TYPE*  VECT_OP_FUNC(MeanM2)(    VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim, unsigned cnt )
239
+{
240
+  unsigned i;
241
+  unsigned cn     = dim == 0 ? scn : srn;
242
+  unsigned rn     = dim == 0 ? srn : scn;
243
+  unsigned inc    = dim == 0 ? srn : 1;
244
+  unsigned stride = dim == 0 ? 1   : srn;
245
+  unsigned d0     = 0;
246
+
247
+  for(i=0; i<cn; ++i, d0+=inc)
248
+    dp[i] = VECT_OP_FUNC(MeanN)(sp + d0, cmMin(rn,cnt), stride );
249
+
250
+  return dp;
251
+}
252
+
238
 VECT_OP_TYPE*  VECT_OP_FUNC(Mean2)(   VECT_OP_TYPE* dp, const VECT_OP_TYPE* (*srcFuncPtr)(void* arg, unsigned idx ), unsigned D, unsigned N, void* argPtr )
253
 VECT_OP_TYPE*  VECT_OP_FUNC(Mean2)(   VECT_OP_TYPE* dp, const VECT_OP_TYPE* (*srcFuncPtr)(void* arg, unsigned idx ), unsigned D, unsigned N, void* argPtr )
239
 {
254
 {
240
   unsigned i,n;
255
   unsigned i,n;
3242
 
3257
 
3243
 
3258
 
3244
 
3259
 
3260
+void VECT_OP_FUNC(Interp1)(VECT_OP_TYPE* y1, const VECT_OP_TYPE* x1, unsigned xy1N, const VECT_OP_TYPE* x0, const VECT_OP_TYPE* y0, unsigned xy0N )
3261
+{
3262
+  unsigned i,j;
3263
+
3264
+  // for each output value
3265
+  for(i=0,j=0; i<xy1N; ++i)
3266
+  {
3267
+    // x1[] and x0[] are increasing monotonic therefore j should never
3268
+    // have to decrease
3269
+    for(; j<xy0N-1; ++j)
3270
+    {
3271
+      // if x1[i] is between x0[j] and x0[j+1]
3272
+      if( x0[j] <= x1[i] && x1[i] < x0[j+1] )
3273
+      {
3274
+        // interpolate y0[j] based on the distance beteen x0[j] and x1[i].
3275
+        y1[i] = y0[j] + (y0[j+1]-y0[j]) * ((x1[i] - x0[j]) / (x0[j+1] - x0[j]));
3276
+        break;
3277
+      }
3278
+    }
3279
+
3280
+    if( j == xy0N-1 )
3281
+      y1[i] = y0[xy0N-1];
3282
+    
3283
+  }
3284
+}
3245
 
3285
 
3246
 #endif
3286
 #endif
3287
+
3288
+

+ 12
- 2
vop/cmVectOpsTemplateHdr.h Parādīt failu

38
 // Set 'dim' to 0 to return mean of columns else return mean of rows.
38
 // Set 'dim' to 0 to return mean of columns else return mean of rows.
39
 VECT_OP_TYPE*  VECT_OP_FUNC(MeanM)(    VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim );
39
 VECT_OP_TYPE*  VECT_OP_FUNC(MeanM)(    VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim );
40
 
40
 
41
+// Take the mean of the first 'cnt' element of each column/row of a matrix.
42
+// Set 'dim' to 0 to return mean of columns else return mean of rows.
43
+// If 'cnt' is greater than the number of elements in the column/row then 'cnt' is
44
+// reduced to the number of elements in the column/row.
45
+VECT_OP_TYPE*  VECT_OP_FUNC(MeanM2)(    VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim, unsigned cnt );
46
+
41
 // Find the mean of the  data points returned by srcFuncPtr(argPtr,i) and return it in dp[dim].
47
 // Find the mean of the  data points returned by srcFuncPtr(argPtr,i) and return it in dp[dim].
42
 // 'dim' is both the size of dp[] and the length of each data point returned by srcFuncPtr().
48
 // 'dim' is both the size of dp[] and the length of each data point returned by srcFuncPtr().
43
 // srcFuncPtr() will be called 'cnt' times but it may return NULL on some calls if the associated
49
 // srcFuncPtr() will be called 'cnt' times but it may return NULL on some calls if the associated
467
 /// maskMtx[ bandCnt, binCnt ] - result matrix
473
 /// maskMtx[ bandCnt, binCnt ] - result matrix
468
 /// binHz - freq resolution of the output filters.
474
 /// binHz - freq resolution of the output filters.
469
 /// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth. 
475
 /// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth. 
470
-///            (Only used if 
476
+///            (Only used if lowHzV or uprHzV are NULL)
471
 /// lowHz[ bandCnt ] - set of upper frequency limits for each band.
477
 /// lowHz[ bandCnt ] - set of upper frequency limits for each band.
472
 /// ctrHz[ bandCnt ] set to the center value in Hz for each band
478
 /// ctrHz[ bandCnt ] set to the center value in Hz for each band
473
 /// uprHz[ bandCnt ] - set of lower frequency limits for each band.
479
 /// uprHz[ bandCnt ] - set of lower frequency limits for each band.
607
 void VECT_OP_FUNC(Lsq1)(const VECT_OP_TYPE* x, const VECT_OP_TYPE* y, unsigned n, VECT_OP_TYPE* b0, VECT_OP_TYPE* b1 );
613
 void VECT_OP_FUNC(Lsq1)(const VECT_OP_TYPE* x, const VECT_OP_TYPE* y, unsigned n, VECT_OP_TYPE* b0, VECT_OP_TYPE* b1 );
608
 
614
 
609
 
615
 
610
-
616
+/// Given the points x0[xy0N],y0[xy0N] fill y1[i] with the interpolated value of y0[] at
617
+/// x1[i].  Note that x0[] and x1[] must be increasing monotonic.
618
+/// This function is similar to the octave interp1() function.
619
+void VECT_OP_FUNC(Interp1)(VECT_OP_TYPE* y1, const VECT_OP_TYPE* x1, unsigned xy1N, const VECT_OP_TYPE* x0, const VECT_OP_TYPE* y0, unsigned xy0N );
620
+ 

Notiek ielāde…
Atcelt
Saglabāt