# Matlab- Find num and den

Discussion in 'Programmer's Corner' started by cloud, Dec 15, 2006.

1. ### cloud Thread Starter Member

Dec 15, 2006
11
0
I have a transfer function called tf(1:43001). How do I obtain the
numerator and the denominator, so that I can use fvtool(num,den)?

Thank you.

2. ### Dave Retired Moderator

Nov 17, 2003
6,960
145
I cannot be specific beacuse I haven't got your transfer function to hand, but you could use the numden function in the Symbolic Math Toolbox (most Matlab installations have this installed as standard).

Code ( (Unknown Language)):
1. [n,d] = numden(tf);
Will return the numerator, n, and the denominator d.

Failing that you could probably look at deriving the numerator and denominator during the derivation of the transfer function. Could you load up you code to let us have a look at it?

Dave

3. ### cloud Thread Starter Member

Dec 15, 2006
11
0
Attached is my code. I will like to find the num and den of my transfer function to design into a filter and to obtain an accurate frequency response. Do you have any suggestions to derive an accurate frequency response for my code?

Thank you.

File size:
2.6 KB
Views:
57
4. ### Papabravo Expert

Feb 24, 2006
10,338
1,850
Does that notation imply that the numerator is a 1, and
the denominator is the polynomial 4x^4 + 3x^3 + 1 ?
So your question is how to get matlab to give you the individual pieces?

5. ### cloud Thread Starter Member

Dec 15, 2006
11
0
My tf(1:43001) is refering to the transfer function from 1 data points to 43001 data points. (1:43001) is the number of data points.

6. ### Papabravo Expert

Feb 24, 2006
10,338
1,850
So this transfer function is defined by a dataset and you want to calculate a rational function with polynomials in the numerator and denominator. Assuming that such a rational approximation exists. I am familiar with polynomial fits but I'm not sure you can find rational approximations to arbitrary data.

Does your data set have singularities? If it does then those are the roots of the denominator polynomial. Multiply the factors together to get the denominator. Does your data set have zeros? If it does those are the roots of the numerator polynomial. Multiply the factors together to get the numerator polynomial. Except for a possible gain constant, the rest of the points are just floor sweepings and have nothing to do with the transfer function.

7. ### Dave Retired Moderator

Nov 17, 2003
6,960
145
Code ( (Unknown Language)):
1. tf=Ysec400c./Ypri400c;  % transfer function=FFT(secondary) / FFT(primary)
Why is this the transfer function? The transfer function is defined as the output/input of the system H(s) = Y(s)/X(s), so is this correct?

From what I can gather about your data, tf will be a 1x43001 array of numbers - correct? Therefore you cannot deduce the numerator and denominator of the transfer function from this information. If tf is a 1x43001 array of s-plane parameters then Matlab will allow you to deduce the transfer function directly using the above method in my earlier post.

Can you write up what data is contained in tf(1:3) as an example?

Thanks.

Dave

8. ### cloud Thread Starter Member

Dec 15, 2006
11
0
Yes, my transfer function is output/input of my system, H(s) = Y(s)/X(s). My tf is a 1x43001 array of data points. I would like to find out the Y(s) and X(s) to represent it as for example, (eg (2s+1)/(s^2+2s+1)). Because I need to perform digital simulations( using Simulink or PSCAD) using the transfer function (eg (2s+1)/(s^2+2s+1)).

9. ### Papabravo Expert

Feb 24, 2006
10,338
1,850
One more time with feeling
The points are irrelevant. Only the poles and zeros matter.

10. ### Dave Retired Moderator

Nov 17, 2003
6,960
145
I concur, from analysing your code the tf array will not provide you the necessary information to derive the transfer function and hence the numerator/denominator for the function fvtool.

I am also not convinced that dividing your two solutions to the FFT for the secondary and primary constitutes the necessary requirements of the transfer function H(s).

Dave

11. ### cloud Thread Starter Member

Dec 15, 2006
11
0
Since my tf=Ysec400c./Ypri400c, how do I represent Ysec400c and Ypri400c into a polynomial respectively?

12. ### Dave Retired Moderator

Nov 17, 2003
6,960
145
Try this as a proposal, I'm not sure how it will work.

You want H(s) = Y(s)/X(s)

So: Y(s) = X(s)H(s)

Think of this in the time-domain: y[n] = x[n]*h[n] (this is convolution)

You effectly want to perform a deconvolution, Matlab lets you do this with the deconv function:

Code ( (Unknown Language)):
1. [h,r] = deconv(y,x);
Where r is the remainder vector such that y = conv(x,h)+r (hopefully r will be a zero vector, i.e. all zeros).

The array h is now your impulse response, where by taking the Fourier Transform of h gives the transfer function.

Dave