2.1.22.3.10 ocmsp_iir_filter_zp


Description

Design digital or analog IIR filters with given specifications. It returns the zeros, poles and the gain:


H(z) = k \frac{(z-z_0)*(z-z_1)*...*(z-z_{n-1})}{(z-p_0)*(z-p_1)*...*(z-p_{n-1})}

Syntax

int ocmsp_iir_filter_zp( UINT N, double Wn, d_complex * pZ, d_complex * pP, double * pk, 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/second if is analog type, and should be normalized to [0, 1] if is digital type (where 1 corresponds to half the sample rate)
pZ
[output] returned zeros, size N
pP
[output] returned poles, size N
pk
[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_zp_ex1()
{
    UINT N = 18; //even number if bandpass or bandstop
    double Wn[2] = {300.0/500, 400.0/500};
    vector<complex> zeros(N), poles(N); //size N
    double gain;
    int type = OMSP_BUTTERWORTH|OMSP_BANDPASS|OMSP_DIGITAL;
 
    int nRet = 0;
    if (0 != (nRet = ocmsp_iir_filter_zp(N, Wn[0], zeros, poles, &gain, type, 0.0, 0.0, Wn[1])))
    {
        printf("ocmsp_iir_filter_zp failed, error code=%d\n", nRet);
        return;
    }
 
    int ii;
    printf("zeros= ");
    for(ii = 0; ii < zeros.GetSize(); ++ii)
    {
		printf("\t%lf %lf\n", zeros[ii].m_re, zeros[ii].m_im);
    }
    printf("poles= ");
    for(ii = 0; ii < poles.GetSize(); ++ii)
    {
		printf("\t%lf %lf\n", poles[ii].m_re, poles[ii].m_im);
    }
}

Remark

See Also

ocmsp_iir_filter, ocmsp_iir_filter_sos, ocmsp_iir_filter_ss

Header to Included

ocmsp.h

Reference