MATLAB: How to get transfer function from a bode plot data

iddata or idfrdSystem Identification Toolbox

I have a set of bode plot data with Gain in decibel and Frequency in Hz and after I import the data into MATLAB, I am confused on using which function to create d objects..( iddata or idfrd) where I gona used tfest function to estimate d transfer function..And could tfest gives the transfer function where the data is in decibel..TF= output/input , but TF= output(dB)-input(dB)

Best Answer

This example shows how to do what you want.
You will need to create idfrd or frd objct to use with tfest. In addition to gain, you also need phase data to create a complex number at each frequency to represent your system response.
To construct frd or idfrd object, you need the gain of the system, not in db. To convert from db:
gain=10^(gaindb/20);
Create idfrd object:
response = gain.*exp(1i*phase*pi/180);
Ts = 0.1; % your sampling time
w=whz*2*pi; %convert Hz to rad/sec
gfr = idfrd(response,w,Ts);
Estimate 2nd ordertransfer function
sys=tfest(gfr,2);
Compute the gain in db:
[mag,ph]=bode(sys,w);
magdb=20*log10(mag);