ocmsp_iir_filter_sos
Description
Design digital or analog IIR filters with given specifications. It returns a filter in second-order section representation:
/math-9938360be268587a9883a933c3e62936.png)
The result is saved in an L-by-6 matrix sos, and a scalar gain.
/math-0b28d36649bf0ecb76be9c2c1a6fd2c9.png)
Each row in sos is the numerator and denominator coefficients and of the second order sections of H(z). Section number L is the closest integer greater than or equal to n/2 (L = (n+1)/2).
Syntax
int ocmsp_iir_filter_sos( UINT N, double Wn, double * pSOS, double * pg, int type, double Rp = 0.0, double Rs = 0.0, double Wn2 = -1.0 )
Parameters
- N
- [input] filter order, should be even if is bandpass or bandstop type
- Wn
- [input] cutoff or passband/stopband-edge frequency, it's in radians/s if is analog type, and should be normalized to [0, 1] if is digital type, where 1 corresponds to half the sample rate
- pSOS
- [output] coefficients matrix of second-order sections H(z), size nsec-by-6, nsec = (N+1)/2
- pg
- [output] returned gain, scalar
- type
- [intput] filter type, it specifies the filter prototype(Butterworth, Chebyshev Type I, Chebyshev Type II, Elliptic or Bessel), bandtype(lowpass, highpass, bandstop or bandpass) and digital or analog type. For example
- OMSP_BUTTERWORTH|OMSP_LOWPASS|OMSP_DIGITAL means a lowpass Butterworth digital filter.
- Rp
- [input][optional] passband ripple (dB), needed when it's Chebyshev Type I or Elliptic type
- Rs
- [input][optional] stopband attenuation (dB), needed when it's Chebyshev Type II or Elliptic type
- Wn2
- [input][optional] cutoff or passband/stopband-edge frequency. Needed when it's a bandpass or bandstop
- filter. It's in radians/second if is analog type, and should be normalized to [0, 1] if is digital type (where 1 corresponds to half the sample rate).
Return
Return OE_NOERROR if succeed, otherwise, non-zero error code is returned (OE_NULL_POINTER, OE_INVALID_FREQ, OE_INVALID_BANDFREQS, OE_INVLAID_RIPPLE, OE_INVALID_BANDRIPPLES or OE_INVALID_TYPE)
Examples
EX1
#include <ocmsp.h>
void ocmsp_iir_filter_sos_ex1()
{
UINT N = 18; //even number if bandpass or bandstop
double Wn[2] = {300.0/500, 400.0/500};
UINT nsec = (N+1)/2; //size L = (n+1)/2;
matrix sos(nsec, 6);
double gain;
int type = OMSP_BUTTERWORTH|OMSP_BANDPASS|OMSP_DIGITAL;
int nRet = 0;
if (0 != (nRet = ocmsp_iir_filter_sos(N, Wn[0], sos, &gain, type, 0.0, 0.0, Wn[1])))
{
printf("ocmsp_iir_filter_sos failed, error code=%d\n", nRet);
return;
}
}
Remark
See Also
ocmsp_iir_filter, ocmsp_iir_filter_ss, ocmsp_iir_filter_zp
header to Included
ocmsp.h
Reference
|