Main Content

ctf2sysobj

Create System object from cascaded transfer functions

Since R2025a

    Description

    ctf = ctf2sysobj(Num,Den) creates a System object™ from a cascaded transfer function (CTF) with numerator coefficients Num and denominator coefficients Den.

    example

    ctf = ctf2sysobj(Num,Den,g) also uses the scale values g of a digital filter.

    example

    ctf = ctf2sysobj(___,Name=Value) uses additional options specified in the name-value arguments. Use this syntax with any of the input arguments in previous syntaxes.

    example

    Examples

    collapse all

    Design a sixth-order bandpass elliptic filter. Obtain the numerator and denominator coefficients in CTF format. The size of the filter coefficients matrices indicate three fourth-order sections.

    [Num,Den] = ellip(6,3,50,[0.3 0.6],"bandpass","ctf")
    Num = 3×5
    
        0.2275   -0.0435   -0.1999   -0.0435    0.2275
        0.2275   -0.1070    0.1733   -0.1070    0.2275
        0.2275   -0.1188    0.2423   -0.1188    0.2275
    
    
    Den = 3×5
    
        1.0000   -0.6236    1.6521   -0.5161    0.6936
        1.0000   -0.5779    1.3890   -0.5327    0.8714
        1.0000   -0.5568    1.2684   -0.5468    0.9715
    
    

    Convert the filter in the CTF format to a System object. The ctf2sysobj function returns a dsp.FourthOrderSectionFilter object.

    ctfObj = ctf2sysobj(Num,Den)
    ctfObj = 
      FourthOrderSectionFilter with properties:
    
          Numerator: [3×5 double]
        Denominator: [3×5 double]
    
    

    Visualize the magnitude response of the System object and of the filter representation in numerator and denominator coefficients. Both filter representations give the same magnitude response.

    fa = filterAnalyzer(ctfObj);
    addFilters(fa,Num,Den)

    Define a CTF numerator array for a cascade of two FIR filters of order 100. Convert the cascade of filters to a System object.

    Num = [designLowpassFIR(FilterOrder=100); ...
           designHighpassFIR(FilterOrder=100)];
    
    Hsys = ctf2sysobj(Num)
    Hsys = 
      dsp.FilterCascade with properties:
    
             Stage1: [1×1 dsp.FIRFilter]
             Stage2: [1×1 dsp.FIRFilter]
        CloneStages: true
    
    

    Customize the conversion from CTF to System object and add filter cascade stages.

    Design an eight-order Butterworth peak IIR filter. The number of columns in the filter coefficients, B and A, indicate that the peak filter is divided in second-order sections. The vector of scale values, g, contains the gain for the four stages and the overall system gain.

    [B,A,g] = designNotchPeakIIR(FilterOrder=8, ...
         QualityFactor=5,HasScaleValues=true)
    B = 4×3
    
        1.0000    2.0000    1.0000
        1.0000   -2.0000    1.0000
        1.0000    2.0000    1.0000
        1.0000   -2.0000    1.0000
    
    
    A = 4×3
    
        1.0000    0.2738    0.8880
        1.0000   -0.2738    0.8880
        1.0000    0.1067    0.7455
        1.0000   -0.1067    0.7455
    
    
    g = 5×1
    
        0.1479
        0.1479
        0.1380
        0.1380
        1.0000
    
    

    Convert the filter coefficients to a System object.

    sosSys = ctf2sysobj(B,A,g)
    sosSys = 
      dsp.SOSFilter with properties:
    
                Structure: 'Direct form II transposed'
        CoefficientSource: 'Property'
                Numerator: [4×3 double]
              Denominator: [4×3 double]
           HasScaleValues: true
              ScaleValues: [5×1 double]
    
      Show all properties
    
    

    By default, the ctf2sysobj function generates a dsp.SOSFilter System object for IIR filters of the order 2 or less. To generate a dsp.FilterCascade System object, specify the ForceCascade name-value argument as true. You can add filter stages in the next step.

    Convert the filter coefficients to a dsp.FilterCascade System object.

    ctfSys = ctf2sysobj(B,A,g,ForceCascade=true)
    ctfSys = 
      dsp.FilterCascade with properties:
    
             Stage1: [1×1 dsp.SOSFilter]
        CloneStages: true
    
    

    Add two stages to the dsp.FilterCascade System object. The stages comprise an allpass filter and a polyphase FIR sample-rate conversion filter. Display the System object. The resulting dsp.FilterCascade System object has three stages.

    addStage(ctfSys, dsp.AllpassFilter)
    addStage(ctfSys, dsp.FIRRateConverter(3,2,triang(9)))
    ctfSys
    ctfSys = 
      dsp.FilterCascade with properties:
    
             Stage1: [1×1 dsp.SOSFilter]
             Stage2: [1×1 dsp.AllpassFilter]
             Stage3: [1×1 dsp.FIRRateConverter]
        CloneStages: true
    
    

    Plot the impulse response discrete-time Fourier transform (DTFT) of the three-stage dsp.FilterCascade System object.

    freqzmr(ctfSys)

    Figure Output spectrum (one sided) contains 2 axes objects. Axes object 1 with title Output Magnitude, xlabel Frequency (mHz), ylabel Magnitude (dB) contains an object of type patch. Axes object 2 with title Output Phase, xlabel Frequency (mHz), ylabel Phase (rad) contains an object of type line.

    Input Arguments

    collapse all

    CTF numerator coefficients, specified as a matrix, vector, or scalar.

    Num must be of size L-by-(m + 1), where:

    • L represents the number of filter sections.

    • m represents the order of the filter numerators.

    For more information about the CTF format and coefficient matrices, see Specify Digital Filters in CTF Format.

    Data Types: single | double
    Complex Number Support: Yes

    CTF denominator coefficients, specified as a matrix, vector, or scalar.

    Den must be of size L-by-(n + 1), where:

    • L represents the number of filter sections.

    • n represents the order of the filter denominators.

    For more information about the CTF format and coefficient matrices, see Specify Digital Filters in CTF Format.

    Note

    If any element of Den(:,1) is not equal to 1, then ctf2sysobj normalizes the filter coefficients by Den(:,1). In this case, Den(:,1) must be nonzero.

    Data Types: single | double
    Complex Number Support: Yes

    Scale values, specified as a real-valued scalar or as a real-valued vector with L + 1 elements, where L is the number of filter sections. The scale values represent the distribution of the filter gain across sections of the cascaded filter representation.

    The ctf2sysobj function applies a gain to the filter sections using the scaleFilterSections function depending on how you specify g:

    • Scalar — The function distributes the gain uniformly across all filter sections.

    • Vector — The function applies the first L gain values to the corresponding filter sections and distributes the last gain value uniformly across all filter sections.

    Data Types: single | double

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: ctf = ctf2sysobj([2 4 2;1 0 0],ForceCascade=true) specifies an FIR digital filter with option to wrap each filter stage into System object.

    Option to force single-stage cascades into a dsp.FilterCascade System object, specified as one of these:

    Data Types: logical

    Option to treat column vectors (Num and Den) as row vectors (single-stage CTF), specified as on these values:

    • true (1) — When you specify Num and Den as column vectors, ctf2sysobj assumes that Num and Den list the coefficients of a single-stage filter.

    • false (0) — When you specify Num and Den as column vectors, ctf2sysobj assumes that each row of Num and Den relates to a separate filter stage.

      To specify ParseColumnVectorsAsRows as false (0), you must specify Num and Den as vectors with the same number of rows and Den must end with nonzero elements.

    Data Types: logical

    Output Arguments

    collapse all

    CTF filter System object, returned as one of these System objects:

    The ctf2sysobj identifies filter stages (SOS, FOS, IIR, or FIR) from the coefficients specified in Num and Den.

    • While an SOS or FOS filter stage can have multiple sections, each IIR or FIR filter stage has one section.

    • The order of each filter stage (stage order) is the maximum between the numerator order and denominator order.

    Depending on the number of stages, maximum order of each stage, and the value specified in ForceCascade, ctf2sysobj returns one of the System objects in this table.

    Stage Impulse Response TypeStage Order

    ForceCascade=false

    (Single-stage CTF)

    ForceCascade=false

    (Multiple-stage CTF)

    ForceCascade=true

    (Single-stage and multiple-stage CTF)

    IIR1 or 2dsp.SOSFilterDoes not applySingle-stage dsp.FilterCascade
    IIR3 or 4dsp.FourthOrderSectionFilterDoes not applySingle-stage dsp.FilterCascade
    IIRGreater than 4dsp.IIRFilterdsp.FilterCascadedsp.FilterCascade
    FIRAnydsp.FIRFilterdsp.FilterCascadedsp.FilterCascade
    Combination of the aboveDoes not applydsp.FilterCascadedsp.FilterCascade

    More About

    collapse all

    References

    [1] Lyons, Richard G. Understanding Digital Signal Processing. Upper Saddle River, NJ: Prentice Hall, 2004.

    Version History

    Introduced in R2025a