I'm wondering of anyone can explain why invfreqs() is unable to fit a polynomial to the data in the image below. The red line is the measured frequency response of an analog system. I should mention that this data is a logarithmic sweep from 100 Hz to 100 GHz. The blue line is the 11th order invfreqs fit (11th order in both numerator and denominator). 11th order does the best job, but as you can see, there is a massive offset from DC to a few MHz. Everything from 1 GHz and above is a stellar fit.
Any idea why the low freqs don't fit?
UPDATE: Problem solved. The frequency vector must be normalized to keep the computation accurate. I divided it by 1e6. Then the b,a coefficients are converted into zpk form. Multiply z and p by 1e6.
%% estimate transfer function using invfreqs() H = freq_resp; samples = length(H); w_norm = w/1e6; wts = 0:samples-1; wts = exp(-wts); [b,a] = invfreqs(H,w_norm,15,15,wts,50); [z,p,k] = tf2zp(b,a); zs = z*1e6 ; ps = p*1e6 ; [bs,as] = zp2tf(zs,ps,k); sys_pred = tf(bs,as); figure bode(sys_true,'r',sys_pred,'b')