kopia lustrzana https://github.com/Dsplib/libdspl-2.0
184 wiersze
4.5 KiB
Plaintext
184 wiersze
4.5 KiB
Plaintext
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int bilinear(double* bs, double* as, int ord, double* bz, double* az)
|
|
|
|
\brief
|
|
Transform a s-plane analog filter transfer function \f$H(s)\f$ to the
|
|
digital filter transfer function \f$H(z)\f$.
|
|
|
|
Bilinear transform is rational composition:
|
|
|
|
\f[
|
|
s \leftarrow \frac{1 - z^{-1}}{1 - z^{-1}}.
|
|
\f]
|
|
|
|
Digital filter order, passband magnitude ripple and stopband suppression
|
|
still the same after bilinear transform as analog filter.
|
|
|
|
Frequency \f$\Omega\f$ of analog filter and frequency
|
|
\f$\omega\f$ of digital filter relations:
|
|
|
|
\f[
|
|
\Omega = \tan(\omega / 2).
|
|
\f]
|
|
|
|
|
|
\param[in] bs
|
|
Pointer to the vector of analog filter \f$H(s)\f$
|
|
numerator coefficients.
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
\n
|
|
|
|
\param[in] as
|
|
Pointer to the vector of analog filter \f$H(s)\f$
|
|
denominator coefficients vector.
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Analog and digital filters order. \n
|
|
\n
|
|
|
|
\param[out] bz
|
|
Pointer to the vector of digital filter \f$H(z)\f$
|
|
numerator coefficients after bilinear transform.
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] az
|
|
Pointer to the vector of digital filter \f$H(z)\f$
|
|
denominator coefficients after bilinear transform.
|
|
Vector size is `[ord+1 x 1]`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if bilinear transform is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
|
|
|
|
Example:
|
|
|
|
\include bilinear_test.c
|
|
|
|
This program calculates the transfer function \f$H(s)\f$ of analog
|
|
Chebyshev filter of the first kind, with a cutoff frequency of 1 rad/s,
|
|
and produces bilinear trandform to digital filter,
|
|
with a normilized cutoff frequency equals 0.5.
|
|
|
|
Result:
|
|
|
|
\verbatim
|
|
bz[0] = 0.246 az[0] = 4.425
|
|
bz[1] = 0.983 az[1] = -3.318
|
|
bz[2] = 1.474 az[2] = 4.746
|
|
bz[3] = 0.983 az[3] = -2.477
|
|
bz[4] = 0.246 az[4] = 1.034
|
|
err = 0
|
|
\endverbatim
|
|
|
|
In addition, the frequency response of the resulting digital filter
|
|
is calculated and plotted by GNUPLOT package.
|
|
|
|
\image html bilinear.png
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup IIR_FILTER_DESIGN_GROUP
|
|
\fn int iir(double rp, double rs, int ord, double w0, double w1,
|
|
int type, double* b, double* a)
|
|
\brief
|
|
Digital IIR filter design.
|
|
|
|
The function calculates the coefficients of the digital IIR filter
|
|
transfer fucntion \f$ H(z) \f$.
|
|
Filter coeffitients can be used in \ref filter_iir function
|
|
|
|
\param[in] rp
|
|
Magnitude ripple in passband (dB). \n
|
|
\n
|
|
|
|
|
|
\param[in] rs
|
|
Suppression level in stopband (dB). \n
|
|
\n
|
|
|
|
\param[in] ord
|
|
Filter order. \n
|
|
Number of \f$H(z)\f$ numerator and denominator coefficients is `ord+1`. \n
|
|
For bandpass and bandstop filters `ord` must be even. \n
|
|
\n
|
|
|
|
\param[in] w0
|
|
Normalized cutoff frequency (from 0 to 1) for lowpass or highpass filter. \n
|
|
Or left normalized cutoff frequency (from 0 to 1) for
|
|
bandpass and bandstop filter. \n
|
|
\n
|
|
|
|
|
|
\param[in] w1
|
|
Right normalized cutoff frequency (from 0 to 1) for
|
|
bandpass and bandstop filter. \n
|
|
This parameter is ingnored for lowpass and highpass filters.
|
|
\n
|
|
|
|
\param[in] type
|
|
Filter type. \n
|
|
This patameter sets combination of filter type (one of follow): \n
|
|
\verbatim
|
|
DSPL_FILTER_LPF - lowpass filter;
|
|
DSPL_FILTER_HPF - highpass filter;
|
|
DSPL_FILTER_BPASS - bandpass filter;
|
|
DSPL_FILTER_BSTOP - bandstop filter,
|
|
\endverbatim
|
|
and of filter approximation type (one of follow):
|
|
\verbatim
|
|
DSPL_FILTER_BUTTER - Butterworth filter;
|
|
DSPL_FILTER_CHEBY1 - Chebyshev of the first kind filter;
|
|
DSPL_FILTER_CHEBY2 - Chebyshev of the second kind filter;
|
|
DSPL_FILTER_ELLIP - Elliptic filter.
|
|
\endverbatim
|
|
\n
|
|
\n
|
|
|
|
\param[out] b
|
|
Pointer to the transfer function \f$H(z)\f$
|
|
numerator coefficients vector. \n
|
|
Vector size is `ord+1`. \n
|
|
Memory must be allocated. \n
|
|
\n
|
|
|
|
\param[out] a
|
|
Pointer to the transfer function \f$H(z)\f$
|
|
denominator coefficients vector. \n
|
|
Vector size is `ord+1`. \n
|
|
\n
|
|
|
|
\return
|
|
`RES_OK` if filter is calculated successfully. \n
|
|
Else \ref ERROR_CODE_GROUP "code error".
|
|
|
|
Example:
|
|
|
|
\include iir_test.c
|
|
|
|
This program calcultes filter coefficients for different flags `type`.
|
|
|
|
In addition, the filters magnitudes
|
|
is calculated and plotted by GNUPLOT package.
|
|
|
|
\image html iir_test.png
|
|
|
|
\author Sergey Bakhurin www.dsplib.org
|
|
***************************************************************************** */ |