How to convert LTspice text file to continuous graph?

3 views (last 30 days)
I designed an active low-pass filter with LTspice. Then, I imported the data from LTspice, but the LTspice graph file is a discrete value text file. So it didn't give me the exact value of the frequency I wanted.
What I want is to download the response results at the desired frequency. just like the example blow.
This example stores the response of the desired frequency in the transfer function.
Hz = [1e2, 5e2, 1e3]
H1 = tf([1], [R1*C1, 1]);
[magnitude, phase_open] = bode(H,w)
I would like to do something similar to this on the graph from LTspice.

Answers (1)

Abhishek Chakram
Abhishek Chakram on 24 Jan 2024
Hi WJ.S,
It appears to me that you want to convert LTspice text file to continuous graph. Here is how you can approach this:
  1. Import the LTspice simulation data into MATLAB. Ensure that the data is organized with frequency in one column and the corresponding magnitude and phase (or real and imaginary parts of the transfer function) in the other columns.
  2. Use MATLAB's interpolation functions, “interp1”, to find the response at the desired frequencies. This function allows you to interpolate between points in your dataset.
  3. Use the interpolated data to estimate the magnitude and phase response at your specified frequencies.
Here is a sample code for the same:
% Example frequencies from LTspice simulation (in Hz)
ltspice_freq = [90, 100, 200, 500, 1000, 2000, 5000]; % Replace with your actual data
% Example magnitude and phase data from LTspice simulation
ltspice_magnitude = [0.9, 0.85, 0.75, 0.5, 0.3, 0.1, 0.05]; % Replace with your actual data
ltspice_phase = [-10, -15, -30, -45, -60, -90, -120]; % Replace with your actual data
% Desired frequencies to estimate response
Hz = [1e2, 5e2, 1e3];
% Interpolate magnitude and phase at the desired frequencies
magnitude_interpolated = interp1(ltspice_freq, ltspice_magnitude, Hz, 'linear', 'extrap');
phase_interpolated = interp1(ltspice_freq, ltspice_phase, Hz, 'linear', 'extrap');
% Display the interpolated magnitude and phase
disp('Interpolated Magnitude:');
Interpolated Magnitude:
disp(magnitude_interpolated);
0.8500 0.5000 0.3000
disp('Interpolated Phase:');
Interpolated Phase:
disp(phase_interpolated);
-15 -45 -60
In the example above, “ltspice_freq”, “ltspice_magnitude”, and “ltspice_phase” are placeholders for your actual LTspice simulation data. Replace these with your actual data points. The "interp1" function is used to interpolate the magnitude and phase at the desired frequencies Hz.
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram

Categories

Find more on Live Scripts and Functions in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!