You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how to find the transfer function from LTspice
51 views (last 30 days)
Show older comments
hi there,
i have plotted the bode diagram of my transfer function from LTSpice to matlab using the following code:
filename = 'nameofthefile.txt';
fidi = fopen(filename, 'rt');
Dc = textscan(fidi, '%f(%fdB,%f°)', 'CollectOutput',1);
D = cell2mat(Dc);
figure
subplot(2,1,1)
semilogx(D(:,1), D(:,2))
title('Amplitude (dB)')
grid
subplot(2,1,2)
semilogx(D(:,1), D(:,3))
title('Phase (°)')
grid
xlabel('Frequency')
now i need to see the expression of the transfer function i plotted as a function of the frequency, but i don't know how to do it. Is there anyone who can help me to do it?
Accepted Answer
Star Strider
on 23 Dec 2021
Perhaps I am missing something, however ‘the expression of the transfer function i plotted as a function of the frequency’ is essentially the definition of the magnitude spectrum of the Bode plot.
If the desired result is a state-space (or other) realisation of system identified from the magnitude, phase and frequency, start with the idfrd function and follow the documentation to identify the model. Be certain that the units are the same as the System Identification Toolbox functions require, so it may be necessary to convert them approporiately.
14 Comments
francesco baldi
on 23 Dec 2021
I'm sorry, maybe I wasn't clear. Isn't there a way to see the function with that Bode diagram? I mean, I traced the Bode diagram , but I don't have the explicit expression of the function with that Bode diagram, and I'd like to find it, as a function of frequency. I hope I exposed the problem more clearly.
Star Strider
on 23 Dec 2021
If the desired result is to get the s (Laplace) domain transfer function realisation or the state space (preferred) realisation of the system that created those data, the only way to get there is with the System Identification Toolbox. Since the only available data appear to be the frequency vector and the decibel magnitude and degree phase angle vectors, this becomes a frequency domain system identification problem.
Given adequate and correct data, the System Identification Toolbox is more than capable of estimating the desired realisation, and comparing its results with the given data.
If I have the data to work with, I can write specific code using System Identification Toolbox functions that will likely identify and estimate the system that created them.
Star Strider
on 24 Dec 2021
A second-order system provides a perfect fit —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/842990/Draft1.txt', 'VariableNamingRule','preserve')
T1 = 401×2 table
Var1 Var2
______ ______________________________________________________
10 {'(-6.02060034191108e+000dB,-1.79999994078238e-002°)'}
10.233 {'(-6.02060036211185e+000dB,-1.84192732265253e-002°)'}
10.471 {'(-6.02060038326466e+000dB,-1.88483131850069e-002°)'}
10.715 {'(-6.02060040541437e+000dB,-1.92873467657410e-002°)'}
10.965 {'(-6.02060042860797e+000dB,-1.97366067499370e-002°)'}
11.22 {'(-6.02060045289464e+000dB,-2.01963313409642e-002°)'}
11.482 {'(-6.02060047832591e+000dB,-2.06667642906489e-002°)'}
11.749 {'(-6.02060050495572e+000dB,-2.11481550285142e-002°)'}
12.023 {'(-6.02060053284056e+000dB,-2.16407587940291e-002°)'}
12.303 {'(-6.02060056203956e+000dB,-2.21448367719392e-002°)'}
12.589 {'(-6.02060059261468e+000dB,-2.26606562307481e-002°)'}
12.882 {'(-6.02060062463075e+000dB,-2.31884906644261e-002°)'}
13.183 {'(-6.02060065815569e+000dB,-2.37286199374180e-002°)'}
13.49 {'(-6.02060069326061e+000dB,-2.42813304330296e-002°)'}
13.804 {'(-6.02060073001998e+000dB,-2.48469152052698e-002°)'}
14.125 {'(-6.02060076851176e+000dB,-2.54256741342303e-002°)'}
V2c = cellfun(@(x)sscanf(x, '(%fdB,%f°'), T1.Var2, 'Unif',0);
V2m = cell2mat(V2c')';
T2 = table('Size',[size(T1.Var1,1) 3],'VariableTypes',{'double','double','double'}, 'VariableNames',{'FreqHz','MagndB','PhasDg'});T2.FreqHz = T1.Var1;
T2.MagndB = V2m(:,1);
T2.PhasDg = V2m(:,2)
T2 = 401×3 table
FreqHz MagndB PhasDg
______ _______ _________
10 -6.0206 -0.018
10.233 -6.0206 -0.018419
10.471 -6.0206 -0.018848
10.715 -6.0206 -0.019287
10.965 -6.0206 -0.019737
11.22 -6.0206 -0.020196
11.482 -6.0206 -0.020667
11.749 -6.0206 -0.021148
12.023 -6.0206 -0.021641
12.303 -6.0206 -0.022145
12.589 -6.0206 -0.022661
12.882 -6.0206 -0.023188
13.183 -6.0206 -0.023729
13.49 -6.0206 -0.024281
13.804 -6.0206 -0.024847
14.125 -6.0206 -0.025426
Mag = db2mag(T2.MagndB);
Phs = deg2rad(T2.PhasDg);
Rsp = Mag.*exp(1j*Phs)
Rsp =
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0002i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0003i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0004i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0005i
0.5000 - 0.0006i
0.5000 - 0.0006i
0.5000 - 0.0006i
0.5000 - 0.0006i
0.5000 - 0.0006i
0.5000 - 0.0006i
0.5000 - 0.0006i
0.5000 - 0.0007i
0.5000 - 0.0007i
0.5000 - 0.0007i
0.5000 - 0.0007i
0.5000 - 0.0007i
0.5000 - 0.0007i
0.5000 - 0.0008i
0.5000 - 0.0008i
0.5000 - 0.0008i
0.5000 - 0.0008i
0.5000 - 0.0008i
0.5000 - 0.0008i
0.5000 - 0.0009i
0.5000 - 0.0009i
0.5000 - 0.0009i
0.5000 - 0.0009i
0.5000 - 0.0009i
0.5000 - 0.0010i
0.5000 - 0.0010i
0.5000 - 0.0010i
0.5000 - 0.0010i
0.5000 - 0.0011i
0.5000 - 0.0011i
0.5000 - 0.0011i
0.5000 - 0.0011i
0.5000 - 0.0012i
0.5000 - 0.0012i
0.5000 - 0.0012i
0.5000 - 0.0012i
0.5000 - 0.0013i
0.5000 - 0.0013i
0.5000 - 0.0013i
0.5000 - 0.0014i
0.5000 - 0.0014i
0.5000 - 0.0014i
0.5000 - 0.0015i
0.5000 - 0.0015i
0.5000 - 0.0015i
0.5000 - 0.0016i
0.5000 - 0.0016i
0.5000 - 0.0016i
0.5000 - 0.0017i
0.5000 - 0.0017i
0.5000 - 0.0018i
0.5000 - 0.0018i
0.5000 - 0.0018i
0.5000 - 0.0019i
0.5000 - 0.0019i
0.5000 - 0.0020i
0.5000 - 0.0020i
0.5000 - 0.0021i
0.5000 - 0.0021i
0.5000 - 0.0022i
0.5000 - 0.0022i
0.5000 - 0.0023i
0.5000 - 0.0023i
0.5000 - 0.0024i
0.5000 - 0.0024i
0.5000 - 0.0025i
0.5000 - 0.0025i
0.5000 - 0.0026i
0.5000 - 0.0027i
0.5000 - 0.0027i
0.5000 - 0.0028i
0.5000 - 0.0029i
0.5000 - 0.0029i
0.5000 - 0.0030i
0.5000 - 0.0031i
0.5000 - 0.0031i
0.5000 - 0.0032i
0.5000 - 0.0033i
0.5000 - 0.0034i
0.5000 - 0.0034i
0.5000 - 0.0035i
0.5000 - 0.0036i
0.5000 - 0.0037i
0.5000 - 0.0038i
0.5000 - 0.0039i
0.5000 - 0.0039i
0.5000 - 0.0040i
0.5000 - 0.0041i
0.5000 - 0.0042i
0.5000 - 0.0043i
0.5000 - 0.0044i
0.5000 - 0.0045i
0.5000 - 0.0046i
0.5000 - 0.0047i
0.5000 - 0.0049i
0.5000 - 0.0050i
0.4999 - 0.0051i
0.4999 - 0.0052i
0.4999 - 0.0053i
0.4999 - 0.0054i
0.4999 - 0.0056i
0.4999 - 0.0057i
0.4999 - 0.0058i
0.4999 - 0.0060i
0.4999 - 0.0061i
0.4999 - 0.0063i
0.4999 - 0.0064i
0.4999 - 0.0065i
0.4999 - 0.0067i
0.4999 - 0.0069i
0.4999 - 0.0070i
0.4999 - 0.0072i
0.4999 - 0.0073i
0.4999 - 0.0075i
0.4999 - 0.0077i
0.4999 - 0.0079i
0.4999 - 0.0081i
0.4999 - 0.0082i
0.4999 - 0.0084i
0.4999 - 0.0086i
0.4998 - 0.0088i
0.4998 - 0.0090i
0.4998 - 0.0092i
0.4998 - 0.0095i
0.4998 - 0.0097i
0.4998 - 0.0099i
0.4998 - 0.0101i
0.4998 - 0.0104i
0.4998 - 0.0106i
0.4998 - 0.0109i
0.4998 - 0.0111i
0.4997 - 0.0114i
0.4997 - 0.0116i
0.4997 - 0.0119i
0.4997 - 0.0122i
0.4997 - 0.0125i
0.4997 - 0.0128i
0.4997 - 0.0131i
0.4996 - 0.0134i
0.4996 - 0.0137i
0.4996 - 0.0140i
0.4996 - 0.0143i
0.4996 - 0.0146i
0.4996 - 0.0150i
0.4995 - 0.0153i
0.4995 - 0.0157i
0.4995 - 0.0161i
0.4995 - 0.0164i
0.4994 - 0.0168i
0.4994 - 0.0172i
0.4994 - 0.0176i
0.4994 - 0.0180i
0.4993 - 0.0184i
0.4993 - 0.0189i
0.4993 - 0.0193i
0.4992 - 0.0197i
0.4992 - 0.0202i
0.4991 - 0.0207i
0.4991 - 0.0212i
0.4991 - 0.0216i
0.4990 - 0.0221i
0.4990 - 0.0227i
0.4989 - 0.0232i
0.4989 - 0.0237i
0.4988 - 0.0243i
0.4988 - 0.0248i
0.4987 - 0.0254i
0.4986 - 0.0260i
0.4986 - 0.0266i
0.4985 - 0.0272i
0.4984 - 0.0278i
0.4984 - 0.0285i
0.4983 - 0.0291i
0.4982 - 0.0298i
0.4981 - 0.0305i
0.4980 - 0.0312i
0.4980 - 0.0319i
0.4979 - 0.0327i
0.4978 - 0.0334i
0.4976 - 0.0342i
0.4975 - 0.0350i
0.4974 - 0.0358i
0.4973 - 0.0366i
0.4972 - 0.0375i
0.4970 - 0.0383i
0.4969 - 0.0392i
0.4968 - 0.0401i
0.4966 - 0.0410i
0.4965 - 0.0420i
0.4963 - 0.0429i
0.4961 - 0.0439i
0.4959 - 0.0449i
0.4957 - 0.0460i
0.4955 - 0.0470i
0.4953 - 0.0481i
0.4951 - 0.0492i
0.4949 - 0.0503i
0.4946 - 0.0515i
0.4944 - 0.0526i
0.4941 - 0.0538i
0.4939 - 0.0550i
0.4936 - 0.0563i
0.4933 - 0.0576i
0.4930 - 0.0589i
0.4926 - 0.0602i
0.4923 - 0.0616i
0.4919 - 0.0630i
0.4916 - 0.0644i
0.4912 - 0.0658i
0.4908 - 0.0673i
0.4903 - 0.0688i
0.4899 - 0.0703i
0.4894 - 0.0719i
0.4889 - 0.0735i
0.4884 - 0.0752i
0.4879 - 0.0768i
0.4873 - 0.0785i
0.4868 - 0.0803i
0.4862 - 0.0820i
0.4855 - 0.0838i
0.4849 - 0.0857i
0.4842 - 0.0875i
0.4835 - 0.0894i
0.4827 - 0.0914i
0.4819 - 0.0934i
0.4811 - 0.0954i
0.4802 - 0.0974i
0.4793 - 0.0995i
0.4784 - 0.1016i
0.4774 - 0.1038i
0.4764 - 0.1060i
0.4754 - 0.1082i
0.4743 - 0.1105i
0.4731 - 0.1128i
0.4719 - 0.1151i
0.4707 - 0.1175i
0.4694 - 0.1199i
0.4680 - 0.1223i
0.4666 - 0.1248i
0.4652 - 0.1273i
0.4637 - 0.1298i
0.4621 - 0.1324i
0.4604 - 0.1350i
0.4587 - 0.1376i
0.4569 - 0.1403i
0.4551 - 0.1430i
0.4532 - 0.1457i
0.4512 - 0.1484i
0.4491 - 0.1512i
0.4470 - 0.1540i
0.4447 - 0.1568i
0.4424 - 0.1596i
0.4400 - 0.1624i
0.4376 - 0.1653i
0.4350 - 0.1681i
0.4324 - 0.1710i
0.4296 - 0.1739i
0.4268 - 0.1768i
0.4239 - 0.1796i
0.4209 - 0.1825i
0.4177 - 0.1854i
0.4145 - 0.1882i
0.4112 - 0.1911i
0.4078 - 0.1939i
0.4043 - 0.1967i
0.4007 - 0.1995i
0.3970 - 0.2022i
0.3931 - 0.2050i
0.3892 - 0.2077i
0.3852 - 0.2103i
0.3811 - 0.2129i
0.3768 - 0.2154i
0.3725 - 0.2179i
0.3681 - 0.2203i
0.3636 - 0.2227i
0.3590 - 0.2250i
0.3542 - 0.2272i
0.3494 - 0.2294i
0.3446 - 0.2314i
0.3396 - 0.2334i
0.3345 - 0.2353i
0.3294 - 0.2371i
0.3242 - 0.2387i
0.3189 - 0.2403i
0.3135 - 0.2418i
0.3081 - 0.2431i
0.3026 - 0.2444i
0.2971 - 0.2455i
0.2915 - 0.2465i
0.2859 - 0.2474i
0.2803 - 0.2482i
0.2746 - 0.2488i
0.2689 - 0.2493i
0.2631 - 0.2497i
0.2574 - 0.2499i
0.2516 - 0.2500i
0.2459 - 0.2500i
0.2401 - 0.2498i
0.2344 - 0.2495i
0.2287 - 0.2491i
0.2230 - 0.2485i
0.2173 - 0.2479i
0.2117 - 0.2470i
0.2061 - 0.2461i
0.2005 - 0.2450i
0.1950 - 0.2439i
0.1895 - 0.2426i
0.1842 - 0.2412i
0.1788 - 0.2397i
0.1736 - 0.2380i
0.1684 - 0.2363i
0.1633 - 0.2345i
0.1583 - 0.2326i
0.1533 - 0.2306i
0.1485 - 0.2285i
0.1437 - 0.2263i
0.1390 - 0.2240i
0.1345 - 0.2217i
0.1300 - 0.2193i
0.1256 - 0.2169i
0.1213 - 0.2143i
0.1171 - 0.2118i
0.1131 - 0.2092i
0.1091 - 0.2065i
0.1052 - 0.2038i
0.1014 - 0.2011i
0.0978 - 0.1983i
0.0942 - 0.1955i
0.0907 - 0.1927i
0.0874 - 0.1899i
0.0841 - 0.1870i
0.0809 - 0.1841i
0.0778 - 0.1813i
0.0749 - 0.1784i
0.0720 - 0.1755i
0.0692 - 0.1726i
0.0665 - 0.1698i
0.0639 - 0.1669i
0.0614 - 0.1640i
0.0589 - 0.1612i
0.0566 - 0.1584i
0.0543 - 0.1556i
0.0521 - 0.1528i
0.0500 - 0.1500i
0.0480 - 0.1472i
0.0460 - 0.1445i
Sizes = [size(T2.FreqHz); size(Rsp)]
Q3 = 2×2
401 1
401 1
sysfr = idfrd(Rsp,T2.FreqHz,0,'FrequencyUnit','Hz') % Create System Response Data Object
sysfr =
IDFRD model.
Contains Frequency Response Data for 1 output(s) and 1 input(s).
Response data is available at 401 frequency points, ranging from 10 Hz to 1e+05 Hz.
Status:
Created by direct construction or transformation. Not estimated.
sys_ss = ssest(sysfr, 2) % State Space Realisation
sys_ss =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 -3919 1.652e-06
x2 1.32e-17 -2e+05
B =
u1
x1 -2.096e-09
x2 256
C =
x1 x2
y1 -0.0006452 390.6
D =
u1
y1 0
K =
y1
x1 0
x2 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 8
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on frequency response data "sysfr".
Fit to estimation data: 100%
FPE: 1.135e-31, MSE: 1.112e-31
figure
compare(sysfr, sys_ss)
sys_tf = tfest(sysfr, 2) % Transfer Function Realisation
sys_tf =
1e05 s + 3.919e08
---------------------------
s^2 + 2.039e05 s + 7.838e08
Continuous-time identified transfer function.
Parameterization:
Number of poles: 2 Number of zeros: 1
Number of free coefficients: 4
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using TFEST on frequency response data "sysfr".
Fit to estimation data: 100%
FPE: 1.19e-29, MSE: 1.166e-29
figure
compare(sysfr, sys_tf)
figure
pzmap(sys_ss)
grid on
format long E
Poles = pole(sys_ss)
Poles = 2×1
1.0e+00 *
-3.918846154562714e+03
-2.000000000000001e+05
Zeros = zero(sys_ss)
Zeros =
-3.918846154562714e+03
The phases are ‘off’ by 360° so exactly match.
.
Star Strider
on 24 Dec 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
francesco baldi
on 24 Dec 2021
i still have two questions: to solve the phase mismatch, can't i just plot the bode of sys_tf without comparing it to the orignally bode from Data? If i delete compare compare(sysfr, sys_tf) and replace it with bode(sys_tf) i get a phase starting from 0.
When i run this code with another data.txt i get the following warning: Estimated model has a lower order than requested. what do i have to modify on the code you wrote to solve this problme?
Star Strider
on 24 Dec 2021
First — Sure! I used the compare function to do just that — show how the estimated system matched the data. The bode function is certainly appropriate for only the Bode plot of the estimated system.
Second — I cannot be certain with the data, however it would appear that the requested order (2) creates multiple poles or zeros located in the same places. The solution is to reduce the order. For the transfer function, this will be relatively straightforward, and for the state space model it could result in a single exponential rather than a matrix.
francesco baldi
on 24 Dec 2021
this is the set of data i'm trying to export in matlab. I tried to reduce the order from 2 to 1 but i'm getting strange plots, can you tell me how to change the code using these data?
Star Strider
on 25 Dec 2021
That warning only occurs with tfest and it goes away when both the number of poles and the number of zeros are set specifically —
sys_tf = tfest(sysfr, 1,1)
I made that change here, and the system is identified correctly. Note that it has a highpass characteristic with a pole at infinity (with respect to floating-point precision).
The state space realisation continues to be a second-order system.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/843515/Draft2.txt', 'VariableNamingRule','preserve')
T1 = 301×2 table
Var1 Var2
______ _____________________________________________________
1000 {'(-6.00777260984419e+000dB,1.79586560570654e+000°)'}
1023.3 {'(-6.00716963461470e+000dB,1.83749784854299e+000°)'}
1047.1 {'(-6.00653839179706e+000dB,1.88008566363902e+000°)'}
1071.5 {'(-6.00587756356241e+000dB,1.92365030242762e+000°)'}
1096.5 {'(-6.00518577135216e+000dB,1.96821344014452e+000°)'}
1122 {'(-6.00446157314733e+000dB,2.01379718070299e+000°)'}
1148.2 {'(-6.00370346062171e+000dB,2.06042406133642e+000°)'}
1174.9 {'(-6.00290985617443e+000dB,2.10811705697993e+000°)'}
1202.3 {'(-6.00207910983768e+000dB,2.15689958435995e+000°)'}
1230.3 {'(-6.00120949605494e+000dB,2.20679550575875e+000°)'}
1258.9 {'(-6.00029921032525e+000dB,2.25782913241795e+000°)'}
1288.2 {'(-5.99934636570885e+000dB,2.31002522754294e+000°)'}
1318.3 {'(-5.99834898918951e+000dB,2.36340900886699e+000°)'}
1349 {'(-5.99730501788862e+000dB,2.41800615073106e+000°)'}
1380.4 {'(-5.99621229512652e+000dB,2.47384278563210e+000°)'}
1412.5 {'(-5.99506856632595e+000dB,2.53094550518955e+000°)'}
V2c = cellfun(@(x)sscanf(x, '(%fdB,%f°'), T1.Var2, 'Unif',0);
V2m = cell2mat(V2c')';
T2 = table('Size',[size(T1.Var1,1) 3],'VariableTypes',{'double','double','double'}, 'VariableNames',{'FreqHz','MagndB','PhasDg'});T2.FreqHz = T1.Var1;
T2.MagndB = V2m(:,1);
T2.PhasDg = V2m(:,2)
T2 = 301×3 table
FreqHz MagndB PhasDg
______ _______ ______
1000 -6.0078 1.7959
1023.3 -6.0072 1.8375
1047.1 -6.0065 1.8801
1071.5 -6.0059 1.9237
1096.5 -6.0052 1.9682
1122 -6.0045 2.0138
1148.2 -6.0037 2.0604
1174.9 -6.0029 2.1081
1202.3 -6.0021 2.1569
1230.3 -6.0012 2.2068
1258.9 -6.0003 2.2578
1288.2 -5.9993 2.31
1318.3 -5.9983 2.3634
1349 -5.9973 2.418
1380.4 -5.9962 2.4738
1412.5 -5.9951 2.5309
Mag = db2mag(T2.MagndB);
Phs = deg2rad(T2.PhasDg);
Rsp = Mag.*exp(1j*Phs)
Rsp =
0.5005 + 0.0157i
0.5005 + 0.0161i
0.5005 + 0.0164i
0.5006 + 0.0168i
0.5006 + 0.0172i
0.5006 + 0.0176i
0.5006 + 0.0180i
0.5007 + 0.0184i
0.5007 + 0.0189i
0.5007 + 0.0193i
0.5008 + 0.0197i
0.5008 + 0.0202i
0.5009 + 0.0207i
0.5009 + 0.0212i
0.5009 + 0.0216i
0.5010 + 0.0221i
0.5010 + 0.0227i
0.5011 + 0.0232i
0.5011 + 0.0237i
0.5012 + 0.0243i
0.5012 + 0.0248i
0.5013 + 0.0254i
0.5014 + 0.0260i
0.5014 + 0.0266i
0.5015 + 0.0272i
0.5016 + 0.0278i
0.5016 + 0.0285i
0.5017 + 0.0291i
0.5018 + 0.0298i
0.5019 + 0.0305i
0.5020 + 0.0312i
0.5020 + 0.0319i
0.5021 + 0.0327i
0.5022 + 0.0334i
0.5024 + 0.0342i
0.5025 + 0.0350i
0.5026 + 0.0358i
0.5027 + 0.0366i
0.5028 + 0.0375i
0.5030 + 0.0383i
0.5031 + 0.0392i
0.5032 + 0.0401i
0.5034 + 0.0410i
0.5035 + 0.0420i
0.5037 + 0.0429i
0.5039 + 0.0439i
0.5041 + 0.0449i
0.5043 + 0.0460i
0.5045 + 0.0470i
0.5047 + 0.0481i
0.5049 + 0.0492i
0.5051 + 0.0503i
0.5054 + 0.0515i
0.5056 + 0.0526i
0.5059 + 0.0538i
0.5061 + 0.0550i
0.5064 + 0.0563i
0.5067 + 0.0576i
0.5070 + 0.0589i
0.5074 + 0.0602i
0.5077 + 0.0616i
0.5081 + 0.0630i
0.5084 + 0.0644i
0.5088 + 0.0658i
0.5092 + 0.0673i
0.5097 + 0.0688i
0.5101 + 0.0703i
0.5106 + 0.0719i
0.5111 + 0.0735i
0.5116 + 0.0752i
0.5121 + 0.0768i
0.5127 + 0.0785i
0.5132 + 0.0803i
0.5138 + 0.0820i
0.5145 + 0.0838i
0.5151 + 0.0857i
0.5158 + 0.0875i
0.5165 + 0.0894i
0.5173 + 0.0914i
0.5181 + 0.0934i
0.5189 + 0.0954i
0.5198 + 0.0974i
0.5207 + 0.0995i
0.5216 + 0.1016i
0.5226 + 0.1038i
0.5236 + 0.1060i
0.5246 + 0.1082i
0.5257 + 0.1105i
0.5269 + 0.1128i
0.5281 + 0.1151i
0.5293 + 0.1175i
0.5306 + 0.1199i
0.5320 + 0.1223i
0.5334 + 0.1248i
0.5348 + 0.1273i
0.5363 + 0.1298i
0.5379 + 0.1324i
0.5396 + 0.1350i
0.5413 + 0.1376i
0.5431 + 0.1403i
0.5449 + 0.1430i
0.5468 + 0.1457i
0.5488 + 0.1484i
0.5509 + 0.1512i
0.5530 + 0.1540i
0.5553 + 0.1568i
0.5576 + 0.1596i
0.5600 + 0.1624i
0.5624 + 0.1653i
0.5650 + 0.1681i
0.5676 + 0.1710i
0.5704 + 0.1739i
0.5732 + 0.1768i
0.5761 + 0.1796i
0.5791 + 0.1825i
0.5823 + 0.1854i
0.5855 + 0.1882i
0.5888 + 0.1911i
0.5922 + 0.1939i
0.5957 + 0.1967i
0.5993 + 0.1995i
0.6030 + 0.2022i
0.6069 + 0.2050i
0.6108 + 0.2077i
0.6148 + 0.2103i
0.6189 + 0.2129i
0.6232 + 0.2154i
0.6275 + 0.2179i
0.6319 + 0.2203i
0.6364 + 0.2227i
0.6410 + 0.2250i
0.6458 + 0.2272i
0.6506 + 0.2294i
0.6554 + 0.2314i
0.6604 + 0.2334i
0.6655 + 0.2353i
0.6706 + 0.2371i
0.6758 + 0.2387i
0.6811 + 0.2403i
0.6865 + 0.2418i
0.6919 + 0.2431i
0.6974 + 0.2444i
0.7029 + 0.2455i
0.7085 + 0.2465i
0.7141 + 0.2474i
0.7197 + 0.2482i
0.7254 + 0.2488i
0.7311 + 0.2493i
0.7369 + 0.2497i
0.7426 + 0.2499i
0.7484 + 0.2500i
0.7541 + 0.2500i
0.7599 + 0.2498i
0.7656 + 0.2495i
0.7713 + 0.2491i
0.7770 + 0.2485i
0.7827 + 0.2479i
0.7883 + 0.2470i
0.7939 + 0.2461i
0.7995 + 0.2450i
0.8050 + 0.2439i
0.8105 + 0.2426i
0.8158 + 0.2412i
0.8212 + 0.2397i
0.8264 + 0.2380i
0.8316 + 0.2363i
0.8367 + 0.2345i
0.8417 + 0.2326i
0.8467 + 0.2306i
0.8515 + 0.2285i
0.8563 + 0.2263i
0.8610 + 0.2240i
0.8655 + 0.2217i
0.8700 + 0.2193i
0.8744 + 0.2169i
0.8787 + 0.2143i
0.8829 + 0.2118i
0.8869 + 0.2092i
0.8909 + 0.2065i
0.8948 + 0.2038i
0.8986 + 0.2011i
0.9022 + 0.1983i
0.9058 + 0.1955i
0.9093 + 0.1927i
0.9126 + 0.1899i
0.9159 + 0.1870i
0.9191 + 0.1841i
0.9222 + 0.1813i
0.9251 + 0.1784i
0.9280 + 0.1755i
0.9308 + 0.1726i
0.9335 + 0.1698i
0.9361 + 0.1669i
0.9386 + 0.1640i
0.9411 + 0.1612i
0.9434 + 0.1584i
0.9457 + 0.1556i
0.9479 + 0.1528i
0.9500 + 0.1500i
0.9520 + 0.1472i
0.9540 + 0.1445i
0.9559 + 0.1418i
0.9577 + 0.1391i
0.9595 + 0.1365i
0.9611 + 0.1339i
0.9628 + 0.1313i
0.9643 + 0.1287i
0.9658 + 0.1262i
0.9672 + 0.1237i
0.9686 + 0.1212i
0.9700 + 0.1188i
0.9712 + 0.1164i
0.9725 + 0.1141i
0.9736 + 0.1118i
0.9748 + 0.1095i
0.9758 + 0.1072i
0.9769 + 0.1050i
0.9779 + 0.1028i
0.9788 + 0.1007i
0.9797 + 0.0986i
0.9806 + 0.0965i
0.9815 + 0.0945i
0.9823 + 0.0925i
0.9830 + 0.0905i
0.9838 + 0.0886i
0.9845 + 0.0867i
0.9852 + 0.0849i
0.9858 + 0.0830i
0.9864 + 0.0813i
0.9870 + 0.0795i
0.9876 + 0.0778i
0.9881 + 0.0761i
0.9887 + 0.0744i
0.9892 + 0.0728i
0.9896 + 0.0712i
0.9901 + 0.0697i
0.9905 + 0.0682i
0.9909 + 0.0667i
0.9913 + 0.0652i
0.9917 + 0.0638i
0.9921 + 0.0624i
0.9924 + 0.0610i
0.9928 + 0.0596i
0.9931 + 0.0583i
0.9934 + 0.0570i
0.9937 + 0.0558i
0.9940 + 0.0545i
0.9943 + 0.0533i
0.9945 + 0.0521i
0.9948 + 0.0510i
0.9950 + 0.0498i
0.9952 + 0.0487i
0.9954 + 0.0476i
0.9956 + 0.0466i
0.9958 + 0.0455i
0.9960 + 0.0445i
0.9962 + 0.0435i
0.9964 + 0.0425i
0.9965 + 0.0416i
0.9967 + 0.0406i
0.9968 + 0.0397i
0.9970 + 0.0388i
0.9971 + 0.0380i
0.9972 + 0.0371i
0.9974 + 0.0363i
0.9975 + 0.0355i
0.9976 + 0.0347i
0.9977 + 0.0339i
0.9978 + 0.0331i
0.9979 + 0.0324i
0.9980 + 0.0316i
0.9981 + 0.0309i
0.9982 + 0.0302i
0.9982 + 0.0295i
0.9983 + 0.0289i
0.9984 + 0.0282i
0.9985 + 0.0276i
0.9985 + 0.0269i
0.9986 + 0.0263i
0.9987 + 0.0257i
0.9987 + 0.0252i
0.9988 + 0.0246i
0.9988 + 0.0240i
0.9989 + 0.0235i
0.9989 + 0.0230i
0.9990 + 0.0224i
0.9990 + 0.0219i
0.9991 + 0.0214i
0.9991 + 0.0209i
0.9992 + 0.0205i
0.9992 + 0.0200i
0.9992 + 0.0196i
0.9993 + 0.0191i
0.9993 + 0.0187i
0.9993 + 0.0182i
0.9994 + 0.0178i
0.9994 + 0.0174i
0.9994 + 0.0170i
0.9994 + 0.0166i
0.9995 + 0.0163i
0.9995 + 0.0159i
Sizes = [size(T2.FreqHz); size(Rsp)]
Sizes = 2×2
301 1
301 1
sysfr = idfrd(Rsp,T2.FreqHz,0,'FrequencyUnit','Hz') % Create System Response Data Object
sysfr =
IDFRD model.
Contains Frequency Response Data for 1 output(s) and 1 input(s).
Response data is available at 301 frequency points, ranging from 1000 Hz to 1e+06 Hz.
Status:
Created by direct construction or transformation. Not estimated.
sys_ss = ssest(sysfr, 2) % State Space Realisation
sys_ss =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 -2e+05 1.087e+13
x2 -1.526e-18 -1.79e+21
B =
u1
x1 -6.066e-15
x2 3.436e+10
C =
x1 x2
y1 -479.5 5.21e+10
D =
u1
y1 0
K =
y1
x1 0
x2 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 8
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on frequency response data "sysfr".
Fit to estimation data: 100%
FPE: 1.01e-30, MSE: 9.839e-31
figure
compare(sysfr, sys_ss)
sys_tf = tfest(sysfr, 1,1) % Transfer Function Realisation
sys_tf =
s + 1e05
----------
s + 200000
Continuous-time identified transfer function.
Parameterization:
Number of poles: 1 Number of zeros: 1
Number of free coefficients: 3
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using TFEST on frequency response data "sysfr".
Fit to estimation data: 100%
FPE: 1.251e-31, MSE: 1.226e-31
figure
compare(sysfr, sys_tf)
figure
pzmap(sys_ss)
grid on
format long E
Poles = pole(sys_ss)
Poles = 2×1
1.0e+00 *
-2.000000000000003e+05
-1.790281097801373e+21
Zeros = zero(sys_ss)
Zeros =
-9.999999933194378e+04
figure
nyquist(sys_ss)
figure
impulse(sys_ss)
figure
step(sys_ss)
The state space realisation had no problem with the order, however the transfer function realisation does.
This is interesting!
.
francesco baldi
on 26 Dec 2021
i'm sorry for the number of questions i'm asking you, i hope it is the last one:
let's assume that i succesfully exported the .txt file of my transfer function (H) from spice to Matlab, and i can see the Bode diagrams. Now, i need to use the values of H to calculate other parameters (G). For example, i need to compute this operation: G = H*100/(1 - H). Do i need to estimate the state space reasilation and find the transfer function of H (as we did), or there was a way to cumpute this operation without writing all this code but only with the Bode diagram exported from Spice?
Star Strider
on 26 Dec 2021
I remember something like that from classical control. (I have done very little with classical control, and mostly use modern control with what I do.)
Using the transfer function realisation for what I believe to be ‘H’ here —
s + 1e05
----------
s + 200000
the Symbolic Math Toolbox makes this relatively straightforward —
syms s
H = (s + 1e05 ) / (s + 200000)
H =
G = H*100/(1 - H)
G =
G = simplifyFraction(G)
G =
GdB = vpa(20*log10(abs(G)))
GdB =
figure
hfp = fplot(G, [0 1E+5]);
Xv = hfp.XData
Xv = 1×45
1.0e+05 *
0 0.0209 0.0455 0.0692 0.0909 0.1132 0.1364 0.1614 0.1818 0.2071 0.2273 0.2492 0.2727 0.2946 0.3182 0.3435 0.3636 0.3880 0.4091 0.4330 0.4545 0.4771 0.5000 0.5227 0.5455 0.5691 0.5909 0.6155 0.6364 0.6587
Yv = hfp.YData
Yv = 1×45
100.0000 102.0855 104.5455 106.9249 109.0909 111.3208 113.6364 116.1441 118.1818 120.7148 122.7273 124.9198 127.2727 129.4575 131.8182 134.3534 136.3636 138.8011 140.9091 143.3013 145.4545 147.7062 150.0000 152.2733 154.5455 156.9085 159.0909 161.5458 163.6364 165.8701
grid
xlabel('Frequency (Hz)')
ylabel('Absolute Amplitude')
figure
semilogx(Xv, Yv, 'LineWidth',2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude (dB)')
(I had problems with fplot and the logarithmic x-axis, so I extracted the data and plotted it using semilogx.)
I am not exactly certain what the problem is, since the Symbolic Math Toolbox will do all the ‘heavy lifting’ here to calculate the desired result. That of course will work with other transfer functions as well.
.
More Answers (0)
See Also
Categories
Find more on Get Started with Control System Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)