2.1.22.3.11 ocmsp_iir_order


Description

Estimate the minimum order of a digital/analog IIR filter required to meet a set of filter design specifications: loses no more than Rp dB in passband and has at least Rs dB of attenuation in the stopband.

Syntax

int ocmsp_iir_order( UINT * pN, double * pWn, double Wp, double Ws, double Rp, double Rs, int type, double * pWn2 = NULL, double Wp2 = -1.0, double Ws2 = -1.0 )

Parameters

pN
[output] returned lowest order N
pWn
[output] natural frequency of the filter, for filter design with ocmsp_IIR_filter
Wp
[input] passband edge frequency, it's in radians/second if is analog type, and should be normalized to [0, 1] if is digital (where 1 corresponds to pi radians/sample)
Ws
[input] stopband edge frequency, it's in radians/second if is analog type, and should be normalized to [0, 1] if is digital(where 1 corresponds to pi radians/sample)
Rp
[input] passband ripple in dB. It's the maximum permissible passband loss in decibels
Rs
[input] stopband attenuation in dB. It's the number of decibels the stopband is down from the passband
type
[input] filter type. It specifies the filter prototype(Butterworth, Chebyshev Type I, Chebyshev Type II, Elliptic or Bessel), band type (lowpass, highpass, bandstop or bandpass) and digital or analog type. For example
OMSP_BUTTERWORTH|OMSP_LOWPASS|OMSP_DIGITAL means a lowpass Butterworth digital filter.
pWn2
[output] natural frequency 2, only needed when it's a bandpass or bandstop filter
Wp2
[input][optional] passband edge frequency, it's in radians/second if is analog type, and should be normalized to [0, 1] if is digital (where 1 corresponds to pi radians/sample). Only needed when it's a bandpass or bandstop filter
Ws2
[input][optional] stopband edge frequency, it's in radians/second if is analog type, and should be normalized to [0, 1] if is digital(where 1 corresponds to pi radians/sample). Only needed when it's a bandpass or bandstop filter
The stopband and passband frequency range should follow:
Filter Type Stopband/Passband conditions Stopband Passband
Lowpass Wp < Ws (Ws, 1) (0, Wp)
Highpass Wp > Ws (0, Ws) (Wp, 1)
Bandpass Ws < Wp < Wp2 < Ws2 (0, Ws) and (Ws2, 1) (Wp, Wp2)
Bandstop Wp < Ws < Ws2 < Wp2 (0, Wp) and (Wp2, 1) (Ws, Ws2)

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_order_ex1()
{
    int type = OMSP_BUTTERWORTH|OMSP_BANDPASS|OMSP_DIGITAL;
    double Wn[2] = {0.0, 0.0}, Wp[2] = {60.0/500, 200.0/500}, Ws[2] = {50.0/500, 250.0/500};
    double Rp = 3, Rs = 40;
    UINT N = 0;

    int nRet = 0;
    if (0 != (nRet = ocmsp_iir_order(&N, &Wn[0], Wp[0], Ws[0], Rp, Rs, type, &Wn[1], Wp[1], Ws[1])))
    {
        printf("ocmsp_iir_order failed, error code=%d\n", nRet);
        return;
    }

    printf("N = %d, Wn = [%lf, %lf]\n", N, Wn[0], Wn[1]);
}

Remark

See Also

Header to Included

ocmsp.h

Reference