# Estimate a Transfer Function from Data

I have been given the frequency response and step response of a closed loop system, with a known k value. What would be the best method to find the transfer function?

The following is only true if you assume a linear plant model. You have the frequency response $|G(j\omega)|$ and $\varphi(\omega)$, hence you can rewrite the result as $$G(j\omega)=|G(j\omega)|\exp\left[j\omega+j\varphi(\omega)\right].$$

Now, you need to come up with candidate functions of the following form

$$\hat{G}(j\omega)=\dfrac{\sum_{m=0}^{M}b_m(j\omega)^m}{\sum_{n=0}^{N}a_n(j\omega)^n}.$$

Normally, we would start off with simple transfer functions and choose a more complicated one, if we are not satisfied with the fit. The goal is to determine the set of parameters $a_n$ and $b_m$. In order to do this, you could minimize the objective function

$$F(a_0,...,a_N,b_0,...,b_M)=\sum_{i=1}^{K}\left[(G(j\omega_i)-\hat{G}(j\omega_i))\overline{(G(j\omega_i)-\hat{G}(j\omega_i))} \right],$$

in which the overline designates the complex conjugate and the index $i$ indicates the index of your measurements/data points, from which you have $K$ in total. You can use Excel/MATLAB/Python to automatically determine the parameters with a nonlinear optimization. After determining the parameters you should check if the fit is acceptable or not.

If you are using MATLAB you can also use the parameter identification toolbox for linear systems.