📄 dsp.h
字号:
/* numElems2 <= numElems1 */
fractional* dstV, /* ptr to destination vector */
/* with numElems1+numElems2-1 elems */
fractional* srcV1, /* ptr to source vector one */
fractional* srcV2 /* ptr to source vector two */
/* dstV returned */
);
/*...........................................................................*/
extern fractional* VectorCorrelate ( /* Vector Correlation */
/* (with itself capable) */
int numElems1, /* number elements in srcV1 */
int numElems2, /* number elements in srcV2 */
/* numElems2 <= numElems1 */
fractional* dstV, /* ptr to destination vector */
/* with numElems2+numElems1-1 elems */
fractional* srcV1, /* ptr to source vector one */
fractional* srcV2 /* ptr to source vector two */
/* dstV returned */
);
/*...........................................................................*/
/****************************************************************************
*
* Interface to windowing operations.
*
* A window is a vector with a specific value distribution within its
* domain ( 0 <= n < numElems). The particular value distribution depends
* on the window being generated.
*
* Given a vector, its value distribution may be modified by applying
* a window to it. In these cases, the window must have the same number
* of elements as the vector to modify.
*
* Before a vector can be windowed, the window must be created. Window
* initialization operations are provided which generate the values of
* the window elements. For higher numerical precision, these values are
* computed in floating point arithmetic, and the resulting quantities
* stored as Q.15 fractionals.
*
* To avoid excessive overhead when applying a window operation, and since
* given a window length the values of the window elements are fixed, a
* particular window could be generated once and used many times during
* the execution of the program. Thus, it is advisable to store the window
* returned by any of the initialization operations in a permanent (static)
* vector.
*
* Additional remarks.
*
* A) All the window initialization functions have been designed to generate
* window vectors allocated in default RAM memory space (X-Data and Y-Data).
*
* B) The windowing function is designed to operate on vectors allocated
* in default RAM memory space (X-Data and Y-Data).
*
****************************************************************************/
/* Windowing operation prototypes. */
extern fractional* BartlettInit ( /* Initialize a Bartlett window */
/* computed in floating point */
/* converted to fractionals */
int numElems, /* number elements in window */
fractional* window /* ptr to window */
/* window returned */
);
/*...........................................................................*/
extern fractional* BlackmanInit ( /* Initialize a Blackman window */
/* computed in floating point */
/* converted to fractionals */
int numElems, /* number elements in window */
fractional* window /* ptr to window */
/* window returned */
);
/*...........................................................................*/
extern fractional* HammingInit ( /* Initialize a Hamming window */
/* computed in floating point */
/* converted to fractionals */
int numElems, /* number elements in window */
fractional* window /* ptr to window */
/* window returned */
);
/*...........................................................................*/
extern fractional* HanningInit ( /* Initialize a Hanning window */
/* computed in floating point */
/* converted to fractionals */
int numElems, /* number elements in window */
fractional* window /* ptr to window */
/* window returned */
);
/*...........................................................................*/
extern fractional* KaiserInit ( /* Initialize a Kaiser window */
/* computed in floating point */
/* converted to fractionals */
int numElems, /* number elements in window */
fractional* window, /* ptr to window */
float betaVal /* shape parameter */
/* window returned */
);
/*...........................................................................*/
extern fractional* VectorWindow ( /* Apply window to vector */
/* dstV[n] = srcV[n] * window[n], */
/* 0 <= n < numElems */
/* (in place capable) */
int numElems, /* number elements in srcV and window */
fractional* dstV, /* ptr to destination vector */
fractional* srcV, /* ptr to source vector */
fractional* window /* ptr to window */
/* dstV returned */
);
/*...........................................................................*/
/****************************************************************************
*
* Interface to matrix operations.
*
* A matrix is a collection of numerical values, the matrix elements,
* allocated contiguosly in memory, with the first element at the
* lowest memory address. One word of memory (two bytes) is used to
* store the value of each element, and this quantity must be interpreted
* as a fractional value in Q.15 format.
*
* A pointer addressing the first element of the matrix is used as
* a handle which provides access to each of the matrix values. The
* two dimensional arrangement of a matrix is emulated in the memory
* storage area by placing its elements organized in row major order.
* Thus, the first value in memeory is the first element of the first
* row. It is followed by the rest of the elements of the first row.
* Then, the elements of the second row are stored, and so on, until
* all the rows are in memory. This way, the element at row r and
* column c of a matrix with R rows and C columns is located from
* the matrix base address BA at:
*
* BA + ((r-1)*C + c-1)*2,
*
* Note that because of the byte addressing capabilities of the dsPIC30F,
* the addressing of a matrix element uses an increment (or decrement)
* size of 2: INC2 (or DEC2) instruction.
*
* Unary and binary operations are prototyped in this interface. The
* operand matrix in a unary operation is called the source matrix.
* In a binary operation the first operand is referred to as source
* one matrix, and the second as source two matrix. Each operation
* applies some computation to one or several elements of the source
* matrix(ces). The operations result in a matrix, referred to as the
* destination matrix.
*
* Some operations resulting in a matrix allow computation in place;
* i.e., the results of the computation are placed back on the source
* (or source one, if binary) matrix. In this case, the destination
* matrix is said to (physically) replace the source (one) matrix.
* When an operation can be computed in place it is indicated as such
* in the comments provided with its prototype.
*
* For some binary operations, the two operands can be the same (physical)
* source matrix: the operation is applied between the source matrix
* and itself. If this type of computation is possible for a given
* operation, it is indicated as such in the comments provided with
* its prototype.
*
* Some operations can be self applicable and computed in place.
*
* The operations prototyped in this interface take the number of rows
* and the number of columns in the operand matrix(ces) as arguments.
* The number of rows times that of columns must be within the range
* {1, 2, ..., (2^14)-1}. In the case of binary operations the number
* of rows and columns of the operand matrices must obey the rules of
* matrix algebra; i.e., for matrix addition and subtraction the two
* matrices must have the same number of rows and columns, while for
* matrix multiplication, the number of columns of the first operand
* must be the same as the number of rows of the second operand. The
* source matrix to the inversion operation must be square (the same
* number of rows as of columns), and non-singular (its determinat
* different than zero).
*
* NOTE: no boundary checking is performed by the operations. So forth,
* out of range number of rows or columns as well as the use of source
* matrices not adhering to the previous rules may produce unexpected
* results.
*
* Additional remarks.
*
* A) Operations which return a destination matrix can be nested, so
* that for instance if:
*
* a = Op1 (b, c), with b = Op2 (d), and c = Op3 (e, f), then
*
* a = Op1 (Op2 (d), Op3 (e, f))
*
* B) The computation of the inverse of a matrix takes as input a floating
* point valued matrix, uses floating point arithmentic, and returns a
* floating point valued matrix.
*
* C) All the functions have been designed to operate on matrices allocated
* in default RAM memory space (X-Data and Y-Data).
*
* D) The sum of sizes of the matrix(ces) involved in an operation must not
* exceed the available memory in the target device.
*
****************************************************************************/
/* Matrix operation prototypes. */
extern fractional* MatrixScale ( /* Matrix scale */
/* dstM[i][j] = sclVal*srcM[i][j] */
/* (in place capable) */
int numRows, /* number rows in srcM (R) */
int numCols, /* number columns in srcM (C) */
fractional* dstM, /* ptr to destination matrix */
fractional* srcM, /* ptr to source matrix */
fractional sclVal /* scale value (Q.15 fractional) */
/* dstM returned */
);
/*...........................................................................*/
extern fractional* MatrixTranspose ( /* Matrix transpose */
/* dstM[i][j] = srcM[j][i] */
/* (in place capable) */
int numRows, /* number rows in srcM (R) */
int numCols, /* number columns in srcM (C) */
fractional* dstM, /* ptr to destination matrix */
fractional* srcM /* ptr to source matrix */
/* dstM returned */
);
/*...........................................................................*/
float* MatrixInvert ( /* Matrix inverse */
/* dstM = srcM^(-1) */
/* (in place capable) */
int numRowsCols, /* number rows and columns in matrix */
/* matrix MUST be square */
float* dstM, /* ptr to destination matrix */
float* srcM, /* ptr to source matrix */
float* pivotFlag, /* internal use; size numRowsCols */
int* swappedRows, /* internal use; size numRowsCols */
int* swappedCols /* internal use; size numRowsCols */
/* last three vectors required from */
/* user, so that function is not */
/* responsible for memory management */
/* dstM returned (or NULL on error */
/* if source matrix is singular) */
);
/*...........................................................................*/
extern fractional* MatrixAdd ( /* Matrix addition */
/* dstM[i][j] = */
/* srcM1[i][j] + srcM2[i][j] */
/* (in place capable) */
/* (with itself capable) */
int numRows, /* number rows in srcM[1,2] (R) */
int numCols, /* number columns in srcM[1,2] (C) */
fractional* dstM, /* ptr to destination matrix */
fractional* srcM1, /* ptr to source one matrix */
fractional* srcM2 /* ptr to source two matrix */
/* dstM returned */
);
/*...........................................................................*/
extern fractional* MatrixSubtract ( /* Matrix subtraction */
/* dstM[i][j] = */
/* srcM1[i][j] - srcM2[i][j] */
/* (in place capable) */
/* (with itself capable) */
int numRows, /* number rows in srcM[1,2] (R) */
int numCols, /* number columns in srcM[1,2] (C) */
fractional* dstM, /* ptr to destination matrix */
fractional* srcM1, /* ptr to source one matrix */
fractional* srcM2 /* ptr to source two matrix */
/* dstM returned */
);
/*...........................................................................*/
extern fractional* MatrixMultiply ( /* Matrix multiplication */
/* dstM[i][j] = */
/* sum_k(srcM1[i][k]*srcM2[k][j]) */
/* i in {0, 1, ..., numRows1-1} */
/* j in {0, 1, ..., numCols2-1} */
/* k in {0, 1, ..., numCols1Rows2-1} */
/* (in place capable, only square) */
/* (with itself capable, only square) */
int numRows1, /* number rows in srcM1 */
int numCols1Rows2, /* number columns in srcM1, same as */
/* number rows in srcM2 */
int numCols2, /* number columns srcM2 */
fractional* dstM, /* ptr to destination matrix */
fractional* srcM1, /* ptr to source one matrix */
fractional* srcM2 /* ptr to source two matrix */
/* dstM returned */
);
/*...........................................................................*/
/****************************************************************************
*
* Interface to FIR filter operations.
*
* Filtering a data sequence x[n] with an FIR filter of impulse response
* b[m] (0<= m < M) is equivalent to solving the difference equation:
*
* y[n] = sum_{m = 0:M-1}(b[m]*x[n-m])
*
* In this operation it is important to know and manage the past history
* of the data sequence (x[m], -M+1 <= m < 0) which represent the initial
* condition of the filtering operation. Also, when applying an FIR filter
* to contiguous sections of a data sequence it is necessary to remember
* the final state of the previous filtering operation (x[m], N-M+1 <= m < N-1),
* and take the state into consideration for the calculations of the next
* filtering stage. Accounting for the past history and current state is
* required to perform a correct (glitch-free) filtering operation.
*
* The management of the past history and current state of the filtering
* operation is commonly implemented via an additional sequence, referred
* to as the delay. Prior to a filtering operation the delay describes the
* past history of the data sequence. After performing the FIR filtering
* the delay contains a set of the most recently filtered data samples.
* (For correct operation, it is advisable to initialize the delay values
* to zero by calling the corresponding init function.)
*
* Even though FIR filtering is a difference equation, several properties
* of FIR filters allow for computation of the operation in more effective
* ways than that of a straight difference equation. Consequently, a set
* of such implementations are hereby provided.
*
* Note that of the four main sequences involved in FIR filtering, input
* data, output data, filter coefficients and delay, the last two are
* usually thought of as making up the filter structure. All the functions
* that follow use the same FIR filter structure to manage the filtering
* operation.
*
* In the current design, the input data sequence is referred to as the
* sequence of source samples, while the resulting filtered sequence
* contains the destination samples. The filters are characterized by
* the number of coefficients or taps, and the delay properties. All of
* these data sets are stored in memory as vectors with their elements
* representing Q.15 fractional quantities. Also, the input and output
* sequences to the filtering operation ought to be allocated in default
* RAM memory (X-Data or Y-Data). The coefficients may be allocated either
* in X-Data or program memory, while the delays must be allocated solely
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -