kopia lustrzana https://github.com/Dsplib/libdspl-2.0
616 wiersze
15 KiB
Plaintext
616 wiersze
15 KiB
Plaintext
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int butter_ap(double Rp, int ord, double* b, double* a)
|
|
|
|
\brief
|
|
Function calculates the transfer function \f$ H(s) \f$ coefficients of
|
|
analog normalized lowpass Butterworth filter.
|
|
|
|
Analog normalized lowpass filter magnitude ripple equals \f$ -R_p \f$ dB
|
|
for angular frequency \f$ \omega \f$ from 0 to 1 rad/s.
|
|
|
|
\param[in] Rp
|
|
Magnitude ripple in passband (dB). \n
|
|
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Filter coefficients number equals `ord+1` for numerator and denominator
|
|
of transfer function \f$ H(s) \f$ \n
|
|
\n
|
|
|
|
\param[out] b
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
numerator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] a
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
denominator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if filter coefficients is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
Example:
|
|
|
|
\include butter_ap_test.c
|
|
|
|
Result:
|
|
|
|
\verbatim
|
|
b[ 0] = 1.002 a[ 0] = 1.002
|
|
b[ 1] = 0.000 a[ 1] = 2.618
|
|
b[ 2] = 0.000 a[ 2] = 3.418
|
|
b[ 3] = 0.000 a[ 3] = 2.615
|
|
b[ 4] = 0.000 a[ 4] = 1.000
|
|
\endverbatim
|
|
\n
|
|
|
|
In `dat` folder will be created 3 files: \n
|
|
|
|
\verbatim
|
|
butter_ap_test_mag.txt magnitude
|
|
butter_ap_test_phi.txt phase response
|
|
butter_ap_test_tau.txt group delay
|
|
\endverbatim
|
|
|
|
In addition, GNUPLOT will build the following graphs from data stored in files:
|
|
|
|
\image html butter_ap_test.png
|
|
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int butter_ap_zp(int ord, double rp, complex_t* z, int* nz,
|
|
complex_t* p, int* np)
|
|
|
|
\brief
|
|
Function calculates arrays of zeros and poles for analog normlized lowpass
|
|
Batterworth filter transfer function \f$ H(s) \f$ order `ord` .
|
|
|
|
Analog normalized lowpass filter magnitude ripple equals \f$ -R_p \f$ dB
|
|
for angular frequency \f$ \omega \f$ from 0 to 1 rad/s.
|
|
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Number of zeros and poles of filter can be less or equal `ord`. \n
|
|
\n
|
|
|
|
\param[in] rp
|
|
Magnitude ripple in passband (dB). \n
|
|
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[out] z
|
|
Pointer to the \f$ H(s) \f$ zeros array. \n
|
|
Maximum vector size is `[ord x 1]`. \n
|
|
Memory must be allocated for maximum vector size. \n
|
|
\n
|
|
|
|
\param[out] nz
|
|
Pointer to the variable which keep number of finite zeros \f$ H(s) \f$. \n
|
|
Number of finite zeros which was calculated and saved in vector `z`. \n
|
|
Pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\param[out] p
|
|
Pointer to the \f$ H(s) \f$ poles array. \n
|
|
Maximum vector size is `[ord x 1]`. \n
|
|
Memory must be allocated for maximum vector size. \n
|
|
\n
|
|
|
|
\param[out] np
|
|
Pointer to the variable which keep number of
|
|
calculated poles of \f$ H(s) \f$. \n
|
|
Pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if zeros and poles is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
\note
|
|
Normalized Butterworth lowpass filter has no finite zeros.
|
|
So `z` vector will not changed and in pointer `nz` will write 0 value. \n
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int cheby1_ap(double Rp, int ord, double* b, double* a)
|
|
|
|
\brief
|
|
Function calculates the transfer function \f$ H(s) \f$ coefficients of
|
|
analog normalized lowpass Chebyshev type 1 filter.
|
|
|
|
Analog normalized lowpass filter magnitude ripple equals \f$ -R_p \f$ dB
|
|
for angular frequency \f$ \omega \f$ from 0 to 1 rad/s.
|
|
|
|
\param[in] Rp
|
|
Magnitude ripple in passband (dB). \n
|
|
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Filter coefficients number equals `ord+1` for numerator and denominator
|
|
of transfer function \f$ H(s) \f$ \n
|
|
\n
|
|
|
|
\param[out] b
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
numerator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] a
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
denominator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if filter coefficients is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
Example:
|
|
|
|
\include cheby1_ap_test.c
|
|
|
|
Result:
|
|
|
|
\verbatim
|
|
b[ 0] = 0.125 a[ 0] = 0.177
|
|
b[ 1] = 0.000 a[ 1] = 0.405
|
|
b[ 2] = 0.000 a[ 2] = 1.169
|
|
b[ 3] = 0.000 a[ 3] = 0.582
|
|
b[ 4] = 0.000 a[ 4] = 1.000
|
|
\endverbatim
|
|
\n
|
|
|
|
In `dat` folder will be created 3 files: \n
|
|
|
|
\verbatim
|
|
cheby1_ap_test_mag.txt magnitude
|
|
cheby1_ap_test_phi.txt phase response
|
|
cheby1_ap_test_tau.txt group delay
|
|
\endverbatim
|
|
|
|
In addition, GNUPLOT will build the following graphs from data stored in files:
|
|
|
|
\image html cheby1_ap_test.png
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int cheby1_ap_zp( int ord, double rp, complex_t *z, int* nz,
|
|
complex_t* p, int* np)
|
|
\brief
|
|
Function calculates arrays of zeros and poles for analog normlized lowpass
|
|
Chebyshev type 1 filter transfer function \f$ H(s) \f$ order `ord` .
|
|
|
|
Analog normalized lowpass filter magnitude ripple equals \f$ -R_p \f$ dB
|
|
for angular frequency \f$ \omega \f$ from 0 to 1 rad/s.
|
|
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Number of zeros and poles of filter can be less or equal `ord`. \n
|
|
\n
|
|
|
|
\param[in] rp
|
|
Magnitude ripple in passband (dB). \n
|
|
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[out] z
|
|
Pointer to the \f$ H(s) \f$ zeros array. \n
|
|
Maximum vector size is `[ord x 1]`. \n
|
|
Memory must be allocated for maximum vector size. \n
|
|
\n
|
|
|
|
\param[out] nz
|
|
Pointer to the variable which keep number of finite zeros \f$ H(s) \f$. \n
|
|
Number of finite zeros which was calculated and saved in vector `z`. \n
|
|
Pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\param[out] p
|
|
Pointer to the \f$ H(s) \f$ poles array. \n
|
|
Maximum vector size is `[ord x 1]`. \n
|
|
Memory must be allocated for maximum vector size. \n
|
|
\n
|
|
|
|
\param[out] np
|
|
Pointer to the variable which keep number of
|
|
calculated poles of \f$ H(s) \f$. \n
|
|
Pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if zeros and poles is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
\note
|
|
Normalized Chebyshev type 1 lowpass filter has no finite zeros.
|
|
So `z` vector will not changed and in pointer `nz` will write 0 value. \n
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int cheby2_ap(double Rs, int ord, double *b, double *a)
|
|
|
|
\brief
|
|
Function calculates the transfer function \f$ H(s) \f$ coefficients of
|
|
analog normalized lowpass Chebyshev type 2 filter.
|
|
|
|
Analog normalized Chebyshev type 2 filter lowpass filter has \f$Rs\f$ dB
|
|
suppression in stopband.
|
|
Also analog normalized Chebyshev type 2 filter magnitude equals \f$-Rs\f$ dB
|
|
for angular frequency \f$\omega = 1\f$ rad/s.
|
|
|
|
\param[in] Rs
|
|
Suppression level in stopband (dB). \n
|
|
This parameter sets filter supression for \f$\omega \geq 1\f$ rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Filter coefficients number equals `ord+1` for numerator and denominator
|
|
of transfer function \f$ H(s) \f$ \n
|
|
\n
|
|
|
|
\param[out] b
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
numerator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] a
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
denominator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if filter coefficients is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
Example:
|
|
|
|
\include cheby2_ap_test.c
|
|
|
|
Result:
|
|
|
|
\verbatim
|
|
b[ 0] = 0.008 a[ 0] = 0.008
|
|
b[ 1] = 0.000 a[ 1] = 0.068
|
|
b[ 2] = 0.008 a[ 2] = 0.300
|
|
b[ 3] = 0.000 a[ 3] = 0.774
|
|
b[ 4] = 0.001 a[ 4] = 1.000
|
|
\endverbatim
|
|
\n
|
|
|
|
In `dat` folder will be created 3 files: \n
|
|
|
|
\verbatim
|
|
cheby2_ap_test_mag.txt magnitude
|
|
cheby2_ap_test_phi.txt phase response
|
|
cheby2_ap_test_tau.txt group delay
|
|
\endverbatim
|
|
|
|
In addition, GNUPLOT will build the following graphs from data stored in files:
|
|
|
|
\image html cheby2_ap_test.png
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int cheby2_ap_zp(int ord, double rs, complex_t* z, int* nz,
|
|
complex_t* p, int* np)
|
|
|
|
\brief
|
|
Function calculates arrays of zeros and poles for analog normlized lowpass
|
|
Chebyshev type 2 filter transfer function \f$ H(s) \f$ order `ord` .
|
|
|
|
Analog normalized Chebyshev type 2 filter lowpass filter has \f$Rs\f$ dB
|
|
suppression in stopband.
|
|
Also analog normalized Chebyshev type 2 filter magnitude equals \f$-Rs\f$ dB
|
|
for angular frequency \f$\omega = 1\f$ rad/s.
|
|
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Number of zeros and poles of filter can be less or equal `ord`. \n
|
|
\n
|
|
|
|
\param[in] rs
|
|
Suppression level in stopband (dB). \n
|
|
This parameter sets filter supression for \f$\omega \geq 1\f$ rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[out] z
|
|
Pointer to the \f$ H(s) \f$ zeros array. \n
|
|
Maximum vector size is `[ord x 1]`. \n
|
|
Memory must be allocated for maximum vector size. \n
|
|
\n
|
|
|
|
\param[out] nz
|
|
Pointer to the variable which keep number of finite zeros \f$ H(s) \f$. \n
|
|
Number of finite zeros which was calculated and saved in vector `z`. \n
|
|
Pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\param[out] p
|
|
Pointer to the \f$ H(s) \f$ poles array. \n
|
|
Maximum vector size is `[ord x 1]`. \n
|
|
Memory must be allocated for maximum vector size. \n
|
|
\n
|
|
|
|
\param[out] np
|
|
Pointer to the variable which keep number of
|
|
calculated poles of \f$ H(s) \f$. \n
|
|
Pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if zeros and poles is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
Example:
|
|
|
|
\include cheby2_ap_zp_test.c
|
|
|
|
Result:
|
|
|
|
\verbatim
|
|
Chebyshev type 2 zeros:
|
|
z[ 0] = 0.000 1.026 j
|
|
z[ 1] = 0.000 -1.026 j
|
|
z[ 2] = 0.000 1.279 j
|
|
z[ 3] = 0.000 -1.279 j
|
|
z[ 4] = 0.000 2.305 j
|
|
z[ 5] = 0.000 -2.305 j
|
|
|
|
Chebyshev type 2 poles:
|
|
p[ 0] = -1.203 0.000 j
|
|
p[ 1] = -0.113 0.772 j
|
|
p[ 2] = -0.113 -0.772 j
|
|
p[ 3] = -0.398 0.781 j
|
|
p[ 4] = -0.398 -0.781 j
|
|
p[ 5] = -0.852 0.642 j
|
|
p[ 6] = -0.852 -0.642 j
|
|
\endverbatim
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int ellip_ap(double rp, double rs, int ord, double* b, double* a)
|
|
|
|
\brief
|
|
Function calculates the transfer function \f$ H(s) \f$ coefficients of
|
|
analog normalized lowpass elliptic filter order `ord` with passband ripple
|
|
`rp` dB and stopband suppression equals `rs` dB.
|
|
|
|
\param[in] rp
|
|
Magnitude ripple in passband (dB). \n
|
|
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
|
|
\param[in] rs
|
|
Suppression level in stopband (dB). \n
|
|
This parameter sets filter supression for \f$\omega \geq 1\f$ rad/s frequency. \n
|
|
Parameter must be positive. \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Filter coefficients number equals `ord+1` for numerator and denominator
|
|
of transfer function \f$ H(s) \f$ \n
|
|
\n
|
|
|
|
\param[out] b
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
numerator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] a
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
denominator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if filter coefficients is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
Example:
|
|
|
|
\include ellip_ap_test.c
|
|
|
|
Result:
|
|
|
|
\verbatim
|
|
b[ 0] = 0.268 a[ 0] = 0.301
|
|
b[ 1] = 0.000 a[ 1] = 0.764
|
|
b[ 2] = 0.045 a[ 2] = 1.472
|
|
b[ 3] = 0.000 a[ 3] = 0.948
|
|
b[ 4] = 0.001 a[ 4] = 1.000
|
|
\endverbatim
|
|
\n
|
|
|
|
In `dat` folder will be created 3 files: \n
|
|
|
|
\verbatim
|
|
ellip_ap_test_mag.txt magnitude
|
|
ellip_ap_test_phi.txt phase response
|
|
ellip_ap_test_tau.txt group delay
|
|
\endverbatim
|
|
|
|
In addition, GNUPLOT will build the following graphs from data stored in files:
|
|
|
|
\image html ellip_ap_test.png
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int filter_zp2ab(complex_t *z, int nz, complex_t *p, int np, int ord,
|
|
double* b, double* a)
|
|
\brief
|
|
Function recalculates complex zeros and poles of transfer function \f$ H(s) \f$
|
|
to the coefficients of \f$ H(s) \f$ numerator and denominator polynomials.
|
|
|
|
Transfer function can we described as:
|
|
\f[
|
|
H(s) =
|
|
\frac{\sum\limits_{n = 0}^{N_z} b_n s^n}{\sum\limits_{m = 0}^{N_p} a_m s^m} =
|
|
\frac{\prod\limits_{n = 0}^{N_z}(s-z_n)}{\prod\limits_{m = 0}^{N_p} (s-p_m)}
|
|
\f]
|
|
|
|
\param[in] z
|
|
Pointer to the vector of transfer function zeros. \n
|
|
Vector size is `[nz x 1]`. \n
|
|
Pointer can be `NULL` if filter has no finite zeros (`nz=0`). \n
|
|
\n
|
|
|
|
\param[in] nz
|
|
Number of fitite zeros (can be zero). \n
|
|
\n
|
|
|
|
\param[in] p
|
|
Pointer to the vector of transfer function poles. \n
|
|
Vector size is `[np x 1]`. \n
|
|
This pointer cannot be `NULL`. \n
|
|
\n
|
|
|
|
\param[in] np
|
|
Size of vector of transfer function poles (`p` vector size). \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Number of \f$H(s)\f$ numerator and denominator coefficients equals `ord+1`. \n
|
|
\n
|
|
|
|
\param[out] b
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
numerator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] a
|
|
Pointer to the vector of transfer function \f$H(s)\f$
|
|
denominator coefficient. \n
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if filter coefficients is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
\n
|
|
|
|
\note
|
|
Function calculates real `b` and `a` coefficients of \f$H(s)\f$.
|
|
It means that zeros and poles vectors must have real values or conjugate pairs
|
|
to get zeros image part of `b` and `a` coefficients. This function ignores
|
|
image part of `b` and `a` coeeffitients if the requirements for zeros
|
|
and poles are not fulfilled.
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|