主要内容

ctf

Convert digital filter to coefficients in cascaded transfer function format

Since R2026a

    Description

    [B,A] = ctf(filtObj) returns the numerator and denominator coefficients in the Cascaded Transfer Functions (CTF) format for the digitalFilter object or filter System object™.

    Using a filter System object requires a DSP System Toolbox™ license.

    example

    [B,A,sv] = ctf(filtObj) returns the scale values in addition to the numerator and denominator coefficients.

    Examples

    collapse all

    Design a lowpass IIR filter with the passband frequency of 0.65π rad/sample and the stopband frequency of 0.80π rad/sample. The passband ripple is 1 dB and the stopband attenuation is 50 dB. Use the designfilt function to create a digitalFilter object with these specifications.

    digiFilt = designfilt("lowpassiir", ...
        PassbandFrequency=0.65,StopbandFrequency=0.80, ...
        PassbandRipple=1,StopbandAttenuation=50)
    digiFilt = 
     digitalFilter with properties:
    
       Coefficients:
                  Numerator: [6×3 double]
                Denominator: [6×3 double]
    
       Specifications:
          FrequencyResponse: 'lowpass'
            ImpulseResponse: 'iir'
        NormalizedFrequency: 1
        StopbandAttenuation: 50
             PassbandRipple: 1
          StopbandFrequency: 0.8000
          PassbandFrequency: 0.6500
               DesignMethod: 'butter'
    
     Use filterAnalyzer to visualize filter
     Use designfilt to edit filter
     Use filter to filter data
    
    

    Get coefficients in the CTF format for this filter.

    [num,den] = ctf(digiFilt)
    num = 6×3
    
        0.6865    1.3729    0.6865
        0.5694    1.1388    0.5694
        0.4953    0.9907    0.4953
        0.4498    0.8996    0.4498
        0.4250    0.8500    0.4250
        0.6459    0.6459         0
    
    
    den = 6×3
    
        1.0000    0.9601    0.7857
        1.0000    0.7964    0.4812
        1.0000    0.6928    0.2885
        1.0000    0.6291    0.1701
        1.0000    0.5944    0.1056
        1.0000    0.2917         0
    
    

    Design a lowpass IIR filter of order 8 using the designLowpassIIR function. Set the SystemObject flag to true to generate a dsp.SOSFilter object. Set HasScaleValues to true.

    sosFilt = designLowpassIIR(FilterOrder=8,HasScaleValues=true,...
        SystemObject=true)
    sosFilt = 
      dsp.SOSFilter with properties:
    
                Structure: 'Direct form II transposed'
        CoefficientSource: 'Property'
                Numerator: [4×3 double]
              Denominator: [4×3 double]
           HasScaleValues: true
              ScaleValues: [0.1287 0.1051 0.0922 0.0865 1]
    
      Show all properties
    
    

    Use the ctf function to obtain the filter coefficients in the CTF format. The function also outputs the scale values.

    [sosnum,sosden,sv] = ctf(sosFilt)
    sosnum = 4×3
    
         1     2     1
         1     2     1
         1     2     1
         1     2     1
    
    
    sosden = 4×3
    
        1.0000   -1.2428    0.7575
        1.0000   -1.0153    0.4359
        1.0000   -0.8906    0.2595
        1.0000   -0.8351    0.1810
    
    
    sv = 5×1
    
        0.1287
        0.1051
        0.0922
        0.0865
        1.0000
    
    

    Create a dsp.AllpassFilter object and specify the allpass polynomial coefficients.

    apFilt = dsp.AllpassFilter(AllpassCoefficients=[0   0.5539   0   0.2503;
                                                    0  -0.4364   0   0.2218;
                                                    0   0.3781   0  -0.3933])
    apFilt = 
      dsp.AllpassFilter with properties:
    
                        Structure: 'Minimum multiplier'
              AllpassCoefficients: [3×4 double]
        TrailingFirstOrderSection: false
    
    

    Use the ctf function to obtain coefficients in the CTF format and the scale values.

    [apnum,apden,sv] = ctf(apFilt)
    apnum = 3×5
    
        0.2503         0    0.5539         0    1.0000
        0.2218         0   -0.4364         0    1.0000
       -0.3933         0    0.3781         0    1.0000
    
    
    apden = 3×5
    
        1.0000         0    0.5539         0    0.2503
        1.0000         0   -0.4364         0    0.2218
        1.0000         0    0.3781         0   -0.3933
    
    
    sv = 
    1
    

    Create a dsp.FilterCascade object with these filter stages:

    • dsp.FIRFilter object

    • dsp.SOSFilter object

    • dsp.FourthOrderSectionFilter object

    • dsp.IIRFilter object

    • A scalar value of 3

    Create a dsp.FIRFilter object using the designLowpassFIR function.

    firFilt = designLowpassFIR(FilterOrder=8,SystemObject=true);

    Create a dsp.SOSFilter object using the designLowpassIIR function.

    sosFilt = designLowpassIIR(FilterOrder=8,HasScaleValues=true,...
        SystemObject=true);

    Create a dsp.FourthOrderSectionFilter object. Specify the filter coefficients.

    fosNum =[0.0135    0.0541    0.0812    0.0541    0.0135
             0.0080    0.0319    0.0478    0.0319    0.0080];
    fosDen =[1.0000   -2.2581    2.4552   -1.3108    0.3302
             1.0000   -1.7257    1.1842   -0.3779    0.0470];
    fosFilt = dsp.FourthOrderSectionFilter(fosNum,fosDen);

    Create a dsp.IIRFilter object. Specify the filter coefficients.

    sosNum = [0.1287    0.2574    0.1287
              0.1051    0.2103    0.1051
              0.0922    0.1844    0.0922
              0.0865    0.1729    0.0865];
    sosDen = [1.0000   -1.2428    0.7575
              1.0000   -1.0153    0.4359
              1.0000   -0.8906    0.2595
              1.0000   -0.8351    0.1810];
    iirFilt = dsp.IIRFilter(sos2tf([sosNum,sosDen]));

    Cascade these filters into a single dsp.FilterCascade object using the cascade function.

    filtCascadeObj = cascade(firFilt,cascade(sosFilt,fosFilt),...
        3,iirFilt)
    filtCascadeObj = 
      dsp.FilterCascade with properties:
    
             Stage1: [1×1 dsp.FIRFilter]
             Stage2: [1×1 dsp.FilterCascade]
             Stage3: 3
             Stage4: [1×1 dsp.IIRFilter]
        CloneStages: true
    
    

    Use the ctf function to obtain the filter coefficients and scale values of the overall filter cascade in the CTF format.

    [cascNum,cascDen,cascSV] = ctf(filtCascadeObj)
    cascNum = 9×9
    
        0.0000    0.0191    0.1019    0.2309    0.2963    0.2309    0.1019    0.0191    0.0000
        1.0000    2.0000    1.0000         0         0         0         0         0         0
        1.0000    2.0000    1.0000         0         0         0         0         0         0
        1.0000    2.0000    1.0000         0         0         0         0         0         0
        1.0000    2.0000    1.0000         0         0         0         0         0         0
        0.0135    0.0541    0.0812    0.0541    0.0135         0         0         0         0
        0.0080    0.0319    0.0478    0.0319    0.0080         0         0         0         0
        3.0000         0         0         0         0         0         0         0         0
        0.0001    0.0009    0.0030    0.0060    0.0076    0.0060    0.0030    0.0009    0.0001
    
    
    cascDen = 9×5
    
        1.0000         0         0         0         0
        1.0000   -1.2428    0.7575         0         0
        1.0000   -1.0153    0.4359         0         0
        1.0000   -0.8906    0.2595         0         0
        1.0000   -0.8351    0.1810         0         0
        1.0000   -2.2581    2.4552   -1.3108    0.3302
        1.0000   -1.7257    1.1842   -0.3779    0.0470
        1.0000         0         0         0         0
        1.0000    0.1000         0         0         0
    
    
    cascSV = 10×1
    
        1.0000
        0.1287
        0.1051
        0.0922
        0.0865
        1.0000
        1.0000
        1.0000
        1.0000
        1.0000
    
    

    Input Arguments

    collapse all

    Digital filter, specified as one of these filter objects:

    Output Arguments

    collapse all

    Cascaded transfer function (CTF) coefficients, returned as a row vector or matrix. B and A list the numerator and denominator coefficients of the cascaded transfer function, respectively.

    The sizes for B and A are L-by-(m+1) and L-by-(n+1), respectively. The function returns the first column of A as 1, thus A(1) = 1 when A is a row vector.

    • L represents the number of filter sections.

    • m represents the order of the filter numerators.

    • n represents the order of the filter denominators.

    Each row of the B and A matrices contains the respective polynomial coefficients of each CTF section.

    For more information about the cascaded transfer function format and coefficient matrices, see Return Digital Filters in CTF Format.

    Data Types: single | double

    Scale values, returned as a scalar or a column vector of length L+1, where L is the number of filter sections. The scale values represent the distribution of the filter gain across the sections of the cascaded filter representation.

    Data Types: single | double

    More About

    collapse all

    References

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

    Version History

    Introduced in R2026a

    See Also

    Functions

    Objects