Main Content

getNumStages

Get number of stages in digital filter cascade

Since R2026a

    Description

    n = getNumStages(d) returns the number of stages in a digital filter cascade d.

    example

    Examples

    collapse all

    Get the number of stages and CTF sections of a lowpass filter, a bandstop filter, and a lowpass-bandstop cascaded filter.

    Design two digital filters with these specifications:

    • A lowpass IIR filter with passband and stopband frequencies of 0.65π rad/sample and 0.80π rad/sample, respectively. The passband ripple is 1 dB and the stopband attenuation is 50 dB.

    • A bandstop IIR filter with passband ripples of 1 dB and stopband attenuation of 50 dB. The passband frequencies are 0.25π rad/sample and 0.34π rad/sample. The stopband frequencies are 0.36π rad/sample and 0.45π rad/sample.

    d1 = designfilt("lowpassiir", ...
        PassbandFrequency=0.65,StopbandFrequency=0.80, ...
        PassbandRipple=1,StopbandAttenuation=50);
    d2 = designfilt("bandstopiir", ...
        PassbandFrequency1=0.25,StopbandFrequency1=0.34, ...
        StopbandFrequency2=0.36,PassbandFrequency2=0.45, ...
        PassbandRipple1=1,StopbandAttenuation=50, ...
        PassbandRipple2=1);

    Cascade the lowpass IIR and bandstop IIR filters to form a single cascaded filter. Calculate the number of stages and CTF sections. The cascaded filter has two stages and 10 CTF sections.

    d3 = cascade(d1,d2)
    d3 = 
     digitalFilter cascade with properties:
    
       Stages:
                     Stage1: [1×1 digitalFilter]
                     Stage2: [1×1 digitalFilter]
    
       Specifications:
        NormalizedFrequency: 1
    
     Use filterAnalyzer to visualize filter
     Use filter to filter data
    
    
    numStages3 = getNumStages(d3)
    numStages3 = 
    2
    
    [B3,A3] = ctf(d3);
    numCTFsections3 = size(B3,1)
    numCTFsections3 = 
    10
    

    Input Arguments

    collapse all

    Digital filter, specified as a digitalFilter object. Use designfilt to generate a digital filter based on frequency-response specifications.

    Example: d = designfilt("lowpassiir",FilterOrder=3,HalfPowerFrequency=0.5) specifies a third-order Butterworth filter with normalized 3 dB frequency 0.5π rad/sample.

    Output Arguments

    collapse all

    Number of stages in filter, returned as a positive integer.

    Version History

    Introduced in R2026a