|
@@ -1,7 +1,21 @@
|
1
|
|
-// \file cmVectOpsTemplateHdr.h
|
2
|
|
-/// Vector operations interface.
|
|
1
|
+//( { label:misc desc:"Miscellaneous vector operations." kw:[vop] }
|
3
|
2
|
|
4
|
|
-/// Setting fieldWidth or decPltCnt to to negative values result in fieldWidth == 10 or decPlCnt == 4
|
|
3
|
+// Compute the cummulative sum of sbp[dn]. Equivalent to Matlab cumsum().
|
|
4
|
+VECT_OP_TYPE* VECT_OP_FUNC(CumSum)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
|
|
5
|
+
|
|
6
|
+// Returns true if all values in each vector are equal.
|
|
7
|
+bool VECT_OP_FUNC(Equal)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
|
|
8
|
+
|
|
9
|
+// Same as Matlab linspace() v[i] = i * (limit-1)/n
|
|
10
|
+VECT_OP_TYPE* VECT_OP_FUNC(LinSpace)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE base, VECT_OP_TYPE limit );
|
|
11
|
+
|
|
12
|
+//======================================================================================================================
|
|
13
|
+//)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+//( { label:Print desc:"Vector printing functions." kw:[vop] }
|
|
17
|
+// Setting fieldWidth or decPltCnt to to negative values result in fieldWidth == 10 or decPlCnt == 4
|
|
18
|
+//
|
5
|
19
|
void VECT_OP_FUNC(Printf)( cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp, int fieldWidth, int decPlCnt, const char* fmt, unsigned flags );
|
6
|
20
|
void VECT_OP_FUNC(Print)( cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
|
7
|
21
|
void VECT_OP_FUNC(PrintE)( cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
|
|
@@ -9,64 +23,68 @@ void VECT_OP_FUNC(PrintE)( cmRpt_t* rpt, unsigned rn, unsigned cn, cons
|
9
|
23
|
void VECT_OP_FUNC(PrintLf)( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp, unsigned fieldWidth, unsigned decPlCnt, const char* fmt );
|
10
|
24
|
void VECT_OP_FUNC(PrintL)( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
|
11
|
25
|
void VECT_OP_FUNC(PrintLE)( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
|
|
26
|
+//======================================================================================================================
|
|
27
|
+//)
|
12
|
28
|
|
13
|
29
|
|
|
30
|
+//( { label:Normalization desc:"Normalization and standardization functions." kw:[vop] }
|
14
|
31
|
|
15
|
|
-/// Normalize the vector of proabilities by dividing through by the sum.
|
16
|
|
-/// This leaves the relative proportions of each value unchanged while producing a total probability of 1.0.
|
|
32
|
+// Normalize the vector of proabilities by dividing through by the sum.
|
|
33
|
+// This leaves the relative proportions of each value unchanged while producing a total probability of 1.0.
|
|
34
|
+//
|
17
|
35
|
VECT_OP_TYPE* VECT_OP_FUNC(NormalizeProbabilityVV)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
|
18
|
36
|
VECT_OP_TYPE* VECT_OP_FUNC(NormalizeProbability)(VECT_OP_TYPE* dbp, unsigned dn);
|
19
|
37
|
VECT_OP_TYPE* VECT_OP_FUNC(NormalizeProbabilityN)(VECT_OP_TYPE* dbp, unsigned dn, unsigned stride);
|
20
|
|
-
|
21
|
|
-/// Standardize the columns of the matrix by subtracting the mean and dividing by the standard deviation.
|
22
|
|
-/// uV[dcn] returns the mean of the data and is optional.
|
23
|
|
-/// sdV[dcn] return the standard deviation of the data and is optional.
|
|
38
|
+//
|
|
39
|
+// Standardize the columns of the matrix by subtracting the mean and dividing by the standard deviation.
|
|
40
|
+// uV[dcn] returns the mean of the data and is optional.
|
|
41
|
+// sdV[dcn] return the standard deviation of the data and is optional.
|
24
|
42
|
VECT_OP_TYPE* VECT_OP_FUNC(StandardizeRows)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE* uV, VECT_OP_TYPE* sdV );
|
25
|
43
|
VECT_OP_TYPE* VECT_OP_FUNC(StandardizeCols)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE* uV, VECT_OP_TYPE* sdV );
|
|
44
|
+//
|
|
45
|
+// Normalize by dividing through by the max. value.
|
|
46
|
+// dp[] ./= max(dp). Returns the index of the max value.
|
|
47
|
+unsigned VECT_OP_FUNC(NormToMax)( VECT_OP_TYPE* dp, unsigned dn );
|
|
48
|
+//
|
|
49
|
+// Normalize by dividing through by the max. absolute value.
|
|
50
|
+// db[] .*= fact / abs(max(dp));
|
|
51
|
+unsigned VECT_OP_FUNC(NormToAbsMax)( VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE fact );
|
|
52
|
+//======================================================================================================================
|
|
53
|
+//)
|
26
|
54
|
|
27
|
|
-/// dbp[] = sbp<0 .* sbp
|
28
|
|
-/// Overlapping the source and dest is allowable as long as dbp <= sbp.
|
29
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(HalfWaveRectify)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
|
30
|
55
|
|
31
|
|
-/// Compute the cummulative sum of sbp[dn]. Equivalent to Matlab cumsum().
|
32
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(CumSum)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
|
|
56
|
+//( { label:"Mean and variance" desc:"Compute mean and variance." kw:[vop] }
|
33
|
57
|
|
34
|
58
|
VECT_OP_TYPE VECT_OP_FUNC(Mean)( const VECT_OP_TYPE* sp, unsigned sn );
|
35
|
59
|
VECT_OP_TYPE VECT_OP_FUNC(MeanN)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
|
36
|
|
-
|
|
60
|
+//
|
37
|
61
|
// Take the mean of each column/row of a matrix.
|
38
|
62
|
// Set 'dim' to 0 to return mean of columns else return mean of rows.
|
39
|
63
|
VECT_OP_TYPE* VECT_OP_FUNC(MeanM)( VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim );
|
40
|
|
-
|
|
64
|
+//
|
41
|
65
|
// Take the mean of the first 'cnt' element of each column/row of a matrix.
|
42
|
66
|
// Set 'dim' to 0 to return mean of columns else return mean of rows.
|
43
|
67
|
// If 'cnt' is greater than the number of elements in the column/row then 'cnt' is
|
44
|
68
|
// reduced to the number of elements in the column/row.
|
45
|
69
|
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
|
|
-
|
|
70
|
+//
|
47
|
71
|
// Find the mean of the data points returned by srcFuncPtr(argPtr,i) and return it in dp[dim].
|
48
|
72
|
// 'dim' is both the size of dp[] and the length of each data point returned by srcFuncPtr().
|
49
|
73
|
// srcFuncPtr() will be called 'cnt' times but it may return NULL on some calls if the associated
|
50
|
74
|
// data point should not be included in the mean calculation.
|
51
|
75
|
VECT_OP_TYPE* VECT_OP_FUNC(Mean2)( VECT_OP_TYPE* dp, const VECT_OP_TYPE* (*srcFuncPtr)(void* arg, unsigned idx ), unsigned dim, unsigned cnt, void* argPtr );
|
52
|
|
-
|
53
|
|
-
|
|
76
|
+//
|
54
|
77
|
// avgPtr is optional - set to NULL to compute the average
|
55
|
78
|
VECT_OP_TYPE VECT_OP_FUNC(Variance)( const VECT_OP_TYPE* sp, unsigned sn, const VECT_OP_TYPE* avgPtr );
|
56
|
79
|
VECT_OP_TYPE VECT_OP_FUNC(VarianceN)(const VECT_OP_TYPE* sp, unsigned sn, unsigned stride, const VECT_OP_TYPE* avgPtr );
|
57
|
|
-
|
|
80
|
+//
|
58
|
81
|
// Set dim=0 to return variance of columns otherwise return variance or rows.
|
59
|
82
|
VECT_OP_TYPE* VECT_OP_FUNC(VarianceM)(VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, const VECT_OP_TYPE* avgPtr, unsigned dim );
|
|
83
|
+//======================================================================================================================
|
|
84
|
+//)
|
60
|
85
|
|
61
|
|
-// dp[] ./= max(dp). Returns the index of the max value.
|
62
|
|
-unsigned VECT_OP_FUNC(NormToMax)( VECT_OP_TYPE* dp, unsigned dn );
|
63
|
|
-
|
64
|
|
-// db[] .*= fact / abs(max(dp));
|
65
|
|
-unsigned VECT_OP_FUNC(NormToAbsMax)( VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE fact );
|
66
|
|
-
|
67
|
|
-
|
68
|
|
-VECT_OP_TYPE VECT_OP_FUNC(AlphaNorm)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE alpha );
|
69
|
86
|
|
|
87
|
+//( { label:"Covariance" desc:"Matrix covariance" kw:[vop] }
|
70
|
88
|
|
71
|
89
|
// Calculate the sample covariance matrix from a set of Gaussian distributed multidimensional data.
|
72
|
90
|
// sp[dn,scn] is the data set.
|
|
@@ -92,8 +110,10 @@ void VECT_OP_FUNC(GaussCovariance)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP
|
92
|
110
|
// through the 'sn' data points.
|
93
|
111
|
// The result of this function are identical to the octave cov() function.
|
94
|
112
|
void VECT_OP_FUNC(GaussCovariance2)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* (*srcFuncPtr)(void* userPtr, unsigned idx), unsigned sn, void* userPtr, const VECT_OP_TYPE* uV, const unsigned* selIdxV, unsigned selKey );
|
|
113
|
+//======================================================================================================================
|
|
114
|
+//)
|
95
|
115
|
|
96
|
|
-bool VECT_OP_FUNC(Equal)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
|
|
116
|
+//( { label:"Float point normal" desc:"Evaluate the 'normalness of floating point values." kw:[vop] }
|
97
|
117
|
|
98
|
118
|
// Returns true if all values are 'normal' according the the C macro 'isnormal'.
|
99
|
119
|
// This function will return false if any of the values are zero.
|
|
@@ -107,80 +127,90 @@ bool VECT_OP_FUNC(IsNormalZ)(const VECT_OP_TYPE* sp, unsigned sn );
|
107
|
127
|
// Returns the count of indexes stored in dp[].
|
108
|
128
|
unsigned VECT_OP_FUNC(FindNonNormal)( unsigned* dp, unsigned dn, const VECT_OP_TYPE* sp );
|
109
|
129
|
unsigned VECT_OP_FUNC(FindNonNormalZ)( unsigned* dp, unsigned dn, const VECT_OP_TYPE* sp );
|
|
130
|
+//======================================================================================================================
|
|
131
|
+//)
|
110
|
132
|
|
111
|
133
|
|
112
|
|
-/// Successive call to to ZeroCrossCount should preserve the value pointed to by delaySmpPtr.
|
|
134
|
+//( { label:"Measure" desc:"Measure features of a vector." kw:[vop] }
|
|
135
|
+
|
|
136
|
+// Successive call to to ZeroCrossCount should preserve the value pointed to by delaySmpPtr.
|
113
|
137
|
unsigned VECT_OP_FUNC(ZeroCrossCount)( const VECT_OP_TYPE* sp, unsigned n, VECT_OP_TYPE* delaySmpPtr);
|
114
|
138
|
|
115
|
139
|
// Calculuate the sum of the squares of all elements in bp[bn].
|
116
|
140
|
VECT_OP_TYPE VECT_OP_FUNC(SquaredSum)( const VECT_OP_TYPE* bp, unsigned bn );
|
117
|
141
|
|
118
|
|
-/// sn must be <= wndSmpCnt. If sn < wndSmpCnt then sp[sn] is treated as a
|
119
|
|
-/// a partially filled buffer padded with wndSmpCnt-sn zeros.
|
120
|
|
-/// rms = sqrt( sum(sp[1:sn] .* sp[1:sn]) / wndSmpCnt )
|
|
142
|
+// sn must be <= wndSmpCnt. If sn < wndSmpCnt then sp[sn] is treated as a
|
|
143
|
+// a partially filled buffer padded with wndSmpCnt-sn zeros.
|
|
144
|
+// rms = sqrt( sum(sp[1:sn] .* sp[1:sn]) / wndSmpCnt )
|
121
|
145
|
VECT_OP_TYPE VECT_OP_FUNC(RMS)( const VECT_OP_TYPE* sp, unsigned sn, unsigned wndSmpCnt );
|
122
|
146
|
|
123
|
|
-/// This function handles the case were sn is not an integer multiple of
|
124
|
|
-/// wndSmpCnt or hopSmpCnt. In this case the function computes zero
|
125
|
|
-/// padded RMS values for windows which go past the end of sp[sn].
|
|
147
|
+// This function handles the case were sn is not an integer multiple of
|
|
148
|
+// wndSmpCnt or hopSmpCnt. In this case the function computes zero
|
|
149
|
+// padded RMS values for windows which go past the end of sp[sn].
|
126
|
150
|
VECT_OP_TYPE* VECT_OP_FUNC(RmsV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp, unsigned sn, unsigned wndSmpCnt, unsigned hopSmpCnt );
|
127
|
151
|
|
128
|
|
-
|
129
|
|
-/// Return the magnitude (Euclidean Norm) of a vector.
|
|
152
|
+// Return the magnitude (Euclidean Norm) of a vector.
|
130
|
153
|
VECT_OP_TYPE VECT_OP_FUNC(EuclidNorm)( const VECT_OP_TYPE* sp, unsigned sn );
|
131
|
154
|
|
|
155
|
+VECT_OP_TYPE VECT_OP_FUNC(AlphaNorm)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE alpha );
|
|
156
|
+
|
|
157
|
+//======================================================================================================================
|
|
158
|
+//)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+//( { label:"Distance" desc:"Calculate various vector distances." kw:[vop] }
|
|
163
|
+
|
132
|
164
|
// Return the Itakura-Saito distance between a modelled power spectrum (up) and another power spectrum (sp).
|
133
|
165
|
VECT_OP_TYPE VECT_OP_FUNC(ItakuraDistance)( const VECT_OP_TYPE* up, const VECT_OP_TYPE* sp, unsigned sn );
|
134
|
166
|
|
135
|
|
-/// Return the cosine distance between two vectors.
|
|
167
|
+// Return the cosine distance between two vectors.
|
136
|
168
|
VECT_OP_TYPE VECT_OP_FUNC(CosineDistance)( const VECT_OP_TYPE* s0P, const VECT_OP_TYPE* s1p, unsigned sn );
|
137
|
169
|
|
138
|
|
-/// Return the Euclidean distance between two vectors
|
|
170
|
+// Return the Euclidean distance between two vectors
|
139
|
171
|
VECT_OP_TYPE VECT_OP_FUNC(EuclidDistance)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
|
140
|
172
|
|
141
|
|
-/// Return the Manhattan distance between two vectors
|
|
173
|
+// Return the Manhattan distance between two vectors
|
142
|
174
|
VECT_OP_TYPE VECT_OP_FUNC(L1Distance)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
|
143
|
175
|
|
144
|
|
-/// Return the Mahalanobis distance between a vector and the mean of the distribution.
|
145
|
|
-/// The mean vector could be replaced with another vector drawn from the same distribution in which
|
146
|
|
-/// case the returned value would reflect the distance between the two vectors.
|
147
|
|
-/// 'sn' is the dimensionality of the data.
|
148
|
|
-/// up[D] and invCovM[sn,sn] are the mean and inverse of the covariance matrix of the distribution from
|
149
|
|
-/// which sp[D] is drawn.
|
|
176
|
+// Return the Mahalanobis distance between a vector and the mean of the distribution.
|
|
177
|
+// The mean vector could be replaced with another vector drawn from the same distribution in which
|
|
178
|
+// case the returned value would reflect the distance between the two vectors.
|
|
179
|
+// 'sn' is the dimensionality of the data.
|
|
180
|
+// up[D] and invCovM[sn,sn] are the mean and inverse of the covariance matrix of the distribution from
|
|
181
|
+// which sp[D] is drawn.
|
150
|
182
|
VECT_OP_TYPE VECT_OP_FUNC(MahalanobisDistance)( const VECT_OP_TYPE* sp, unsigned sn, const VECT_OP_TYPE* up, const VECT_OP_TYPE* invCovM );
|
151
|
183
|
|
152
|
|
-/// Return the KL distance between two probability distributions up[sn] and sp[sn].
|
153
|
|
-/// Since up[] and sp[] are probability distributions they must sum to 1.0.
|
|
184
|
+// Return the KL distance between two probability distributions up[sn] and sp[sn].
|
|
185
|
+// Since up[] and sp[] are probability distributions they must sum to 1.0.
|
154
|
186
|
VECT_OP_TYPE VECT_OP_FUNC(KL_Distance)( const VECT_OP_TYPE* up, const VECT_OP_TYPE* sp, unsigned sn );
|
155
|
187
|
|
156
|
|
-/// Return the KL distance between a prototype vector up[sn] and another vector sp[sn].
|
157
|
|
-/// This function first normalizes the two vectors to sum to 1.0 before calling
|
|
188
|
+// Return the KL distance between a prototype vector up[sn] and another vector sp[sn].
|
|
189
|
+// This function first normalizes the two vectors to sum to 1.0 before calling
|
158
|
190
|
// VECT_OP_FUNC(KL_Distance)(up,sp,sn);
|
159
|
191
|
VECT_OP_TYPE VECT_OP_FUNC(KL_Distance2)( const VECT_OP_TYPE* up, const VECT_OP_TYPE* sp, unsigned sn );
|
160
|
192
|
|
161
|
193
|
|
162
|
|
-/// Measure the Euclidean distance between a vector and all the columns in a matrix.
|
163
|
|
-/// If dv[scn] is no NULL then return the Euclidean distance from sv[scn] to each column of sm[srn,scn].
|
164
|
|
-/// The function returns the index of the closest data point (column) in sm[].
|
|
194
|
+// Measure the Euclidean distance between a vector and all the columns in a matrix.
|
|
195
|
+// If dv[scn] is no NULL then return the Euclidean distance from sv[scn] to each column of sm[srn,scn].
|
|
196
|
+// The function returns the index of the closest data point (column) in sm[].
|
165
|
197
|
unsigned VECT_OP_FUNC(EuclidDistanceVM)( VECT_OP_TYPE* dv, const VECT_OP_TYPE* sv, const VECT_OP_TYPE* sm, unsigned srn, unsigned scn );
|
166
|
198
|
|
167
|
|
-
|
168
|
|
-
|
169
|
|
-/// Measure the distance between each column in s0M[ rn, s0cn ] and
|
170
|
|
-/// each column in s1M[rn, s1cn ]. If dM is non-NULL store the
|
171
|
|
-/// result in dM[s1cn, s0cn]. The difference between s0M[:,0] and s1M[:,0]
|
172
|
|
-/// is stored in dM[0,0], the diff. between s0M[:,1] and s1M[:,1] is stored
|
173
|
|
-/// in dM[1,0], etc. If mvV[s0cn] is non-NULL then minV[i] is set with
|
174
|
|
-/// the distance from s0M[:,i] to the nearest column in s1M[]. If miV[s0cn]
|
175
|
|
-/// is non-NULL then it is set with the column index of s1M[] which is
|
176
|
|
-/// closest to s0M[:,i]. In other words mvV[i] gives the distance to column
|
177
|
|
-/// miV[i] from column s0M[:,i].
|
178
|
|
-/// In those cases where the distane from a prototype (centroid) to the data point
|
179
|
|
-/// is not the same as from the data point to the centroid then s1M[] is considered
|
180
|
|
-/// to hold the prototypes and s0M[] is considered to hold the data points.
|
181
|
|
-/// The distance function returns the distance from a prototype 'cV[dimN]' to
|
182
|
|
-/// an datapoint dV[dimN]. 'dimN' is the dimensionality of the data vector
|
183
|
|
-/// and is threfore equal to 'rn'.
|
|
199
|
+// Measure the distance between each column in s0M[ rn, s0cn ] and
|
|
200
|
+// each column in s1M[rn, s1cn ]. If dM is non-NULL store the
|
|
201
|
+// result in dM[s1cn, s0cn]. The difference between s0M[:,0] and s1M[:,0]
|
|
202
|
+// is stored in dM[0,0], the diff. between s0M[:,1] and s1M[:,1] is stored
|
|
203
|
+// in dM[1,0], etc. If mvV[s0cn] is non-NULL then minV[i] is set with
|
|
204
|
+// the distance from s0M[:,i] to the nearest column in s1M[]. If miV[s0cn]
|
|
205
|
+// is non-NULL then it is set with the column index of s1M[] which is
|
|
206
|
+// closest to s0M[:,i]. In other words mvV[i] gives the distance to column
|
|
207
|
+// miV[i] from column s0M[:,i].
|
|
208
|
+// In those cases where the distane from a prototype (centroid) to the data point
|
|
209
|
+// is not the same as from the data point to the centroid then s1M[] is considered
|
|
210
|
+// to hold the prototypes and s0M[] is considered to hold the data points.
|
|
211
|
+// The distance function returns the distance from a prototype 'cV[dimN]' to
|
|
212
|
+// an datapoint dV[dimN]. 'dimN' is the dimensionality of the data vector
|
|
213
|
+// and is threfore equal to 'rn'.
|
184
|
214
|
void VECT_OP_FUNC(DistVMM)(
|
185
|
215
|
VECT_OP_TYPE* dM, // dM[s1cn,s0cn] return distance mtx (optional)
|
186
|
216
|
VECT_OP_TYPE* mvV, // mvV[s0cn] distance to closest data point in s0M[]. (optional)
|
|
@@ -193,192 +223,238 @@ void VECT_OP_FUNC(DistVMM)(
|
193
|
223
|
VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* cV, const VECT_OP_TYPE* dV, unsigned dimN ),
|
194
|
224
|
void* userPtr );
|
195
|
225
|
|
196
|
|
-/// Select 'selIdxN' columns from sM[srn,scn].
|
197
|
|
-/// dM[srn,selIdxN] receives copies of the selected columns.
|
198
|
|
-/// selIdxV[selIdxN] receives the column indexes of the selected columns.
|
199
|
|
-/// Both dM[] and selIdxV[] are optional.
|
200
|
|
-/// In each case the first selected point is chosen at random.
|
201
|
|
-/// SelectRandom() then selects the following selIdxN-1 points at random.
|
202
|
|
-/// SelectMaxDist() selects the next selIdxN-1 points by selecting
|
203
|
|
-/// the point whose combined distance to the previously selected points
|
204
|
|
-/// is greatest. SelectMaxAvgDist() selectes the points whose combined
|
205
|
|
-/// average distance is greatest relative the the previously selected
|
206
|
|
-/// points.
|
|
226
|
+//======================================================================================================================
|
|
227
|
+//)
|
|
228
|
+
|
|
229
|
+//( { label:"Select columns" desc:"Select columns based on distance." kw:[vop] }
|
|
230
|
+
|
|
231
|
+// Select 'selIdxN' columns from sM[srn,scn].
|
|
232
|
+// dM[srn,selIdxN] receives copies of the selected columns.
|
|
233
|
+// selIdxV[selIdxN] receives the column indexes of the selected columns.
|
|
234
|
+// Both dM[] and selIdxV[] are optional.
|
|
235
|
+// In each case the first selected point is chosen at random.
|
|
236
|
+// SelectRandom() then selects the following selIdxN-1 points at random.
|
|
237
|
+// SelectMaxDist() selects the next selIdxN-1 points by selecting
|
|
238
|
+// the point whose combined distance to the previously selected points
|
|
239
|
+// is greatest. SelectMaxAvgDist() selectes the points whose combined
|
|
240
|
+// average distance is greatest relative the the previously selected
|
|
241
|
+// points.
|
207
|
242
|
void VECT_OP_FUNC(SelectRandom)( VECT_OP_TYPE* dM, unsigned* selIdxV, unsigned selIdxN, const VECT_OP_TYPE* sM, unsigned srn, unsigned scn );
|
208
|
243
|
void VECT_OP_FUNC(SelectMaxDist)( VECT_OP_TYPE* dM, unsigned* selIdxV, unsigned selIdxN, const VECT_OP_TYPE* sM, unsigned srn, unsigned scn, VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* s0V, const VECT_OP_TYPE* s1V, unsigned sn ), void* distUserPtr );
|
209
|
244
|
void VECT_OP_FUNC(SelectMaxAvgDist)( VECT_OP_TYPE* dM, unsigned* selIdxV, unsigned selIdxN, const VECT_OP_TYPE* sM, unsigned srn, unsigned scn, VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* s0V, const VECT_OP_TYPE* s1V, unsigned sn ), void* distUserPtr );
|
210
|
245
|
|
211
|
|
-/// Return the sum of the products (dot product)
|
|
246
|
+//======================================================================================================================
|
|
247
|
+//)
|
|
248
|
+
|
|
249
|
+//( { label:"Matrix multiplication" desc:"Various matrix multiplication operations." kw:[vop] }
|
|
250
|
+
|
|
251
|
+// Return the sum of the products (dot product)
|
212
|
252
|
VECT_OP_TYPE VECT_OP_FUNC(MultSumVV)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
|
213
|
253
|
VECT_OP_TYPE VECT_OP_FUNC(MultSumVS)( const VECT_OP_TYPE* s0p, unsigned sn, VECT_OP_TYPE s );
|
214
|
254
|
|
215
|
|
-/// Number of elements in the dest vector is expected to be the same
|
216
|
|
-/// as the number of source matrix rows.
|
217
|
|
-/// mcn gives the number of columns in the source matrix which is
|
|
255
|
+// Number of elements in the dest vector is expected to be the same
|
|
256
|
+// as the number of source matrix rows.
|
|
257
|
+// mcn gives the number of columns in the source matrix which is
|
218
|
258
|
// expected to match the number of elements in the source vector.
|
219
|
|
-/// dbp[dn,1] = mp[dn,mcn] * vp[mcn,1]
|
|
259
|
+// dbp[dn,1] = mp[dn,mcn] * vp[mcn,1]
|
220
|
260
|
VECT_OP_TYPE* VECT_OP_FUNC(MultVMV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* mp, unsigned mcn, const VECT_OP_TYPE* vp );
|
221
|
261
|
|
222
|
|
-/// Multiply a row vector with a matrix to produce a row vector.
|
223
|
|
-/// dbp[1,dn] = v[1,vn] * m[vn,dn]
|
|
262
|
+// Multiply a row vector with a matrix to produce a row vector.
|
|
263
|
+// dbp[1,dn] = v[1,vn] * m[vn,dn]
|
224
|
264
|
VECT_OP_TYPE* VECT_OP_FUNC(MultVVM)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* vp, unsigned vn, const VECT_OP_TYPE* mp );
|
225
|
265
|
|
226
|
|
-/// Same as MultVMtV() except M is transposed as part of the multiply.
|
227
|
|
-/// mrn gives the number of rows in m[] and number of elements in vp[]
|
228
|
|
-/// dpb[dn] = mp[mrn,dn] * vp[mrn]
|
|
266
|
+// Same as MultVMtV() except M is transposed as part of the multiply.
|
|
267
|
+// mrn gives the number of rows in m[] and number of elements in vp[]
|
|
268
|
+// dpb[dn] = mp[mrn,dn] * vp[mrn]
|
229
|
269
|
VECT_OP_TYPE* VECT_OP_FUNC(MultVMtV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* mp, unsigned mrn, const VECT_OP_TYPE* vp );
|
230
|
270
|
|
231
|
|
-/// Same as MultVMV() but where the matrix is diagonal.
|
|
271
|
+// Same as MultVMV() but where the matrix is diagonal.
|
232
|
272
|
VECT_OP_TYPE* VECT_OP_FUNC(MultDiagVMV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* mp, unsigned mcn, const VECT_OP_TYPE* vp );
|
233
|
273
|
|
234
|
|
-/// Generalized matrix multiply.
|
235
|
|
-/// If transposition is selected for M0 or M1 then the given dimension represent the size of the matrix 'after' the transposion.
|
236
|
|
-/// d[drn,dcn] = alpha * op(m0[drn,m0cn_m1rn]) * op(m1[m0cn_m1rn,dcn]) + beta * d[drn,dcn]
|
237
|
|
-//// See enum { kTranpsoseM0Fl=0x01, kTransposeM1Fl=0x02 } in cmVectOps for flags.
|
|
274
|
+// Generalized matrix multiply.
|
|
275
|
+// If transposition is selected for M0 or M1 then the given dimension represent the size of the matrix 'after' the transposion.
|
|
276
|
+// d[drn,dcn] = alpha * op(m0[drn,m0cn_m1rn]) * op(m1[m0cn_m1rn,dcn]) + beta * d[drn,dcn]
|
|
277
|
+/// See enum { kTranpsoseM0Fl=0x01, kTransposeM1Fl=0x02 } in cmVectOps for flags.
|
238
|
278
|
VECT_OP_TYPE* VECT_OP_FUNC(MultMMM1)(VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE alpha, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn, VECT_OP_TYPE beta, unsigned flags );
|
239
|
279
|
|
240
|
|
-/// Same a VECT_OP_FUNC(MultMMM1) except allows the operation on a sub-matrix by providing the physical (memory) row count rather than the logical (matrix) row count.
|
|
280
|
+// Same a VECT_OP_FUNC(MultMMM1) except allows the operation on a sub-matrix by providing the physical (memory) row count rather than the logical (matrix) row count.
|
241
|
281
|
VECT_OP_TYPE* VECT_OP_FUNC(MultMMM2)(VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE alpha, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn, VECT_OP_TYPE beta, unsigned flags, unsigned dprn, unsigned m0prn, unsigned m1prn );
|
242
|
282
|
|
243
|
|
-/// d[drn,dcn] = m0[drn,m0cn] * m1[m1rn,dcn]
|
|
283
|
+// d[drn,dcn] = m0[drn,m0cn] * m1[m1rn,dcn]
|
244
|
284
|
VECT_OP_TYPE* VECT_OP_FUNC(MultMMM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn );
|
245
|
285
|
|
246
|
|
-/// same as MultMMM() except second source matrix is transposed prior to the multiply
|
|
286
|
+// same as MultMMM() except second source matrix is transposed prior to the multiply
|
247
|
287
|
VECT_OP_TYPE* VECT_OP_FUNC(MultMMMt)(VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn );
|
248
|
|
-
|
249
|
288
|
|
250
|
|
-// Raise dbp[] to the power 'expon'
|
251
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(PowVS)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE expon );
|
252
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(PowVVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE expon );
|
|
289
|
+//======================================================================================================================
|
|
290
|
+//)
|
253
|
291
|
|
254
|
|
-// Take the natural log of all values in sbp[dn]. It is allowable for sbp point to the same array as dbp=.
|
255
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(LogV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
|
|
292
|
+//( { label:"Linear algebra" desc:"Miscellaneous linear algebra operations. Determinant, Inversion, Cholesky decompostion. Linear system solver." kw:[vop] }
|
256
|
293
|
|
257
|
|
-// Convert a magnitude (amplitude) spectrum to/from decibels.
|
258
|
|
-// It is allowable for dbp==sbp.
|
259
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(AmplToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
|
260
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(DbToAmplVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
|
261
|
|
-
|
262
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(PowToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
|
263
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(DbToPowVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
|
264
|
|
-
|
265
|
|
-/// Initialize dbp[dn,dn] as a square symetric positive definite matrix using values
|
266
|
|
-/// from a random uniform distribution. This is useful for initializing random
|
267
|
|
-/// covariance matrices as used by multivariate Gaussian distributions
|
268
|
|
-/// If t is non-NULL it must point to a block of scratch memory of t[dn,dn].
|
269
|
|
-/// If t is NULL then scratch memory is internally allocated and deallocated.
|
|
294
|
+// Initialize dbp[dn,dn] as a square symetric positive definite matrix using values
|
|
295
|
+// from a random uniform distribution. This is useful for initializing random
|
|
296
|
+// covariance matrices as used by multivariate Gaussian distributions
|
|
297
|
+// If t is non-NULL it must point to a block of scratch memory of t[dn,dn].
|
|
298
|
+// If t is NULL then scratch memory is internally allocated and deallocated.
|
270
|
299
|
VECT_OP_TYPE* VECT_OP_FUNC(RandSymPosDef)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE* t );
|
271
|
300
|
|
272
|
301
|
|
273
|
|
-
|
274
|
|
-/// Compute the determinant of any square matrix.
|
|
302
|
+// Compute the determinant of any square matrix.
|
275
|
303
|
VECT_OP_TYPE VECT_OP_FUNC(DetM)( const VECT_OP_TYPE* sp, unsigned srn );
|
276
|
304
|
|
277
|
|
-/// Compute the determinant of a diagonal matrix.
|
|
305
|
+// Compute the determinant of a diagonal matrix.
|
278
|
306
|
VECT_OP_TYPE VECT_OP_FUNC(DetDiagM)( const VECT_OP_TYPE* sp, unsigned srn);
|
279
|
307
|
|
280
|
|
-/// Compute the log determinant of any square matrix.
|
|
308
|
+// Compute the log determinant of any square matrix.
|
281
|
309
|
VECT_OP_TYPE VECT_OP_FUNC(LogDetM)( const VECT_OP_TYPE* sp, unsigned srn );
|
282
|
310
|
|
283
|
|
-/// Compute the log determinant of a diagonal matrix.
|
|
311
|
+// Compute the log determinant of a diagonal matrix.
|
284
|
312
|
VECT_OP_TYPE VECT_OP_FUNC(LogDetDiagM)( const VECT_OP_TYPE* sp, unsigned srn);
|
285
|
313
|
|
286
|
314
|
|
287
|
|
-/// Compute the inverse of a square matrix. Returns NULL if the matrix is not invertable.
|
288
|
|
-/// 'drn' is the dimensionality of the data.
|
|
315
|
+// Compute the inverse of a square matrix. Returns NULL if the matrix is not invertable.
|
|
316
|
+// 'drn' is the dimensionality of the data.
|
289
|
317
|
VECT_OP_TYPE* VECT_OP_FUNC(InvM)( VECT_OP_TYPE* dp, unsigned drn );
|
290
|
318
|
|
291
|
|
-/// Compute the inverse of a diagonal matrix. Returns NULL if the matrix is not invertable.
|
|
319
|
+// Compute the inverse of a diagonal matrix. Returns NULL if the matrix is not invertable.
|
292
|
320
|
VECT_OP_TYPE* VECT_OP_FUNC(InvDiagM)( VECT_OP_TYPE* dp, unsigned drn );
|
293
|
321
|
|
294
|
|
-/// Solve a linear system of the form AX=B where A[an,an] is square.
|
295
|
|
-/// Since A is square B must have 'an' rows.
|
296
|
|
-/// Result is returned in B.
|
297
|
|
-/// Returns a pointer to B on success or NULL on fail.
|
298
|
|
-/// NOTE: Both A and B are overwritten by this operation.
|
|
322
|
+// Solve a linear system of the form AX=B where A[an,an] is square.
|
|
323
|
+// Since A is square B must have 'an' rows.
|
|
324
|
+// Result is returned in B.
|
|
325
|
+// Returns a pointer to B on success or NULL on fail.
|
|
326
|
+// NOTE: Both A and B are overwritten by this operation.
|
299
|
327
|
VECT_OP_TYPE* VECT_OP_FUNC(SolveLS)( VECT_OP_TYPE* A, unsigned an, VECT_OP_TYPE* B, unsigned bcn );
|
300
|
328
|
|
301
|
|
-/// Perform a Cholesky decomposition of the square symetric matrix U[un,un].
|
302
|
|
-/// The factorization has the form: A=U'TU.
|
303
|
|
-/// If the factorization is successful A is set to U and a pointer to A is returned.
|
304
|
|
-/// Note that the lower triangle of A is not overwritten. See CholZ().
|
305
|
|
-/// If the factorization fails NULL is returned.
|
|
329
|
+// Perform a Cholesky decomposition of the square symetric matrix U[un,un].
|
|
330
|
+// The factorization has the form: A=U'TU.
|
|
331
|
+// If the factorization is successful A is set to U and a pointer to A is returned.
|
|
332
|
+// Note that the lower triangle of A is not overwritten. See CholZ().
|
|
333
|
+// If the factorization fails NULL is returned.
|
306
|
334
|
VECT_OP_TYPE* VECT_OP_FUNC(Chol)(VECT_OP_TYPE* A, unsigned an );
|
307
|
335
|
|
308
|
|
-/// Same as Chol() but sets the lower triangle of U to zero.
|
309
|
|
-/// This is equivalent ot the Matlab version.
|
|
336
|
+// Same as Chol() but sets the lower triangle of U to zero.
|
|
337
|
+// This is equivalent ot the Matlab version.
|
310
|
338
|
VECT_OP_TYPE* VECT_OP_FUNC(CholZ)(VECT_OP_TYPE* U, unsigned un );
|
311
|
339
|
|
|
340
|
+// Calculate the best fit line: b0 + b1*x_i through the points x_i,y_i.
|
|
341
|
+// Set x to NULL if it uses sequential integers [0,1,2,3...]
|
|
342
|
+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 );
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+//======================================================================================================================
|
|
346
|
+//)
|
|
347
|
+
|
|
348
|
+//( { label:"Stretch/Shrink" desc:"Stretch or shrink a vector by resampling." kw:[vop] }
|
312
|
349
|
|
313
|
|
-/// Return the average value of the contents of sbp[] between two fractional indexes
|
|
350
|
+// Return the average value of the contents of sbp[] between two fractional indexes
|
314
|
351
|
VECT_OP_TYPE VECT_OP_FUNC(FracAvg)( double bi, double ei, const VECT_OP_TYPE* sbp, unsigned sn );
|
315
|
352
|
|
316
|
|
-/// Shrinking function - Decrease the size of sbp[] by averaging blocks of values into single values in dbp[]
|
|
353
|
+// Shrinking function - Decrease the size of sbp[] by averaging blocks of values into single values in dbp[]
|
317
|
354
|
VECT_OP_TYPE* VECT_OP_FUNC(DownSampleAvg)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn );
|
318
|
355
|
|
319
|
|
-/// Stretching function - linear interpolate between points in sbp[] to fill dbp[] ... where dn > sn
|
|
356
|
+// Stretching function - linear interpolate between points in sbp[] to fill dbp[] ... where dn > sn
|
320
|
357
|
VECT_OP_TYPE* VECT_OP_FUNC(UpSampleInterp)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn );
|
321
|
358
|
|
322
|
|
-/// Stretch or shrink the sbp[] to fit into dbp[]
|
|
359
|
+// Stretch or shrink the sbp[] to fit into dbp[]
|
323
|
360
|
VECT_OP_TYPE* VECT_OP_FUNC(FitToSize)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn );
|
324
|
361
|
|
325
|
|
-/// Stretch or shrink sV[] to fit into dV[] using a simple linear mapping.
|
326
|
|
-/// When stretching (sn<dn) each source element is repeated dn/sn times
|
327
|
|
-/// and the last fraction position is interpolated. When shrinking
|
328
|
|
-/// (sn>dn) each dest value is formed by the average of sequential segments
|
329
|
|
-/// of sn/dn source elements. Fractional values are used at the beginning
|
330
|
|
-/// and end of each segment.
|
|
362
|
+// Stretch or shrink sV[] to fit into dV[] using a simple linear mapping.
|
|
363
|
+// When stretching (sn<dn) each source element is repeated dn/sn times
|
|
364
|
+// and the last fraction position is interpolated. When shrinking
|
|
365
|
+// (sn>dn) each dest value is formed by the average of sequential segments
|
|
366
|
+// of sn/dn source elements. Fractional values are used at the beginning
|
|
367
|
+// and end of each segment.
|
331
|
368
|
VECT_OP_TYPE* VECT_OP_FUNC(LinearMap)(VECT_OP_TYPE* dV, unsigned dn, VECT_OP_TYPE* sV, unsigned sn );
|
332
|
369
|
|
333
|
|
-/// Generate a vector of uniformly distributed random numbers in the range minVal to maxVal.
|
|
370
|
+//======================================================================================================================
|
|
371
|
+//)
|
|
372
|
+
|
|
373
|
+//( { label:"Random number generation" desc:"Generate random numbers." kw:[vop] }
|
|
374
|
+
|
|
375
|
+// Generate a vector of uniformly distributed random numbers in the range minVal to maxVal.
|
334
|
376
|
VECT_OP_TYPE* VECT_OP_FUNC(Random)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE minVal, VECT_OP_TYPE maxVal );
|
335
|
377
|
|
336
|
|
-/// Generate dn random numbers integers between 0 and wn-1 based on a the relative
|
337
|
|
-/// weights in wp[wn]. Note thtat the weights do not have to sum to 1.0.
|
|
378
|
+// Generate dn random numbers integers between 0 and wn-1 based on a the relative
|
|
379
|
+// weights in wp[wn]. Note thtat the weights do not have to sum to 1.0.
|
338
|
380
|
unsigned* VECT_OP_FUNC(WeightedRandInt)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* wp, unsigned wn );
|
339
|
381
|
|
340
|
|
-/// Generate a vector of normally distributed univariate random numbers
|
|
382
|
+// Generate a vector of normally distributed univariate random numbers
|
341
|
383
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGauss)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE mean, VECT_OP_TYPE var );
|
342
|
384
|
|
343
|
|
-/// Generate a vector of normally distributed univariate random numbers where each value has been drawn from a
|
344
|
|
-/// seperately parameterized Gaussian distribution. meanV[] and varV[] must both contain dn velues.
|
|
385
|
+// Generate a vector of normally distributed univariate random numbers where each value has been drawn from a
|
|
386
|
+// seperately parameterized Gaussian distribution. meanV[] and varV[] must both contain dn velues.
|
345
|
387
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* varV );
|
346
|
388
|
|
347
|
|
-/// Generate a matrix of multi-dimensional random values. Each column represents a single vector value and each row contains a dimension.
|
348
|
|
-/// meanV[] and varV[] must both contain drn elements where each meanV[i],varV[i] pair parameterize one dimensions Gaussian distribution.
|
|
389
|
+// Generate a matrix of multi-dimensional random values. Each column represents a single vector value and each row contains a dimension.
|
|
390
|
+// meanV[] and varV[] must both contain drn elements where each meanV[i],varV[i] pair parameterize one dimensions Gaussian distribution.
|
349
|
391
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* varV );
|
350
|
392
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussDiagM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* diagCovarM );
|
351
|
393
|
|
352
|
|
-/// Generate a matrix of multivariate random values drawn from a normal distribution.
|
353
|
|
-/// The dimensionality of the values are 'drn'.
|
354
|
|
-/// The count of returned values is 'dcn'.
|
355
|
|
-/// meanV[drn] and covarM[drn,drn] parameterize the normal distribution.
|
356
|
|
-/// The covariance matrix must be symetric and positive definite.
|
357
|
|
-/// t[(drn*drn) ] points to scratch memory or is set to NULL if the function should
|
358
|
|
-/// allocate the memory internally.
|
359
|
|
-/// Based on octave function mvrnd.m.
|
|
394
|
+// Generate a matrix of multivariate random values drawn from a normal distribution.
|
|
395
|
+// The dimensionality of the values are 'drn'.
|
|
396
|
+// The count of returned values is 'dcn'.
|
|
397
|
+// meanV[drn] and covarM[drn,drn] parameterize the normal distribution.
|
|
398
|
+// The covariance matrix must be symetric and positive definite.
|
|
399
|
+// t[(drn*drn) ] points to scratch memory or is set to NULL if the function should
|
|
400
|
+// allocate the memory internally.
|
|
401
|
+// Based on octave function mvrnd.m.
|
360
|
402
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussNonDiagM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* covarM, VECT_OP_TYPE* t );
|
361
|
403
|
|
362
|
|
-/// Same as RandomGaussNonDiagM() except requires the upper trianglular
|
363
|
|
-/// Cholesky factor of the covar matrix in 'uM'.
|
|
404
|
+// Same as RandomGaussNonDiagM() except requires the upper trianglular
|
|
405
|
+// Cholesky factor of the covar matrix in 'uM'.
|
364
|
406
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussNonDiagM2)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* uM );
|
365
|
407
|
|
366
|
408
|
|
367
|
|
-/// Generate a matrix of N*K multi-dimensional data points.
|
368
|
|
-/// Where D is the dimensionality of the data. (D == drn).
|
369
|
|
-/// K is the number of multi-dimensional PDF's (clusters).
|
370
|
|
-/// N is the number of data points to generate per cluster.
|
371
|
|
-/// dbp[ D, N*K ] contains the returned data point.
|
372
|
|
-/// The first N columns is associated with the cluster 0,
|
373
|
|
-/// the next N columns is associated with cluster 1, ...
|
374
|
|
-/// meanM[ D, K ] and varM[D,K] parameterize the generating PDF.s for each cluster
|
|
409
|
+// Generate a matrix of N*K multi-dimensional data points.
|
|
410
|
+// Where D is the dimensionality of the data. (D == drn).
|
|
411
|
+// K is the number of multi-dimensional PDF's (clusters).
|
|
412
|
+// N is the number of data points to generate per cluster.
|
|
413
|
+// dbp[ D, N*K ] contains the returned data point.
|
|
414
|
+// The first N columns is associated with the cluster 0,
|
|
415
|
+// the next N columns is associated with cluster 1, ...
|
|
416
|
+// meanM[ D, K ] and varM[D,K] parameterize the generating PDF.s for each cluster
|
375
|
417
|
VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussMM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanM, const VECT_OP_TYPE* varM, unsigned K );
|
376
|
418
|
|
377
|
|
-/// Generate the set of coordinates which describe a circle with a center at x,y.
|
378
|
|
-/// dbp[dn,2] must contain 2*dn elements. The first column holds the x coord and and the second holds the y coord.
|
379
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(CircleCoords)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE x, VECT_OP_TYPE y, VECT_OP_TYPE varX, VECT_OP_TYPE varY );
|
380
|
419
|
|
381
|
|
-/// The following functions all return the phase of the next value.
|
|
420
|
+// Evaluate the univariate normal distribution defined by 'mean' and 'stdDev'.
|
|
421
|
+VECT_OP_TYPE* VECT_OP_FUNC(GaussPDF)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE mean, VECT_OP_TYPE stdDev );
|
|
422
|
+
|
|
423
|
+// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
|
|
424
|
+// at the data points held in the columns of xM[D,N]. Return the evaluation
|
|
425
|
+// results in the vector yV[N]. D is the dimensionality of the data. N is the number of
|
|
426
|
+// data points to evaluate and values to return in yV[N].
|
|
427
|
+// Set diagFl to true if covarM is diagonal.
|
|
428
|
+// The function fails and returns false if the covariance matrix is singular.
|
|
429
|
+bool VECT_OP_FUNC(MultVarGaussPDF)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* covarM, unsigned D, unsigned N, bool diagFl );
|
|
430
|
+
|
|
431
|
+// Same as multVarGaussPDF[] except takes the inverse covar mtx invCovarM[D,D]
|
|
432
|
+// and log determinant of covar mtx.
|
|
433
|
+// Always returns yV[].
|
|
434
|
+VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF2)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* invCovarM, VECT_OP_TYPE logDet, unsigned D, unsigned N, bool diagFl );
|
|
435
|
+
|
|
436
|
+// Same as multVarGaussPDF[] except uses a function to obtain the data vectors.
|
|
437
|
+// srcFunc() can filter the data points by returning NULL if the data vector at frmIdx should
|
|
438
|
+// not be evaluated against the PDF. In this case yV[frmIdx] will be set to 0.
|
|
439
|
+VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF3)(
|
|
440
|
+ VECT_OP_TYPE* yV,
|
|
441
|
+ const VECT_OP_TYPE* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
|
|
442
|
+ void* funcDataPtr,
|
|
443
|
+ const VECT_OP_TYPE* meanV,
|
|
444
|
+ const VECT_OP_TYPE* invCovarM,
|
|
445
|
+ VECT_OP_TYPE logDet,
|
|
446
|
+ unsigned D,
|
|
447
|
+ unsigned N,
|
|
448
|
+ bool diagFl );
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+//======================================================================================================================
|
|
452
|
+//)
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+//( { label:"Signal generators" desc:"Generate periodic signals." kw:[vop] }
|
|
456
|
+
|
|
457
|
+// The following functions all return the phase of the next value.
|
382
|
458
|
unsigned VECT_OP_FUNC(SynthSine)( VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz );
|
383
|
459
|
unsigned VECT_OP_FUNC(SynthCosine)( VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz );
|
384
|
460
|
unsigned VECT_OP_FUNC(SynthSquare)( VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz, unsigned otCnt );
|
|
@@ -389,11 +465,33 @@ unsigned VECT_OP_FUNC(SynthImpulse)( VECT_OP_TYPE* dbp, unsigned dn, unsi
|
389
|
465
|
unsigned VECT_OP_FUNC(SynthPhasor)( VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz );
|
390
|
466
|
|
391
|
467
|
|
392
|
|
-/// Return value should be passed back via delaySmp on the next call.
|
|
468
|
+// Return value should be passed back via delaySmp on the next call.
|
393
|
469
|
VECT_OP_TYPE VECT_OP_FUNC(SynthPinkNoise)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE delaySmp );
|
394
|
470
|
|
395
|
|
-/// Same as Matlab linspace() v[i] = i * (limit-1)/n
|
396
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(LinSpace)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE base, VECT_OP_TYPE limit );
|
|
471
|
+//======================================================================================================================
|
|
472
|
+//)
|
|
473
|
+
|
|
474
|
+//( { label:"Exponential conversion" desc:"pow() and log() functions." kw:[vop] }
|
|
475
|
+
|
|
476
|
+// Raise dbp[] to the power 'expon'
|
|
477
|
+VECT_OP_TYPE* VECT_OP_FUNC(PowVS)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE expon );
|
|
478
|
+VECT_OP_TYPE* VECT_OP_FUNC(PowVVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE expon );
|
|
479
|
+
|
|
480
|
+// Take the natural log of all values in sbp[dn]. It is allowable for sbp point to the same array as dbp=.
|
|
481
|
+VECT_OP_TYPE* VECT_OP_FUNC(LogV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
|
|
482
|
+
|
|
483
|
+//======================================================================================================================
|
|
484
|
+//)
|
|
485
|
+
|
|
486
|
+//( { label:"dB Conversions" desc:"Convert vectors between dB,linear and power representations." kw:[vop] }
|
|
487
|
+
|
|
488
|
+// Convert a magnitude (amplitude) spectrum to/from decibels.
|
|
489
|
+// It is allowable for dbp==sbp.
|
|
490
|
+VECT_OP_TYPE* VECT_OP_FUNC(AmplToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
|
|
491
|
+VECT_OP_TYPE* VECT_OP_FUNC(DbToAmplVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
|
|
492
|
+
|
|
493
|
+VECT_OP_TYPE* VECT_OP_FUNC(PowToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
|
|
494
|
+VECT_OP_TYPE* VECT_OP_FUNC(DbToPowVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
|
397
|
495
|
|
398
|
496
|
VECT_OP_TYPE* VECT_OP_FUNC(LinearToDb)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE mult );
|
399
|
497
|
VECT_OP_TYPE* VECT_OP_FUNC(dBToLinear)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE mult );
|
|
@@ -401,6 +499,10 @@ VECT_OP_TYPE* VECT_OP_FUNC(AmplitudeToDb)( VECT_OP_TYPE* dbp, unsigned dn, const
|
401
|
499
|
VECT_OP_TYPE* VECT_OP_FUNC(PowerToDb)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
|
402
|
500
|
VECT_OP_TYPE* VECT_OP_FUNC(dBToAmplitude)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
|
403
|
501
|
VECT_OP_TYPE* VECT_OP_FUNC(dBToPower)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
|
|
502
|
+//======================================================================================================================
|
|
503
|
+//)
|
|
504
|
+
|
|
505
|
+//( { label:"DSP Windows" desc:"DSP windowing functions." kw:[vop] }
|
404
|
506
|
|
405
|
507
|
VECT_OP_TYPE VECT_OP_FUNC(KaiserBetaFromSidelobeReject)( double sidelobeRejectDb );
|
406
|
508
|
VECT_OP_TYPE VECT_OP_FUNC(KaiserFreqResolutionFactor)( double sidelobeRejectDb );
|
|
@@ -410,84 +512,86 @@ VECT_OP_TYPE* VECT_OP_FUNC(Hamming)( VECT_OP_TYPE* dbp, unsigned dn );
|
410
|
512
|
VECT_OP_TYPE* VECT_OP_FUNC(Hann)( VECT_OP_TYPE* dbp, unsigned dn );
|
411
|
513
|
VECT_OP_TYPE* VECT_OP_FUNC(Triangle)(VECT_OP_TYPE* dbp, unsigned dn );
|
412
|
514
|
|
413
|
|
-/// The MATLAB equivalent Hamming and Hann windows.
|
|
515
|
+// The MATLAB equivalent Hamming and Hann windows.
|
414
|
516
|
//VECT_OP_TYPE* VECT_OP_FUNC(HammingMatlab)(VECT_OP_TYPE* dbp, unsigned dn );
|
415
|
517
|
VECT_OP_TYPE* VECT_OP_FUNC(HannMatlab)( VECT_OP_TYPE* dbp, unsigned dn );
|
416
|
518
|
|
417
|
|
-/// Simulates the MATLAB GaussWin function. Set arg to 2.5 to simulate the default arg
|
418
|
|
-/// as used by MATLAB.
|
|
519
|
+// Simulates the MATLAB GaussWin function. Set arg to 2.5 to simulate the default arg
|
|
520
|
+// as used by MATLAB.
|
419
|
521
|
VECT_OP_TYPE* VECT_OP_FUNC(GaussWin)( VECT_OP_TYPE* dbp, unsigned dn, double arg );
|
420
|
|
-
|
421
|
|
-
|
422
|
|
-/// Direct form II algorithm based on the MATLAB implmentation
|
423
|
|
-/// http://www.mathworks.com/access/helpdesk/help/techdoc/ref/filter.html#f83-1015962
|
424
|
|
-/// The only difference between this function and the equivalent MATLAB filter() function
|
425
|
|
-/// is that the first feedforward coeff is given as a seperate value. The first b coefficient
|
426
|
|
-/// in this function is therefore the same as the second coefficient in the MATLAB function.
|
427
|
|
-/// and the first a[] coefficient (which is generally set to 1.0) is skipped.
|
428
|
|
-/// Example:
|
429
|
|
-/// Matlab: b=[.5 .4 .3] a=[1 .2 .1]
|
430
|
|
-/// Equiv: b0 = .5 b=[ .4 .3] a=[ .2 .1];
|
431
|
|
-///
|
432
|
|
-/// y[yn] - output vector
|
433
|
|
-/// x[xn] - input vector. xn must be <= yn. if xn < yn then the end of y[] is set to zero.
|
434
|
|
-/// b0 - signal scale. This can also be seen as b[0] (which is not included in b[])
|
435
|
|
-/// b[dn] - feedforward coeff's b[1..dn-1]
|
436
|
|
-/// a[dn] - feedback coeff's a[1..dn-1]
|
437
|
|
-/// d[dn+1] - delay registers - note that this array must be one element longer than the coeff arrays.
|
438
|
|
-///
|
|
522
|
+//======================================================================================================================
|
|
523
|
+//)
|
|
524
|
+
|
|
525
|
+//( { label:"DSP Filters" desc:"DSP filtering functions." kw:[vop] }
|
|
526
|
+
|
|
527
|
+// Direct form II algorithm based on the MATLAB implmentation
|
|
528
|
+// http://www.mathworks.com/access/helpdesk/help/techdoc/ref/filter.html#f83-1015962
|
|
529
|
+// The only difference between this function and the equivalent MATLAB filter() function
|
|
530
|
+// is that the first feedforward coeff is given as a seperate value. The first b coefficient
|
|
531
|
+// in this function is therefore the same as the second coefficient in the MATLAB function.
|
|
532
|
+// and the first a[] coefficient (which is generally set to 1.0) is skipped.
|
|
533
|
+// Example:
|
|
534
|
+// Matlab: b=[.5 .4 .3] a=[1 .2 .1]
|
|
535
|
+// Equiv: b0 = .5 b=[ .4 .3] a=[ .2 .1];
|
|
536
|
+//
|
|
537
|
+// y[yn] - output vector
|
|
538
|
+// x[xn] - input vector. xn must be <= yn. if xn < yn then the end of y[] is set to zero.
|
|
539
|
+// b0 - signal scale. This can also be seen as b[0] (which is not included in b[])
|
|
540
|
+// b[dn] - feedforward coeff's b[1..dn-1]
|
|
541
|
+// a[dn] - feedback coeff's a[1..dn-1]
|
|
542
|
+// d[dn+1] - delay registers - note that this array must be one element longer than the coeff arrays.
|
|
543
|
+//
|
439
|
544
|
VECT_OP_TYPE* VECT_OP_FUNC(Filter)( VECT_OP_TYPE* y, unsigned yn, const VECT_OP_TYPE* x, unsigned xn, cmReal_t b0, const cmReal_t* b, const cmReal_t* a, cmReal_t* d, unsigned dn );
|
440
|
545
|
|
441
|
546
|
struct cmFilter_str;
|
442
|
547
|
//typedef cmRC_t (*VECT_OP_FUNC(FiltExecFunc_t))( struct acFilter_str* f, const VECT_OP_TYPE* x, unsigned xn, VECT_OP_TYPE* y, unsigned yn );
|
443
|
548
|
VECT_OP_TYPE* VECT_OP_FUNC(FilterFilter)(struct cmFilter_str* f, cmRC_t (*func)( struct cmFilter_str* f, const VECT_OP_TYPE* x, unsigned xn, VECT_OP_TYPE* y, unsigned yn ), const cmReal_t bb[], unsigned bn, const cmReal_t aa[], unsigned an, const VECT_OP_TYPE* x, unsigned xn, VECT_OP_TYPE* y, unsigned yn );
|
444
|
549
|
|
445
|
|
-/// Compute the coefficients of a low/high pass FIR filter
|
446
|
|
-/// wndV[dn] gives the window function used to truncate the ideal low-pass impulse response.
|
447
|
|
-/// Set wndV to NULL to use a unity window.
|
448
|
|
-/// See enum { kHighPass_LPSincFl=0x01, kNormalize_LPSincFl=0x02 } in cmVectOps.h
|
|
550
|
+// Compute the coefficients of a low/high pass FIR filter
|
|
551
|
+// wndV[dn] gives the window function used to truncate the ideal low-pass impulse response.
|
|
552
|
+// Set wndV to NULL to use a unity window.
|
|
553
|
+// See enum { kHighPass_LPSincFl=0x01, kNormalize_LPSincFl=0x02 } in cmVectOps.h
|
449
|
554
|
VECT_OP_TYPE* VECT_OP_FUNC(LP_Sinc)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* wndV, double srate, double fcHz, unsigned flags );
|
450
|
555
|
|
451
|
|
-/// Compute the complex transient detection function from successive spectral frames.
|
452
|
|
-/// The spectral magntidue mag0V precedes mag1V and the phase (radians) spectrum phs0V precedes the phs1V which precedes phs2V.
|
453
|
|
-/// binCnt gives the length of each of the spectral vectors.
|
454
|
|
-VECT_OP_TYPE VECT_OP_FUNC(ComplexDetect)(const VECT_OP_TYPE* mag0V, const VECT_OP_TYPE* mag1V, const VECT_OP_TYPE* phs0V, const VECT_OP_TYPE* phs1V, const VECT_OP_TYPE* phs2V, unsigned binCnt );
|
455
|
556
|
|
456
|
557
|
|
457
|
|
-/// Compute a set of filterCnt mel filter masks for wieghting magnitude spectra consisting of binCnt bins.
|
458
|
|
-/// The spectrum is divided into bandCnt equal bands in the mel domain
|
459
|
|
-/// Each row of the matrix contains the mask for a single filter band consisting of binCnt elements.
|
460
|
|
-/// See enum{ kShiftMelFl=0x01, kNormalizeMelFl=0x02 } in cmVectOps.h
|
461
|
|
-/// Set kShiftMelFl to shift the mel bands onto the nearest FFT bin.
|
462
|
|
-/// Set kNormalizeMelFl to normalize the combined filters for unity gain.
|
463
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(MelMask)( VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, double srate, unsigned flags );
|
|
558
|
+//======================================================================================================================
|
|
559
|
+//)
|
464
|
560
|
|
|
561
|
+//( { label:"Spectral Masking" desc:"A collection of spectral masking functions." kw:[vop] }
|
465
|
562
|
|
|
563
|
+// Compute a set of filterCnt mel filter masks for wieghting magnitude spectra consisting of binCnt bins.
|
|
564
|
+// The spectrum is divided into bandCnt equal bands in the mel domain
|
|
565
|
+// Each row of the matrix contains the mask for a single filter band consisting of binCnt elements.
|
|
566
|
+// See enum{ kShiftMelFl=0x01, kNormalizeMelFl=0x02 } in cmVectOps.h
|
|
567
|
+// Set kShiftMelFl to shift the mel bands onto the nearest FFT bin.
|
|
568
|
+// Set kNormalizeMelFl to normalize the combined filters for unity gain.
|
|
569
|
+VECT_OP_TYPE* VECT_OP_FUNC(MelMask)( VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, double srate, unsigned flags );
|
466
|
570
|
|
467
|
|
-/// Fill binIdxV[bandCnt] and cntV[bandCnt] with a bin to band map.
|
468
|
|
-/// binIdx[] contains the first (minimum) bin index for a given band.
|
469
|
|
-/// cntV[] contains the count of bins for each band.
|
470
|
|
-/// bandCnt is the number of bark bands to return
|
471
|
|
-/// The function returns the actual number of bands mapped which will always be <= 23.
|
|
571
|
+// Fill binIdxV[bandCnt] and cntV[bandCnt] with a bin to band map.
|
|
572
|
+// binIdx[] contains the first (minimum) bin index for a given band.
|
|
573
|
+// cntV[] contains the count of bins for each band.
|
|
574
|
+// bandCnt is the number of bark bands to return
|
|
575
|
+// The function returns the actual number of bands mapped which will always be <= 23.
|
472
|
576
|
unsigned VECT_OP_FUNC(BarkMap)(unsigned* binIdxV, unsigned* cntV, unsigned bandCnt, unsigned binCnt, double srate );
|
473
|
577
|
|
474
|
|
-/// Calc a set of triangle fitler masks into each row of maskMtx.
|
475
|
|
-/// maskMtx[ bandCnt, binCnt ] - result matrix
|
476
|
|
-/// binHz - freq resolution of the output filters.
|
477
|
|
-/// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth.
|
478
|
|
-/// (Only used if lowHzV or uprHzV are NULL)
|
479
|
|
-/// lowHz[ bandCnt ] - set of upper frequency limits for each band.
|
480
|
|
-/// ctrHz[ bandCnt ] set to the center value in Hz for each band
|
481
|
|
-/// uprHz[ bandCnt ] - set of lower frequency limits for each band.
|
482
|
|
-/// Note if lowHz[] and uprHz[] are set to NULL then stSpread is used to set the bandwidth of each band.
|
|
578
|
+// Calc a set of triangle fitler masks into each row of maskMtx.
|
|
579
|
+// maskMtx[ bandCnt, binCnt ] - result matrix
|
|
580
|
+// binHz - freq resolution of the output filters.
|
|
581
|
+// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth.
|
|
582
|
+// (Only used if lowHzV or uprHzV are NULL)
|
|
583
|
+// lowHz[ bandCnt ] - set of upper frequency limits for each band.
|
|
584
|
+// ctrHz[ bandCnt ] set to the center value in Hz for each band
|
|
585
|
+// uprHz[ bandCnt ] - set of lower frequency limits for each band.
|
|
586
|
+// Note if lowHz[] and uprHz[] are set to NULL then stSpread is used to set the bandwidth of each band.
|
483
|
587
|
VECT_OP_TYPE* VECT_OP_FUNC(TriangleMask)(VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, const VECT_OP_TYPE* ctrHzV, VECT_OP_TYPE binHz, VECT_OP_TYPE stSpread, const VECT_OP_TYPE* lowHzV, const VECT_OP_TYPE* uprHzV );
|
484
|
588
|
|
485
|
|
-/// Calculate a set of Bark band triangle filters into maskMtx.
|
486
|
|
-/// Each row of maskMtx contains the filter for one band.
|
487
|
|
-/// maskMtx[ bandCnt, binCnt ]
|
488
|
|
-/// bandCnt - the number of triangle bankds. If bandCnt is > 24 it will be reduced to 24.
|
489
|
|
-/// binCnt - the number of bins in the filters.
|
490
|
|
-/// binHz - the width of each bin in Hz.
|
|
589
|
+// Calculate a set of Bark band triangle filters into maskMtx.
|
|
590
|
+// Each row of maskMtx contains the filter for one band.
|
|
591
|
+// maskMtx[ bandCnt, binCnt ]
|
|
592
|
+// bandCnt - the number of triangle bankds. If bandCnt is > 24 it will be reduced to 24.
|
|
593
|
+// binCnt - the number of bins in the filters.
|
|
594
|
+// binHz - the width of each bin in Hz.
|
491
|
595
|
VECT_OP_TYPE* VECT_OP_FUNC(BarkMask)(VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, double binHz );
|
492
|
596
|
|
493
|
597
|
// Terhardt 1979 (Calculating virtual pitch, Hearing Research #1, pp 155-182)
|
|
@@ -497,39 +601,27 @@ VECT_OP_TYPE* VECT_OP_FUNC(TerhardtThresholdMask)(VECT_OP_TYPE* maskV, unsigned
|
497
|
601
|
//Schroeder et al., 1979, JASA, Optimizing digital speech coders by exploiting masking properties of the human ear
|
498
|
602
|
VECT_OP_TYPE* VECT_OP_FUNC(ShroederSpreadingFunc)(VECT_OP_TYPE* m, unsigned bandCnt, double srate);
|
499
|
603
|
|
500
|
|
-/// Compute a set of DCT-II coefficients. Result dp[ coeffCnt, filtCnt ]
|
501
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(DctMatrix)( VECT_OP_TYPE* dp, unsigned coeffCnt, unsigned filtCnt );
|
502
|
|
-
|
503
|
|
-
|
504
|
|
-/// Set the indexes of local peaks greater than threshold in dbp[].
|
505
|
|
-/// Returns the number of peaks in dbp[]
|
506
|
|
-/// The maximum number of peaks from n source values is max(0,floor((n-1)/2)).
|
507
|
|
-/// Note that peaks will never be found at index 0 or index sn-1.
|
508
|
|
-unsigned VECT_OP_FUNC(PeakIndexes)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE threshold );
|
509
|
|
-
|
510
|
|
-/// Return the index of the bin containing v or acInvalidIdx if v is below sbp[0] or above sbp[ n-1 ]
|
511
|
|
-/// The bin limits are contained in sbp[].
|
512
|
|
-/// The value in spb[] are therefore expected to be in increasing order.
|
513
|
|
-/// The value returned will be in the range 0:sn-1.
|
514
|
|
-unsigned VECT_OP_FUNC(BinIndex)( const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE v );
|
515
|
|
-
|
516
|
|
-
|
517
|
|
-/// Assign each data point to one of k clusters using an expectation-maximization algorithm.
|
518
|
|
-/// k gives the number of clusters to identify
|
519
|
|
-/// Each column of sp[ srn, scn ] contains a multidimensional data point.
|
520
|
|
-/// srn therefore defines the dimensionality of the data.
|
521
|
|
-/// Each column of centroidV[ srn, k ] is set to the centroid of each of k clusters.
|
522
|
|
-/// classIdxV[ scn ] assigns the index (0 to k-1) of a cluster to each soure data point
|
523
|
|
-/// The function returns the number of iterations required for the EM process to converge.
|
524
|
|
-/// selIdxV[ scn ] is optional and contains a list of id's assoc'd with each column of sM.
|
525
|
|
-/// selKey is a integer value.
|
526
|
|
-/// If selIdxV is non-NULL then only columns of sM[] where selIdxV[] == selKey will be clustered.
|
527
|
|
-/// All columns of sM[] where the associated column in selIdxV[] do not match will be ignored.
|
528
|
|
-/// Set 'initFromCentroidFl' to true if the initial centroids should be taken from centroidM[].
|
529
|
|
-/// otherwise the initial centroids are selected from 'k' random data points in sp[].
|
530
|
|
-/// The distance function distFunc(cV,dV,dN) is called to determine the distance from a
|
531
|
|
-/// centroid the centroid 'cV[dN]' to a data point 'dV[dN]'. 'dN' is the dimensionality of the
|
532
|
|
-/// feature vector and is therefore equal to 'srn'.
|
|
604
|
+//======================================================================================================================
|
|
605
|
+//)
|
|
606
|
+
|
|
607
|
+//( { label:"Machine learning" desc:"K-means clustering and Viterbi algorithms." kw:[vop] }
|
|
608
|
+
|
|
609
|
+// Assign each data point to one of k clusters using an expectation-maximization algorithm.
|
|
610
|
+// k gives the number of clusters to identify
|
|
611
|
+// Each column of sp[ srn, scn ] contains a multidimensional data point.
|
|
612
|
+// srn therefore defines the dimensionality of the data.
|
|
613
|
+// Each column of centroidV[ srn, k ] is set to the centroid of each of k clusters.
|
|
614
|
+// classIdxV[ scn ] assigns the index (0 to k-1) of a cluster to each soure data point
|
|
615
|
+// The function returns the number of iterations required for the EM process to converge.
|
|
616
|
+// selIdxV[ scn ] is optional and contains a list of id's assoc'd with each column of sM.
|
|
617
|
+// selKey is a integer value.
|
|
618
|
+// If selIdxV is non-NULL then only columns of sM[] where selIdxV[] == selKey will be clustered.
|
|
619
|
+// All columns of sM[] where the associated column in selIdxV[] do not match will be ignored.
|
|
620
|
+// Set 'initFromCentroidFl' to true if the initial centroids should be taken from centroidM[].
|
|
621
|
+// otherwise the initial centroids are selected from 'k' random data points in sp[].
|
|
622
|
+// The distance function distFunc(cV,dV,dN) is called to determine the distance from a
|
|
623
|
+// centroid the centroid 'cV[dN]' to a data point 'dV[dN]'. 'dN' is the dimensionality of the
|
|
624
|
+// feature vector and is therefore equal to 'srn'.
|
533
|
625
|
unsigned VECT_OP_FUNC(Kmeans)(
|
534
|
626
|
unsigned* classIdxV,
|
535
|
627
|
VECT_OP_TYPE* centroidM,
|
|
@@ -543,9 +635,9 @@ unsigned VECT_OP_FUNC(Kmeans)(
|
543
|
635
|
VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* cV, const VECT_OP_TYPE* dV, unsigned dN ),
|
544
|
636
|
void* userDistPtr );
|
545
|
637
|
|
546
|
|
-/// 'srcFunc() should return NULL if the data point located at 'frmIdx' should not be included in the clustering.
|
547
|
|
-/// Clustering is considered to be complete after 'maxIterCnt' iterations or when
|
548
|
|
-/// 'deltaStopCnt' or fewer data points change class on a single iteration
|
|
638
|
+// 'srcFunc() should return NULL if the data point located at 'frmIdx' should not be included in the clustering.
|
|
639
|
+// Clustering is considered to be complete after 'maxIterCnt' iterations or when
|
|
640
|
+// 'deltaStopCnt' or fewer data points change class on a single iteration
|
549
|
641
|
unsigned VECT_OP_FUNC(Kmeans2)(
|
550
|
642
|
unsigned* classIdxV, // classIdxV[scn] - data point class assignments
|
551
|
643
|
VECT_OP_TYPE* centroidM, // centroidM[srn,K] - cluster centroids
|
|
@@ -559,64 +651,67 @@ unsigned VECT_OP_FUNC(Kmeans2)(
|
559
|
651
|
int iterCnt, // max. number of iterations (-1 to ignore)
|
560
|
652
|
int deltaStopCnt); // if less than deltaStopCnt data points change classes on a given iteration then convergence occurs.
|
561
|
653
|
|
562
|
|
-/// Evaluate the univariate normal distribution defined by 'mean' and 'stdDev'.
|
563
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(GaussPDF)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE mean, VECT_OP_TYPE stdDev );
|
564
|
|
-
|
565
|
|
-/// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
|
566
|
|
-/// at the data points held in the columns of xM[D,N]. Return the evaluation
|
567
|
|
-/// results in the vector yV[N]. D is the dimensionality of the data. N is the number of
|
568
|
|
-/// data points to evaluate and values to return in yV[N].
|
569
|
|
-/// Set diagFl to true if covarM is diagonal.
|
570
|
|
-/// The function fails and returns false if the covariance matrix is singular.
|
571
|
|
-bool VECT_OP_FUNC(MultVarGaussPDF)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* covarM, unsigned D, unsigned N, bool diagFl );
|
|
654
|
+// Determine the most likely state sequece stateV[timeN] given a
|
|
655
|
+// transition matrix a[stateN,stateN],
|
|
656
|
+// observation probability matrix b[stateN,timeN] and
|
|
657
|
+// initial state probability vector phi[stateN].
|
|
658
|
+// a[i,j] is the probability of transitioning from state i to state j.
|
|
659
|
+// b[i,t] is the probability of state i emitting the obj t.
|
|
660
|
+void VECT_OP_FUNC(DiscreteViterbi)(unsigned* stateV, unsigned timeN, unsigned stateN, const VECT_OP_TYPE* phi, const VECT_OP_TYPE* a, const VECT_OP_TYPE* b );
|
572
|
661
|
|
573
|
|
-/// Same as multVarGaussPDF[] except takes the inverse covar mtx invCovarM[D,D]
|
574
|
|
-/// and log determinant of covar mtx.
|
575
|
|
-/// Always returns yV[].
|
576
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF2)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* invCovarM, VECT_OP_TYPE logDet, unsigned D, unsigned N, bool diagFl );
|
577
|
662
|
|
578
|
|
-/// Same as multVarGaussPDF[] except uses a function to obtain the data vectors.
|
579
|
|
-/// srcFunc() can filter the data points by returning NULL if the data vector at frmIdx should
|
580
|
|
-/// not be evaluated against the PDF. In this case yV[frmIdx] will be set to 0.
|
581
|
|
-VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF3)(
|
582
|
|
- VECT_OP_TYPE* yV,
|
583
|
|
- const VECT_OP_TYPE* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
|
584
|
|
- void* funcDataPtr,
|
585
|
|
- const VECT_OP_TYPE* meanV,
|
586
|
|
- const VECT_OP_TYPE* invCovarM,
|
587
|
|
- VECT_OP_TYPE logDet,
|
588
|
|
- unsigned D,
|
589
|
|
- unsigned N,
|
590
|
|
- bool diagFl );
|
|
663
|
+//======================================================================================================================
|
|
664
|
+//)
|
591
|
665
|
|
592
|
|
-/// Determine the most likely state sequece stateV[timeN] given a
|
593
|
|
-/// transition matrix a[stateN,stateN],
|
594
|
|
-/// observation probability matrix b[stateN,timeN] and
|
595
|
|
-/// initial state probability vector phi[stateN].
|
596
|
|
-/// a[i,j] is the probability of transitioning from state i to state j.
|
597
|
|
-/// b[i,t] is the probability of state i emitting the obj t.
|
598
|
|
-void VECT_OP_FUNC(DiscreteViterbi)(unsigned* stateV, unsigned timeN, unsigned stateN, const VECT_OP_TYPE* phi, const VECT_OP_TYPE* a, const VECT_OP_TYPE* b );
|
|
666
|
+//( { label:"Graphics" desc:"Graphics related algorithms." kw:[vop] }
|
599
|
667
|
|
|
668
|
+// Generate the set of coordinates which describe a circle with a center at x,y.
|
|
669
|
+// dbp[dn,2] must contain 2*dn elements. The first column holds the x coord and and the second holds the y coord.
|
|
670
|
+VECT_OP_TYPE* VECT_OP_FUNC(CircleCoords)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE x, VECT_OP_TYPE y, VECT_OP_TYPE varX, VECT_OP_TYPE varY );
|
600
|
671
|
|
601
|
|
-/// Clip the line defined by x0,y0 to x1,y1 into the rect defined by xMin,yMin xMax,yMax.
|
|
672
|
+// Clip the line defined by x0,y0 to x1,y1 into the rect defined by xMin,yMin xMax,yMax.
|
602
|
673
|
bool VECT_OP_FUNC(ClipLine)( VECT_OP_TYPE* x0, VECT_OP_TYPE* y0, VECT_OP_TYPE* x1, VECT_OP_TYPE* y1, VECT_OP_TYPE xMin, VECT_OP_TYPE yMin, VECT_OP_TYPE xMax, VECT_OP_TYPE yMax );
|
603
|
674
|
|
604
|
|
-/// Return true if the line defined by x0,y0 to x1,y1 intersects with
|
605
|
|
-/// the rectangle formed by xMin,yMin - xMax,yMax
|
|
675
|
+// Return true if the line defined by x0,y0 to x1,y1 intersects with
|
|
676
|
+// the rectangle formed by xMin,yMin - xMax,yMax
|
606
|
677
|
bool VECT_OP_FUNC(IsLineInRect)( VECT_OP_TYPE x0, VECT_OP_TYPE y0, VECT_OP_TYPE x1, VECT_OP_TYPE y1, VECT_OP_TYPE xMin, VECT_OP_TYPE yMin, VECT_OP_TYPE xMax, VECT_OP_TYPE yMax );
|
607
|
678
|
|
608
|
679
|
|
609
|
|
-/// Return the perpendicular distance from the line formed by x0,y0 and x1,y1
|
610
|
|
-/// and the point px,py
|
|
680
|
+// Return the perpendicular distance from the line formed by x0,y0 and x1,y1
|
|
681
|
+// and the point px,py
|
611
|
682
|
VECT_OP_TYPE VECT_OP_FUNC(PtToLineDistance)( VECT_OP_TYPE x0, VECT_OP_TYPE y0, VECT_OP_TYPE x1, VECT_OP_TYPE y1, VECT_OP_TYPE px, VECT_OP_TYPE py);
|
612
|
683
|
|
613
|
|
-/// Calculate the best fit line: b0 + b1*x_i through the points x_i,y_i.
|
614
|
|
-/// Set x to NULL if it uses sequential integers [0,1,2,3...]
|
615
|
|
-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 );
|
|
684
|
+//======================================================================================================================
|
|
685
|
+//)
|
|
686
|
+
|
|
687
|
+//( { label:"Miscellaneous DSP" desc:"Common DSP algorithms." kw:[vop] }
|
|
688
|
+
|
|
689
|
+// Compute the complex transient detection function from successive spectral frames.
|
|
690
|
+// The spectral magntidue mag0V precedes mag1V and the phase (radians) spectrum phs0V precedes the phs1V which precedes phs2V.
|
|
691
|
+// binCnt gives the length of each of the spectral vectors.
|
|
692
|
+VECT_OP_TYPE VECT_OP_FUNC(ComplexDetect)(const VECT_OP_TYPE* mag0V, const VECT_OP_TYPE* mag1V, const VECT_OP_TYPE* phs0V, const VECT_OP_TYPE* phs1V, const VECT_OP_TYPE* phs2V, unsigned binCnt );
|
|
693
|
+
|
|
694
|
+// Compute a set of DCT-II coefficients. Result dp[ coeffCnt, filtCnt ]
|
|
695
|
+VECT_OP_TYPE* VECT_OP_FUNC(DctMatrix)( VECT_OP_TYPE* dp, unsigned coeffCnt, unsigned filtCnt );
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+// Set the indexes of local peaks greater than threshold in dbp[].
|
|
699
|
+// Returns the number of peaks in dbp[]
|
|
700
|
+// The maximum number of peaks from n source values is max(0,floor((n-1)/2)).
|
|
701
|
+// Note that peaks will never be found at index 0 or index sn-1.
|
|
702
|
+unsigned VECT_OP_FUNC(PeakIndexes)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE threshold );
|
|
703
|
+
|
|
704
|
+// Return the index of the bin containing v otherwise return kInvalidIdx if v is below sbp[0] or above sbp[ n-1 ]
|
|
705
|
+// The bin limits are contained in sbp[].
|
|
706
|
+// The value in spb[] are therefore expected to be in increasing order.
|
|
707
|
+// The value returned will be in the range 0:sn-1.
|
|
708
|
+unsigned VECT_OP_FUNC(BinIndex)( const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE v );
|
616
|
709
|
|
617
|
710
|
|
618
|
|
-/// Given the points x0[xy0N],y0[xy0N] fill y1[i] with the interpolated value of y0[] at
|
619
|
|
-/// x1[i]. Note that x0[] and x1[] must be increasing monotonic.
|
620
|
|
-/// This function is similar to the octave interp1() function.
|
|
711
|
+// Given the points x0[xy0N],y0[xy0N] fill y1[i] with the interpolated value of y0[] at
|
|
712
|
+// x1[i]. Note that x0[] and x1[] must be increasing monotonic.
|
|
713
|
+// This function is similar to the octave interp1() function.
|
621
|
714
|
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 );
|
622
|
715
|
|
|
716
|
+//======================================================================================================================
|
|
717
|
+//)
|