Plotting LTSpice bodeplot in Matlab

My problem is identical with the question in this question on this forum.
I've tried to implement the accepted solution, but it does not work. The variable Dc is empty, and the resulting plot is an empty plot with the axes shown. I've tried to read the documentation for fopen and textscan, but cannot find an answer to what I might be doing wrong.
I use the R2020a version, so I should be up to date.
filename = 'RVDT_feedback_filter_V1.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')

 Accepted Answer

This is not the most elegant or efficient way to read and plot this, however it has the advantage of working, so I’m using it —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/757614/RVDT_feedback_filter_V1.txt', 'VariableNamingRule','preserve')
T1 = 4001×2 table
Freq. V(n002) ______ ______________________________________________________ 10 {'(-6.10503986437257e+001dB,-9.00345432737350e+001°)'} 10.023 {'(-6.10303738458341e+001dB,-9.00346229875252e+001°)'} 10.046 {'(-6.10103489334093e+001dB,-9.00347028856527e+001°)'} 10.069 {'(-6.09903239059221e+001dB,-9.00347829685466e+001°)'} 10.093 {'(-6.09702987628407e+001dB,-9.00348632366365e+001°)'} 10.116 {'(-6.09502735036309e+001dB,-9.00349436903537e+001°)'} 10.139 {'(-6.09302481277559e+001dB,-9.00350243301301e+001°)'} 10.162 {'(-6.09102226346766e+001dB,-9.00351051563988e+001°)'} 10.186 {'(-6.08901970238513e+001dB,-9.00351861695938e+001°)'} 10.209 {'(-6.08701712947358e+001dB,-9.00352673701502e+001°)'} 10.233 {'(-6.08501454467833e+001dB,-9.00353487585042e+001°)'} 10.257 {'(-6.08301194794448e+001dB,-9.00354303350928e+001°)'} 10.28 {'(-6.08100933921683e+001dB,-9.00355121003543e+001°)'} 10.304 {'(-6.07900671843995e+001dB,-9.00355940547280e+001°)'} 10.328 {'(-6.07700408555816e+001dB,-9.00356761986540e+001°)'} 10.351 {'(-6.07500144051551e+001dB,-9.00357585325738e+001°)'}
Vn002 = T1.('V(n002)');
for k = 1:numel(Vn002)
V(:,k) = sscanf(Vn002{k}, '(%fdB,%f)');
end
figure
subplot(2,1,1)
semilogx(T1.('Freq.'), V(1,:))
grid
ylabel('Magnitude (dB)')
subplot(2,1,2)
semilogx(T1.('Freq.'), V(2,:))
grid
xlabel('Frequency (Hz)')
ylabel('Phase (°)')
sgtitle('V(n002)')
Experiment to get different results.
.

More Answers (0)

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!