how to find the transfer function from LTspice

48 次查看(过去 30 天)
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?

采纳的回答

Star Strider
Star Strider 2021-12-23
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 个评论
francesco baldi
francesco baldi 2021-12-26
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
Star Strider 2021-12-26
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.
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Control System Toolbox 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by