How to extract Symbolic coefficient of TRANSFER FUNCTION in MATLAB

10,017

You can apply numden to extract the numerator and the denominator polynomical expression:

[numexpr, denexpr] = numden(sym(H))  %// 'sym' makes sure that H is symbolic

and then you can extract the symbolic coefficients of S by using the coeffs command (remember to apply expand on each expression first to obtain their polynomial forms).

However, note that coeffs returns only the non-zero coefficients. To overcome this issue, I suggest the following:

%// Extract numerator coefficients
[numcoef, numpow] = coeffs(expand(numexpr), S);
num = rot90(sym(sym2poly(sum(numpow))), 2);
num(num ~= 0) = coeffs(expand(numexpr), S);

%// Extract denominator coefficients
[dencoef, denpow] = coeffs(expand(denexpr), S);
den = rot90(sym(sym2poly(sum(denpow))), 2);
den(den ~= 0) = coeffs(expand(denexpr), S);

P.S: you can also apply sym2polys tool from the MATLAB Exchange on numexpr and denexpr instead.

Also note that it is more common for the last elements in the coefficient vectors to be associated with the highest powers of S, so the result of this solution will be in reverse order to what you have described in your question.

Example

%// Create symbolic function
syms a b S
H = b * S / (a + S^2)
[numexpr, denexpr] = numden(sym(H));

%// Extract numerator coefficients
[numcoef, numpow] = coeffs(expand(numexpr), S);
num = rot90(sym(sym2poly(sum(numpow))), 2);
num(num ~= 0) = coeffs(expand(numexpr), S);

%// Extract denominator coefficients
[dencoef, denpow] = coeffs(expand(denexpr), S);
den = rot90(sym(sym2poly(sum(denpow))), 2);
den(den ~= 0) = coeffs(expand(denexpr), S);

The result is:

num =
    [0, b]

den =
    [a, 0, 1]
Share:
10,017

Related videos on Youtube

Shafqat
Author by

Shafqat

My areas of interest are: DSP, Microwave and Optical Communication

Updated on July 11, 2022

Comments

  • Shafqat
    Shafqat almost 2 years

    How to extract coefficient in symbolic math MATLAB.

    eg, i have transfer function like

    H(S) = (a*S^2 + b*S^ + a*c*S + d*a) / (S^3 + b*c*S^2 + d*S^1 + a*d)
    

    I want to get coefficient of 'S' term in H(s) as vector array like

    num = [a b a*c d*a]
    den = [1 b*c d a*d]
    
  • Shafqat
    Shafqat about 11 years
    Thanks alot Eitan for reply... When i use these codes in my actual problem i.e. S(Z1, z) =(Z1*z + Z1)/((Z1 - 25)*z + Z1 + 25); extracting wrt 'z', using code: syms Z1 z S(Z1, z) =(Z1*z + Z1)/((Z1 - 25)*z + Z1 + 25); [numexpr, denexpr] = numden(S); num = coeffs(numexpr, z) den = coeffs(numexpr, z) Results are---> num = [ Z1, Z1] den = [ Z1, Z1]. Here, den is wrong coz den should be [Z1-25 Z1+25]..
  • Eitan T
    Eitan T about 11 years
    @Shafqat You did den = coeffs(numexpr, z) by mistake instead of den = coeffs(denexpr, z).
  • Shafqat
    Shafqat about 11 years
    Yup my mistake...Thanks 4 help...:)