⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsp.h

📁 PID算法的介绍和应用,在很多场合需要,详细的事例说明
💻 H
📖 第 1 页 / 共 5 页
字号:

/* ....................................................................... */

/****************************************************************************
*
* Interface to IIR filter operations.
*
* Filtering a data sequence x[n] with an IIR filter of impulse response
* {b[m] (0<= m < M), a[p] (0 <= p < P)} is equivalent to solving the
* difference equation:
*
*       sum_{p = 0:P-1}(a[p]*y[n-p]) = 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 input and output data sequences (x[m], -M+1 <= m < 0, and y[p],
* -P+1 <= p < 0) which represent the initial conditions of the filtering
* operation. Also, when applying an IIR filter to contiguous sections of
* a data sequence it is necessary to remember the final state of the
* last filtering operation (x[m], N-M+1 <= m < N-1, and y[p], N-P+1 <= p < 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 additional sequences, referred
* to as the delays. Prior to a filtering operation the delays describe the
* past history of the filter. After performing the IIR filtering operation
* the delays contain a set of the most recently filtered data samples, and
* of the most recent output samples. (For correct operation, it is advisable
* to initialize the delay values to zero by calling the corresponding init
* function.)
*
* Even though IIR filtering is a difference equation, several properties
* of IIR 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 six main sequences involved in IIR filtering, input
* data, output data, filter coefficients (a,b) and delays, the last four
* are usually thought of as making up the filter structure. However, since
* different implementations allow for particular arrangaments of the filter
* structure for efficiency gain, the structure has not been standardized,
* but rather taylored to best fit the particular implementations.
*
* 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 in the 'a' and 'b' sets, and the
* delay properties. All of these data sets are stored in memory as
* vectors with their elements representing Q.15 fractional quantities.
* Also, except for the 'IIRLattice' and associated 'IIRLatticeStruct'
* implementations, the filters are made up of cascaded second order
* sections. In all cases, the input, output and coefficient vectors
* are allocated in default RAM memory space (X-Data and Y-Data). The
* coefficients may be allocated in either X-Data or program memory,
* while the delays ought to be in Y-Data.
*
****************************************************************************/

/* IIR filter operation prototypes. */


typedef struct {
  int numSectionsLess1;                 /* 1 less than number of cascaded */
                                        /* second order sections */
  fractional* coeffsBase;               /* ptr to filter coefficients */
                                        /* either in X-Data or P-MEM */
                                        /* number of coefficients is */
                                        /* 5*number of second order sections */
                                        /* {a2,a1,b2,b1,b0} per section */
  int coeffsPage;                       /* page number of program memory if */
                                        /* coefficients are in program memory */
                                        /* COEFFS_IN_DATA if not */
  fractional* delayBase;                /* ptr to filter delay */
                                        /* two words for every section */
                                        /* only in Y-Data */
  fractional initialGain;               /* initial gain value */
  int finalShift;                       /* output scaling (shift left) */
                                        /* restores filter gain to 0 dB */
                                        /* shift count may be zero, if not */
                                        /* zero, it is the number of bits */
                                        /* to shift output: negative means */
                                        /* shift to the left, positive is */
                                        /* shift right */
} IIRCanonicStruct;     /* Direct Form II Canonic biquad filter structure */

extern fractional* IIRCanonic (         /* Direct Form II (Canonic) */
                                        /* biquad filtering */
   int numSamps,                        /* number of input samples (N) */
   fractional* dstSamps,                /* ptr to output samples */
                                        /* (y[n], 0 <= n < N) */
   fractional* srcSamps,                /* ptr to input samples */
                                        /* (x[n], 0 <= n < N) */
   IIRCanonicStruct* filter             /* filter structure */

                                        /* returns dstSamps */
);

extern void IIRCanonicInit (            /* Initialize filter structure */
   IIRCanonicStruct* filter             /* Canonic biquad filter structure */
);

/* ....................................................................... */

typedef struct {
  int numSectionsLess1;                 /* 1 less than number of cascaded */
                                        /* second order sections */
  fractional* coeffsBase;               /* ptr to filter coefficients */
                                        /* either in X-Data or P-MEM */
                                        /* number of coefficients is */
                                        /* 5*number of second order sections */
                                        /* {b0,b1,a1,b2,a2} per section */
  int coeffsPage;                       /* page number of program memory if */
                                        /* coefficients are in program memory */
                                        /* COEFFS_IN_DATA if not */
  fractional* delayBase1;               /* ptr to state variable (delay) 1 */
                                        /* one word for every section */
                                        /* only in Y-Data */
  fractional* delayBase2;               /* ptr to state variable (delay) 2 */
                                        /* one word for every section */
                                        /* only in Y-Data */
  int finalShift;                       /* output scaling (shift left) */
                                        /* restores filter gain to 0 dB */
                                        /* shift count may be zero, if not */
                                        /* zero, it is the number of bits */
                                        /* to shift the output to the left */
                                        /* negative value means shift right */
} IIRTransposedStruct;  /* Transposed Direct Form II biquad filter structure */

extern fractional* IIRTransposed (      /* Direct Form II (Transposed) */
                                        /* biquad filtering */
   int numSamps,                        /* number of input samples (N) */
   fractional* dstSamps,                /* ptr to output samples */
                                        /* (y[n], 0 <= n < N) */
   fractional* srcSamps,                /* ptr to input samples */
                                        /* (x[n], 0 <= n < N) */
   IIRTransposedStruct* filter          /* Transposed biquad filter structure */

                                        /* returns dstSamps */
);

extern void IIRTransposedInit (         /* Initialize filter structure */
   IIRTransposedStruct* filter          /* Transposed biquad filter structure */
);

/* ....................................................................... */

typedef struct {
   int order;                           /* filter order (M) */
                                        /* M <= N (see IIRLattice for N) */
   fractional* kappaVals;               /* ptr to lattice coefficients */
                                        /* (k[m], 0 <= m <= M) */
                                        /* either in X-Data or P-MEM */
   fractional* gammaVals;               /* ptr to ladder coeficients */
                                        /* (g[m], 0 <= m <= M) */
                                        /* either in X-Data or P-MEM */
                                        /* NULL for all pole implementation */
   int coeffsPage;                      /* page number of program memory if */
                                        /* coefficients are in program memory */
                                        /* COEFFS_IN_DATA if not */
   fractional* delay;                   /* ptr to delay */
                                        /* (d[m], 0 <= m <= M) */
                                        /* only in Y-Data */
} IIRLatticeStruct;                     /* IIR Lattice filter structure */

extern fractional* IIRLattice (         /* IIR Lattice filtering */
   int numSamps,                        /* number of input samples (N) */
   fractional* dstSamps,                /* ptr to output samples */
                                        /* (y[n], 0 <= n < N) */
   fractional* srcSamps,                /* ptr to input samples */
                                        /* (x[n], 0 <= n < N) */
   IIRLatticeStruct* filter             /* filter structure */

                                        /* returns dstSamps */
);

extern void IIRLatticeInit (            /* Zero out dealy in filter structure */
   IIRLatticeStruct* filter             /* Lattice filter structure */
);

/* ....................................................................... */

/****************************************************************************
*
* Interface to transform operations.
*
* A set of linear discrete signal transformations (and some of the inverse
* transforms) are prototyped below. The first set applies a Discrete Fourier
* transform (or its inverse) to a complex data set. The second set applies
* a Type II Discrete Cosine Transform (DCT) to a real valued sequence.
*
* A complex valued sequence is represented by a vector in which every pair
* of values corresponds with a sequence element. The first value in the pair
* is the real part of the element, and the second its imaginary part (see
* the declaration of the 'fractcomplex' structure at the beginning of this
* file for further details). Both, the real and imaginary parts, are stored
* in memory using one word (two bytes) each, and must be interpreted as Q.15
* fractionals.
*
* The following transforms have been designed to either operate out-of-place,
* or in-place. The former type populates an output sequence with the results
* of the transformation. In the latter, the input sequence is (physically)
* replaced by the transformed sequence. For out-of-place operations, the user
* must provide with enough memory to accept the results of the computation.
* The input and output sequences to the FFT family of transforms must be
* allocated in Y-Data memopry.
*
* The transforms here described make use of transform factors which must be
* supplied to the transforming function during its invokation. These factors,
* which are complex data sets, are computed in floating point arithmetic,
* and then transformed into fractionals for use by the operations. To avoid
* excessive overhead when applying a transformation, and since for a given
* transform size the values of the factors are fixed, a particular set of
* transform factors could be generated once and used many times during the
* execution of the program. Thus, it is advisable to store the factors
* returned by any of the initialization operations in a permanent (static)
* vector. The factors to a transform may be allocated either in X-Data or
* program memory.
*
* Additional remarks.
*
* A) Operations which return a destination vector 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))
*
****************************************************************************/

/* Transform operation prototypes. */


extern fractcomplex* TwidFactorInit (   /* Initialize twiddle factors */
                                        /* WN(k) = exp(i*2*pi*k/N) */
                                        /* computed in floating point */
                                        /* converted to fractionals */
   int log2N,                           /* log2(N), N complex factors */
                                        /* (although only N/2 are computed */
                                        /* since only half of twiddle factors */
                                        /* are used for I/FFT computation) */
   fractcomplex* twidFactors,           /* ptr to twiddle factors */
   int conjFlag                         /* indicates whether to generate */
                                        /* complex conjugates of twiddles */
                                        /* 0 : no conjugates (default) */
                                        /* 1 : conjug

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -