이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to plot transfer function exported from LTSpice
조회 수: 20 (최근 30일)
이전 댓글 표시
hi there, i used the following code to plot the bode diagram of a trasnfer function exported from LTSpice:
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')
the fact is that it works well if i export the data from Spice in polar coordinates (dB and deg). Now i'd like to obtain the same result by exporting the data in cartesian coordinates (real and imm), and i don't know what to modify in this code. i attach the data set i'd like to plot.
답변 (1개)
Star Strider
2021년 12월 26일
편집: Star Strider
2021년 12월 26일
I have no idea what would be necessary for LTSPice to export in Cartesian coordiantes, however to convert them to Cartesian in MATLAB is straightforward, by extracting the real and imag components of the ‘Rsp’ vector as the ‘Real’ and ‘Imag’ vectors (this also identifies the system, since I had that code ready to go) —
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/844455/Draft3.txt';
T1 = readtable(filename, 'VariableNamingRule','preserve')
V2c = cellfun(@(x)sscanf(x, '%f\t%f'), T1.Var1, 'Unif',0);
V2m = [cell2mat(V2c')' T1.Var2]
T2 = table('Size',[size(T1.Var1,1) 3],'VariableTypes',{'double','double','double'}, 'VariableNames',{'FreqHz','MagndB','PhasDg'});
T2.FreqHz = V2m(:,1);
T2.MagndB = V2m(:,2);
T2.PhasDg = V2m(:,3)
D = table2array(T2)
Mag = db2mag(T2.MagndB); % Absolute MAgnitude (Not Decibels)
Phs = deg2rad(T2.PhasDg); % Radian Phase Angle
Rsp = Mag.*exp(1j*Phs)
Real = real(Rsp) % REAL Part Of Complex Response Vector
Imag = imag(Rsp) % IMAG Part Of Complex Response Vector
Sizes = [size(T2.FreqHz); size(Rsp)]
sysfr = idfrd(Rsp,T2.FreqHz,0,'FrequencyUnit','Hz') % Create System Response Data Object
sys_ss = ssest(sysfr, 3) % State Space Realisation
figure
compare(sysfr, sys_ss)
sys_tf = tfest(sysfr, 2, 2) % Transfer Function Realisation
figure
compare(sysfr, sys_tf)
figure
pzmap(sys_ss)
grid on
format long E
Poles = pole(sys_ss)
Zeros = zero(sys_ss)
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')
EDIT — (26 Dec 2021 at 13:24)
Corrected name provided to readtable, and provided subsequent correct parsing of the resulting table.
With those changes, my code runs without error and produces the correct results.
.
댓글 수: 9
Star Strider
2021년 12월 26일
I copied tther correct file to ‘filename’ however forgot to substitute ‘filename’ in the readtable call. Also, the textscan format string no longer works with this file, as the data are significantly different.
My cellfun call:
V2c = cellfun(@(x)sscanf(x, '%f\t%f'), T1.Var1, 'Unif',0);
converts it correctly.
This is significantly different in format from the previous files, so it required a different way to parse them.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/844455/Draft3.txt';
T1 = readtable(filename, 'VariableNamingRule','preserve')
T1 = 401×2 table
Var1 Var2
_______________________________________________ ___________
{'1.00000000000000e+001→4.99999950651983e-001'} -0.00015708
{'1.02329299228075e+001→4.99999948326283e-001'} -0.00016074
{'1.04712854805090e+001→4.99999945890976e-001'} -0.00016448
{'1.07151930523761e+001→4.99999943340896e-001'} -0.00016831
{'1.09647819614319e+001→4.99999940670635e-001'} -0.00017223
{'1.12201845430196e+001→4.99999937874529e-001'} -0.00017625
{'1.14815362149688e+001→4.99999934946646e-001'} -0.00018035
{'1.17489755493953e+001→4.99999931880776e-001'} -0.00018455
{'1.20226443461741e+001→4.99999928670417e-001'} -0.00018885
{'1.23026877081238e+001→4.99999925308757e-001'} -0.00019325
{'1.25892541179417e+001→4.99999921788668e-001'} -0.00019775
{'1.28824955169313e+001→4.99999918102682e-001'} -0.00020236
{'1.31825673855641e+001→4.99999914242981e-001'} -0.00020707
{'1.34896288259165e+001→4.99999910201378e-001'} -0.00021189
{'1.38038426460288e+001→4.99999905969300e-001'} -0.00021683
{'1.41253754462275e+001→4.99999901537771e-001'} -0.00022188
V2c = cellfun(@(x)sscanf(x, '%f\t%f'), T1.Var1, 'Unif',0);
V2m = [cell2mat(V2c')' T1.Var2]
V2m = 401×3
10.0000 0.5000 -0.0002
10.2329 0.5000 -0.0002
10.4713 0.5000 -0.0002
10.7152 0.5000 -0.0002
10.9648 0.5000 -0.0002
11.2202 0.5000 -0.0002
11.4815 0.5000 -0.0002
11.7490 0.5000 -0.0002
12.0226 0.5000 -0.0002
12.3027 0.5000 -0.0002
T2 = table('Size',[size(T1.Var1,1) 3],'VariableTypes',{'double','double','double'}, 'VariableNames',{'FreqHz','MagndB','PhasDg'});
T2.FreqHz = V2m(:,1);
T2.MagndB = V2m(:,2);
T2.PhasDg = V2m(:,3)
T2 = 401×3 table
FreqHz MagndB PhasDg
______ ______ ___________
10 0.5 -0.00015708
10.233 0.5 -0.00016074
10.471 0.5 -0.00016448
10.715 0.5 -0.00016831
10.965 0.5 -0.00017223
11.22 0.5 -0.00017625
11.482 0.5 -0.00018035
11.749 0.5 -0.00018455
12.023 0.5 -0.00018885
12.303 0.5 -0.00019325
12.589 0.5 -0.00019775
12.882 0.5 -0.00020236
13.183 0.5 -0.00020707
13.49 0.5 -0.00021189
13.804 0.5 -0.00021683
14.125 0.5 -0.00022188
D = table2array(T2)
D = 401×3
10.0000 0.5000 -0.0002
10.2329 0.5000 -0.0002
10.4713 0.5000 -0.0002
10.7152 0.5000 -0.0002
10.9648 0.5000 -0.0002
11.2202 0.5000 -0.0002
11.4815 0.5000 -0.0002
11.7490 0.5000 -0.0002
12.0226 0.5000 -0.0002
12.3027 0.5000 -0.0002
Mag = db2mag(T2.MagndB); % Absolute MAgnitude (Not Decibels)
Phs = deg2rad(T2.PhasDg); % Radian Phase Angle
Rsp = Mag.*exp(1j*Phs)
Rsp =
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0000i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0593 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0001i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0002i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0003i
1.0592 - 0.0004i
1.0592 - 0.0004i
1.0592 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0004i
1.0591 - 0.0005i
1.0591 - 0.0005i
1.0591 - 0.0005i
1.0591 - 0.0005i
1.0591 - 0.0005i
1.0591 - 0.0005i
1.0591 - 0.0005i
1.0590 - 0.0005i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0590 - 0.0006i
1.0589 - 0.0007i
1.0589 - 0.0007i
1.0589 - 0.0007i
1.0589 - 0.0007i
1.0589 - 0.0007i
1.0589 - 0.0007i
1.0588 - 0.0008i
1.0588 - 0.0008i
1.0588 - 0.0008i
1.0588 - 0.0008i
1.0588 - 0.0008i
1.0587 - 0.0008i
1.0587 - 0.0009i
1.0587 - 0.0009i
1.0587 - 0.0009i
1.0586 - 0.0009i
1.0586 - 0.0010i
1.0586 - 0.0010i
1.0585 - 0.0010i
1.0585 - 0.0010i
1.0585 - 0.0010i
1.0584 - 0.0011i
1.0584 - 0.0011i
1.0584 - 0.0011i
1.0583 - 0.0011i
1.0583 - 0.0012i
1.0582 - 0.0012i
1.0582 - 0.0012i
1.0581 - 0.0012i
1.0581 - 0.0013i
1.0580 - 0.0013i
1.0580 - 0.0013i
1.0579 - 0.0014i
1.0578 - 0.0014i
1.0578 - 0.0014i
1.0577 - 0.0014i
1.0576 - 0.0015i
1.0576 - 0.0015i
1.0575 - 0.0015i
1.0574 - 0.0016i
1.0573 - 0.0016i
1.0572 - 0.0017i
1.0571 - 0.0017i
1.0570 - 0.0017i
1.0569 - 0.0018i
1.0568 - 0.0018i
1.0567 - 0.0018i
1.0566 - 0.0019i
1.0565 - 0.0019i
1.0564 - 0.0020i
1.0563 - 0.0020i
1.0561 - 0.0020i
1.0560 - 0.0021i
1.0558 - 0.0021i
1.0557 - 0.0022i
1.0555 - 0.0022i
1.0554 - 0.0023i
1.0552 - 0.0023i
1.0550 - 0.0023i
1.0548 - 0.0024i
1.0546 - 0.0024i
1.0544 - 0.0025i
1.0542 - 0.0025i
1.0540 - 0.0026i
1.0538 - 0.0026i
1.0536 - 0.0027i
1.0533 - 0.0027i
1.0531 - 0.0028i
1.0528 - 0.0028i
1.0525 - 0.0029i
1.0523 - 0.0029i
1.0520 - 0.0030i
1.0517 - 0.0030i
1.0514 - 0.0031i
1.0510 - 0.0031i
1.0507 - 0.0032i
1.0504 - 0.0032i
1.0500 - 0.0033i
1.0496 - 0.0033i
1.0493 - 0.0034i
1.0489 - 0.0034i
1.0485 - 0.0035i
1.0481 - 0.0035i
1.0476 - 0.0036i
1.0472 - 0.0036i
1.0468 - 0.0037i
1.0463 - 0.0037i
1.0458 - 0.0038i
1.0453 - 0.0038i
1.0448 - 0.0039i
1.0443 - 0.0039i
1.0438 - 0.0040i
1.0433 - 0.0040i
1.0427 - 0.0041i
1.0422 - 0.0041i
1.0416 - 0.0041i
1.0410 - 0.0042i
1.0405 - 0.0042i
1.0399 - 0.0042i
1.0393 - 0.0043i
1.0386 - 0.0043i
1.0380 - 0.0043i
1.0374 - 0.0044i
1.0367 - 0.0044i
1.0361 - 0.0044i
1.0354 - 0.0044i
1.0348 - 0.0044i
1.0341 - 0.0044i
1.0335 - 0.0045i
1.0328 - 0.0045i
1.0321 - 0.0045i
1.0314 - 0.0045i
1.0307 - 0.0045i
1.0301 - 0.0045i
1.0294 - 0.0045i
1.0287 - 0.0045i
1.0280 - 0.0045i
1.0273 - 0.0045i
1.0267 - 0.0045i
1.0260 - 0.0045i
1.0253 - 0.0044i
1.0247 - 0.0044i
1.0240 - 0.0044i
1.0233 - 0.0044i
1.0227 - 0.0044i
1.0221 - 0.0043i
1.0214 - 0.0043i
1.0208 - 0.0043i
1.0202 - 0.0042i
1.0196 - 0.0042i
1.0190 - 0.0042i
1.0184 - 0.0041i
1.0178 - 0.0041i
1.0172 - 0.0041i
1.0167 - 0.0040i
1.0161 - 0.0040i
1.0156 - 0.0039i
1.0151 - 0.0039i
1.0146 - 0.0038i
1.0141 - 0.0038i
1.0136 - 0.0037i
1.0131 - 0.0037i
1.0126 - 0.0036i
1.0122 - 0.0036i
1.0117 - 0.0036i
1.0113 - 0.0035i
1.0109 - 0.0034i
1.0105 - 0.0034i
1.0101 - 0.0033i
1.0097 - 0.0033i
1.0094 - 0.0032i
1.0090 - 0.0032i
1.0087 - 0.0031i
1.0083 - 0.0031i
1.0080 - 0.0030i
1.0077 - 0.0030i
1.0074 - 0.0029i
1.0071 - 0.0029i
1.0068 - 0.0028i
1.0065 - 0.0028i
1.0063 - 0.0027i
1.0060 - 0.0027i
1.0058 - 0.0026i
1.0055 - 0.0026i
1.0053 - 0.0025i
Real = real(Rsp) % REAL Part Of Complex Response Vector
Real = 401×1
1.0593
1.0593
1.0593
1.0593
1.0593
1.0593
1.0593
1.0593
1.0593
1.0593
Imag = imag(Rsp) % IMAG Part Of Complex Response Vector
Imag = 401×1
1.0e+00 *
-0.0000
-0.0000
-0.0000
-0.0000
-0.0000
-0.0000
-0.0000
-0.0000
-0.0000
-0.0000
Sizes = [size(T2.FreqHz); size(Rsp)]
Sizes = 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, 3) % 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 x3
x1 -1.967e+05 4.001e+05 1.656e+08
x2 2.268e-07 1.976e+05 1.66e+08
x3 -8.426e-11 -8.339e-11 5.911e+11
B =
u1
x1 1.475e-10
x2 -1.957e-10
x3 1.049e+06
C =
x1 x2 x3
y1 1359 -1362 -5.638e+05
D =
u1
y1 0
K =
y1
x1 0
x2 0
x3 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 15
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on frequency response data "sysfr".
Fit to estimation data: 100%
FPE: 4.055e-14, MSE: 3.935e-14
figure
compare(sysfr, sys_ss)
sys_tf = tfest(sysfr, 2,2) % Transfer Function Realisation
sys_tf =
s^2 + 885.4 s - 4.117e10
------------------------
s^2 - 860.3 s - 3.887e10
Continuous-time identified transfer function.
Parameterization:
Number of poles: 2 Number of zeros: 2
Number of free coefficients: 5
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using TFEST on frequency response data "sysfr".
Fit to estimation data: 100%
FPE: 4.796e-14, MSE: 4.678e-14
figure
compare(sysfr, sys_tf)
figure
pzmap(sys_ss)
grid on
format long E
Poles = pole(sys_ss)
Poles = 3×1
1.0e+00 *
-1.967237778489041e+05
1.975767036132812e+05
5.911429745307852e+11
Zeros = zero(sys_ss)
Zeros = 2×1
1.0e+00 *
-2.033539159391936e+05
2.024607634016894e+05
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')
Everything now runs without error and the system is correctly identified. It took a few experiments to determine what the variables were, and where they were.
With the file correctly parsed, ‘Real’ and ‘Imag’ are correct, and the system is correctly identified
.
francesco baldi
2021년 12월 26일
that's not correct. Check the output of T2 table: you are threating the real part as it was modulus and the imaginary part as it was phase. In the draft3.txt i have frequency in the first column, real part of the transfer function in the second column and imaginary part of the transfer function in the third column.
Star Strider
2021년 12월 26일
I have no idea what is in the file, since the columns are not labeled. The code posted in the Question shed no light on this, and the textscan format string is completely inappropriate for this file, since there are no ‘dB’ or ‘°’ characters in it. The delimiters are also inconsistent.
The first 3 rows of the file (that has no header lines) are —
1.00000000000000e+001 4.99999950651983e-001,-1.57079617176353e-004
1.02329299228075e+001 4.99999948326283e-001,-1.60738470739046e-004
1.04712854805090e+001 4.99999945890976e-001,-1.64482549896060e-004
The first column appears to be frequency, the second column magnitude, and the third, phase. (It required some effort to parse the file correctly.) That asssumption works with respect to the identification part of the code as well.
My code appears to parse the data correctly and identify the systems correctly.
If I did not guess correctly what the file contained, it is because I had no reliable information to work with.
I will do my best to help, however I need to know what information is provided in the file so I can work with it correctly.
francesco baldi
2021년 12월 26일
the first column is frequency, the second is the value of the real part of the transfer function, and the third is the value of the imaginary part of the transfer function.
Star Strider
2021년 12월 26일
편집: Star Strider
2021년 12월 26일
In that instance, only a few changes in my code are necessary, those being to construct the response vector ‘Rsp’ using the real and imaginary parts of the signal —
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/844455/Draft3.txt';
T1 = readtable(filename, 'VariableNamingRule','preserve')
T1 = 401×2 table
Var1 Var2
_______________________________________________ ___________
{'1.00000000000000e+001→4.99999950651983e-001'} -0.00015708
{'1.02329299228075e+001→4.99999948326283e-001'} -0.00016074
{'1.04712854805090e+001→4.99999945890976e-001'} -0.00016448
{'1.07151930523761e+001→4.99999943340896e-001'} -0.00016831
{'1.09647819614319e+001→4.99999940670635e-001'} -0.00017223
{'1.12201845430196e+001→4.99999937874529e-001'} -0.00017625
{'1.14815362149688e+001→4.99999934946646e-001'} -0.00018035
{'1.17489755493953e+001→4.99999931880776e-001'} -0.00018455
{'1.20226443461741e+001→4.99999928670417e-001'} -0.00018885
{'1.23026877081238e+001→4.99999925308757e-001'} -0.00019325
{'1.25892541179417e+001→4.99999921788668e-001'} -0.00019775
{'1.28824955169313e+001→4.99999918102682e-001'} -0.00020236
{'1.31825673855641e+001→4.99999914242981e-001'} -0.00020707
{'1.34896288259165e+001→4.99999910201378e-001'} -0.00021189
{'1.38038426460288e+001→4.99999905969300e-001'} -0.00021683
{'1.41253754462275e+001→4.99999901537771e-001'} -0.00022188
V2c = cellfun(@(x)sscanf(x, '%f\t%f'), T1.Var1, 'Unif',0);
V2m = [cell2mat(V2c')' T1.Var2]
V2m = 401×3
10.0000 0.5000 -0.0002
10.2329 0.5000 -0.0002
10.4713 0.5000 -0.0002
10.7152 0.5000 -0.0002
10.9648 0.5000 -0.0002
11.2202 0.5000 -0.0002
11.4815 0.5000 -0.0002
11.7490 0.5000 -0.0002
12.0226 0.5000 -0.0002
12.3027 0.5000 -0.0002
T2 = table('Size',[size(T1.Var1,1) 3],'VariableTypes',{'double','double','double'}, 'VariableNames',{'FreqHz','Real','Imag'});
T2.FreqHz = V2m(:,1);
T2.Real = V2m(:,2);
T2.Imag = V2m(:,3)
T2 = 401×3 table
FreqHz Real Imag
______ ____ ___________
10 0.5 -0.00015708
10.233 0.5 -0.00016074
10.471 0.5 -0.00016448
10.715 0.5 -0.00016831
10.965 0.5 -0.00017223
11.22 0.5 -0.00017625
11.482 0.5 -0.00018035
11.749 0.5 -0.00018455
12.023 0.5 -0.00018885
12.303 0.5 -0.00019325
12.589 0.5 -0.00019775
12.882 0.5 -0.00020236
13.183 0.5 -0.00020707
13.49 0.5 -0.00021189
13.804 0.5 -0.00021683
14.125 0.5 -0.00022188
D = table2array(T2)
D = 401×3
10.0000 0.5000 -0.0002
10.2329 0.5000 -0.0002
10.4713 0.5000 -0.0002
10.7152 0.5000 -0.0002
10.9648 0.5000 -0.0002
11.2202 0.5000 -0.0002
11.4815 0.5000 -0.0002
11.7490 0.5000 -0.0002
12.0226 0.5000 -0.0002
12.3027 0.5000 -0.0002
Rsp = hypot(T2.Imag,T2.Real).*exp(1j*atan2(T2.Imag,T2.Real)) % Create Complex Response Vector
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)]
Sizes = 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, 1) % 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
x1 -2e+05
B =
u1
x1 256
C =
x1
y1 390.6
D =
u1
y1 0
K =
y1
x1 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 3
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.281e-31, MSE: 1.268e-31
figure
compare(sysfr, sys_ss)
sys_tf = tfest(sysfr, 1,1) % Transfer Function Realisation
sys_tf =
1e05
--------
s + 2e05
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: 2.133e-31, MSE: 2.101e-31
figure
compare(sysfr, sys_tf)
figure
pzmap(sys_ss)
grid on
format long E
Poles = pole(sys_ss)
Poles =
-200000
Zeros = zero(sys_ss)
Zeros =
0×1 empty double column vector
figure
subplot(2,1,1)
semilogx(D(:,1), mag2db(abs(Rsp))) % Changed
title('Amplitude (dB)')
grid
subplot(2,1,2)
semilogx(D(:,1), angle(Rsp)) % Changed
title('Phase (°)')
grid
xlabel('Frequency')
This is now revealed to be a simple, first-order system.
EDIT — (26 Dec 2021 at 17:42)
Changed magnitude plot call to —
semilogx(D(:,1), mag2db(abs(Rsp)))
.
francesco baldi
2021년 12월 26일
thank you, this is what i was looking for. The only thing i don't understand is why amplitude and phase have those values on the y axis in the last plots of your code, they should be different.
Star Strider
2021년 12월 26일
In the magnitude plot, the y-axis scales are slightly different, so the curves appear slightly different. In the phase plots, the phase is ’off’ (at least in the plot) by 360° (so actually correct). This may be a minor bug in the System Identification Toolbox functions. (I intend to mention this to MathWorks.)
Since I apparently (finally) understood the contents of the file and parsed it correctly, I have no idea how they should be ‘different’. Unless there is other missing information, my code is correct and the plots are correct.
If this is incorrect, how should the plots look? How do they look when LTSpice plots them?
.
francesco baldi
2021년 12월 26일
the figure is correct, i don't understand why the scale on the y axis is different. The amplitude should go from -6dB to approximately -16dB, and the phase from 0 to approximately -77° in that range of frequencies.
Star Strider
2021년 12월 26일
In the last plot, I did not initially plot it in dB so I went back and edited the magnitude plot call to do that.
Now, all the plots agree.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Plot Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)