PeterFeicht / ltspice2matlab

LTspice2Matlab - Import LTspice data into MATLAB
BSD 2-Clause "Simplified" License
46 stars 17 forks source link

Unable to load .raw data with spice list directive #5

Open ethangoldstein opened 3 years ago

ethangoldstein commented 3 years ago

Hello,

I am able to load the .raw file when I run a basic .tran command. However, when I include a .step directive in the simulation I get the following error from MATLAB:

Error using reshape Size arguments must be real integers.

Error in LTspice2Matlab (line 531) raw_data.variable_mat = reshape(raw_data.variable_mat, mat_size(1), mat_size(2) / num_steps, num_steps);

Error in test (line 6) sr = LTspice2Matlab(path);

Any help would be greatley appreciated.

Thank You,

Ethan

yc-niu commented 2 years ago

I got the same error. Attached is an example file that comes with LTspiceXVII that can reproduce this error.

C:\Program Files\LTspiceXVII\examples\Educational\FRA\Eg1.asc Run simulation -> Eg1.raw

".tran 0 {5/Freq+.1m} .1m" in Eg1.asc can save computation burden significently, but it cause the simulation data points (and also the matrix size) vary depends the variable {Freq} along each step.

(line 531) "mat_size(2) / num_steps" is not compatible with this situation and causes the error.

I would appreciate taking consider this situation. Thank you.

YC Niu Eg1.zip

kunkun9527 commented 2 years ago

@ethangoldstein @yc-niu

I also had this problem recently, but finally solved it perfectly.

I guess the reason is because the length of the data is inconsistent, since LTSpice is a solver with variable step size.

The solution is to use the software "ltsputil.exe" to interpolate the data in the raw file to achieve a consistent step size. For the new version of LTSpice, you also need to use "ltsputil17raw4.exe" to convert raw files.

The above software can be easily found in google. Below is the code I use, just for reference:

cd/d D:\Circuit_results\sweep_new\verify ltsputil17raw4.exe fixed_frequency.raw converted_fixed_frequency.raw ltsputil.exe -eo converted_fixed_frequency.raw output_fixed_frequency.raw 40000

Note that they should run by CMD command, or use the batch file.

kunkun9527 commented 2 years ago

One more important step is to keep raw uncompressed, the following command can be used in LTSpice.

.opt plotwinsize=0

But this will greatly increase the raw file size.