How to plot LTspice graph in Matlab in this case?
18 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 15 Aug 2023
One approach —
T1 = readtable('final_all1.txt', 'VariableNamingRule','preserve')
T1.MagdB = str2double(extractBetween(T1{:,2},'(','dB'));
T1.PhaseDeg = str2double(extractBetween(T1{:,2},',','°'))
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 Comments
More Answers (0)
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!