What am I doing wrong?-Bode plots to get transfer function

I've noticed a couple of similar questions which haven't been answered such as:

https://dsp.stackexchange.com/questions/24381/derivation-of-transfer-function-from-bode-plot

Anyway, I thought I would ask since it hasn't been answered. So as I understand the s-variable in the s-domain can be thought of as $j\omega$. I have a Bode plot so I have values of $$H(j\omega)=H(j\omega) \exp[j\arg(H(j\omega))]=\textsf{gain}\cdot\exp(j \cdot\textsf{phase})$$ (The graph I had was not a magnitude in terms of decibel but not gain) Now I tried to do a regression on it(actually probably technically not a regression from a statisticians' point of view by trying to minimise the least square error of a rational function $$(as^2+bs+c)/(ds^2+es+f)$$ and the values of $H(j\omega)$ that we have from the Bode plot. (Tried higher order rational function as well like of degree 10). And I get absolutely rubbish results for $a$,$b$,$c$,$d$,$e$,$f$ with Bode plots which look nothing alike. What am I doing wrong?

• Just to understand what you did: you took the (linear!) gain, the phase in radians (!), and you formed a complex frequency response on a frequency grid, and then you tried to fit a rational function in $s$ with quadratic numerator and denominator, setting $s=j\omega$? – Matt L. Jul 10 '15 at 15:35
• Yes,Matt. That's exactly what I did. (Sorry I asked the question and I had a previous stackexchange account but I don't think it registered with dsp.stackexchange for some reason as I am not too familiar with everything.) I used Python. I might try it with Matlab and see if that works. I used the scipy.optimize.minimize function to minimise the least square error of the rational function and the values of H(jw) I obtained from the plots getting different Bode plots so I thought it might be something to do with the actual process rather than the implementation. – daruma Jul 10 '15 at 19:16
• You could describe in more detail how you arrived at the result, because like this it's impossible to tell what went wrong. As far as I understand, the approach itself is OK. One problem could be the convergence of the optimization routine, because this is a non-linear problem which can get stuck in a local minimum. Do you use Matlab? – Matt L. Jul 11 '15 at 9:51
• Usually with a transfer function you would be able to guess the values of the zeros and poles by looking at it, these can be used to fit $\frac{a(s-z_1)(s-z_2)\dots}{(s-p_1)(s-p_2)\dots}$. Also note that I removed one gain of the highest power, since this is not fully defined. It would also be better to split up the popes and zeros into real and complex parts and probably these will come in complex conjugate pairs. – fibonatic Jul 13 '15 at 10:17