How to plot LTspice graph in Matlab in this case?

14 ビュー (過去 30 日間)
Huihong
Huihong 2023 年 8 月 15 日
コメント済み: Star Strider 2023 年 8 月 16 日
Hello,
I'm trying to use matlab to plot the bode plot exported from LTspice. The .txt file as well as my code is added below. I wonder why matlab keep warning me that "plot" is not proper, but I can't fix it. I really appreciate it if anyone can tell me how to solve it. And my code is listed below.
plot (Freq1,Vvo1);
hold on
xlabel('Freq (Hz)');
ylabel('Magnitude (dB)');
grid on

採用された回答

Star Strider
Star Strider 2023 年 8 月 15 日
One approach —
T1 = readtable('final_all1.txt', 'VariableNamingRule','preserve')
T1 = 261×2 table
Freq. V(vo) _________ ___________________________________________________ 0.001 {'(8.14596880037347e+01dB,-1.08562817812189e-04°)'} 0.001122 {'(8.14596880035216e+01dB,-1.21809484544416e-04°)'} 0.0012589 {'(8.14596880032533e+01dB,-1.36672488873043e-04°)'} 0.0014125 {'(8.14596880029152e+01dB,-1.53349053729508e-04°)'} 0.0015849 {'(8.14596880024902e+01dB,-1.72060466847946e-04°)'} 0.0017783 {'(8.14596880019545e+01dB,-1.93055017100971e-04°)'} 0.0019953 {'(8.14596880012804e+01dB,-2.16611289116791e-04°)'} 0.0022387 {'(8.14596880004315e+01dB,-2.43041859892065e-04°)'} 0.0025119 {'(8.14596879993632e+01dB,-2.72697446447758e-04°)'} 0.0028184 {'(8.14596879980181e+01dB,-3.05971559559613e-04°)'} 0.0031623 {'(8.14596879963252e+01dB,-3.43305725305582e-04°)'} 0.0035481 {'(8.14596879941933e+01dB,-3.85195343705754e-04°)'} 0.0039811 {'(8.14596879915092e+01dB,-4.32196262177601e-04°)'} 0.0044668 {'(8.14596879881307e+01dB,-4.84932151008020e-04°)'} 0.0050119 {'(8.14596879838771e+01dB,-5.44102778676502e-04°)'} 0.0056234 {'(8.14596879785223e+01dB,-6.10493296788157e-04°)'}
T1.MagdB = str2double(extractBetween(T1{:,2},'(','dB'));
T1.PhaseDeg = str2double(extractBetween(T1{:,2},',','°'))
T1 = 261×4 table
Freq. V(vo) MagdB PhaseDeg _________ ___________________________________________________ _____ ___________ 0.001 {'(8.14596880037347e+01dB,-1.08562817812189e-04°)'} 81.46 -0.00010856 0.001122 {'(8.14596880035216e+01dB,-1.21809484544416e-04°)'} 81.46 -0.00012181 0.0012589 {'(8.14596880032533e+01dB,-1.36672488873043e-04°)'} 81.46 -0.00013667 0.0014125 {'(8.14596880029152e+01dB,-1.53349053729508e-04°)'} 81.46 -0.00015335 0.0015849 {'(8.14596880024902e+01dB,-1.72060466847946e-04°)'} 81.46 -0.00017206 0.0017783 {'(8.14596880019545e+01dB,-1.93055017100971e-04°)'} 81.46 -0.00019306 0.0019953 {'(8.14596880012804e+01dB,-2.16611289116791e-04°)'} 81.46 -0.00021661 0.0022387 {'(8.14596880004315e+01dB,-2.43041859892065e-04°)'} 81.46 -0.00024304 0.0025119 {'(8.14596879993632e+01dB,-2.72697446447758e-04°)'} 81.46 -0.0002727 0.0028184 {'(8.14596879980181e+01dB,-3.05971559559613e-04°)'} 81.46 -0.00030597 0.0031623 {'(8.14596879963252e+01dB,-3.43305725305582e-04°)'} 81.46 -0.00034331 0.0035481 {'(8.14596879941933e+01dB,-3.85195343705754e-04°)'} 81.46 -0.0003852 0.0039811 {'(8.14596879915092e+01dB,-4.32196262177601e-04°)'} 81.46 -0.0004322 0.0044668 {'(8.14596879881307e+01dB,-4.84932151008020e-04°)'} 81.46 -0.00048493 0.0050119 {'(8.14596879838771e+01dB,-5.44102778676502e-04°)'} 81.46 -0.0005441 0.0056234 {'(8.14596879785223e+01dB,-6.10493296788157e-04°)'} 81.46 -0.00061049
figure
subplot(2,1,1)
semilogx(T1.('Freq.'), T1.MagdB)
grid
ylabel('Magnitude (dB)')
subplot(2,1,2)
semilogx(T1.('Freq.'), T1.PhaseDeg)
ylabel('Phase (°)')
grid
xlabel('Frequency')
sgtitle('Bode Plot of LTSpice Data')
There may be more efficient ways to extract the data, however this works.
To unwrap the phase data:
T1.PhaseDegU = rad2deg(unwrap(deg2rad(T1.PhaseDeg)))
and plot that instead for the phase. Otherwise, just leave it as it is.
.
  2 件のコメント
Huihong
Huihong 2023 年 8 月 16 日
Thanks a lot for your help!
Star Strider
Star Strider 2023 年 8 月 16 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by