Plotting The bodee plots extracted from LTSPICE simulator

54 views (last 30 days)
Hello,
After I simulated a circuit using a LTSPICE simulator and got the bode plots, I wanted to plot these plots using Matlab, so I exported the bode plots to a TXT file (attached to this post) in order to be able to plot them after that using matlab.
after I put the .txt file in the matlab directory, I used the command "dlmread('Data.txt);", nevertheless, Matlab could not read the text file.
Is there a way so that I can read the file and plot it using Matlab?

Accepted Answer

Star Strider
Star Strider on 18 Apr 2019
Edited: Star Strider on 18 Apr 2019
MATLAB can read it, however it needs a bit of help in order to understand how to read it.
Try this:
fidi = fopen('Data.txt');
Dc = textscan(fidi, '%f(%fdB,%f°)', 'CollectOutput',1);
D = cell2mat(Dc);
figure
subplot(2,1,1)
plot(D(:,1), D(:,2))
title('Amplitude (dB)')
grid
subplot(2,1,2)
plot(D(:,1), D(:,3))
title('Phase (°)')
grid
xlabel('Frequency')
The frequency appears to be ‘D(:,1)’, amplitude ‘D(:,2)’, and phase ‘D(:,3)’ in my code. That reads the file correctly, and seems to produce the correct plot. See the documentation on textscan (link) to understand how it works and what my code does.
Experiment to get the result you want.
EDIT — (18 Apr 2019 at 11:22)
The plot calls can be improved slightly as:
figure
subplot(2,1,1)
semilogx(D(:,1), D(:,2))
ylabel('Amplitude (dB)')
grid
subplot(2,1,2)
semilogx(D(:,1), D(:,3))
ylabel('Phase (°)')
grid
xlabel('Frequency')
NOTE: Tthe frequency units are not stated in your file, so it is not possible to determine if they are Hz or rad/sec. The amplitude is clearly in dB so it is already log-transformed, and the phase is clearly in degrees (°).

More Answers (1)

UTKARSH JADLI
UTKARSH JADLI on 18 Apr 2019
Edited: UTKARSH JADLI on 18 Apr 2019
First of all, please separate the magnitude data with the phase data. Both are merged right now.
Then save the data with three separate variables namely as magnitude, phase and frequency. Then use the follwing code to plot them:
subplot(2,1,1), loglog(frequency,magnitude), grid on
xlabel 'Frequency (rad/s)', ylabel Magnitude
subplot(2,1,2), semilogx(frequency,phase), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'
Hope this will help you!!!
Regards
Utkarsh

Community Treasure Hunt

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

Start Hunting!