Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

How to use script to run multiple AC sweep simulations?

0 votes
1,210 views

Hello,

I would like to know if there is a way to use an script to run multiple AC sweep simulations in PLECS standalone.

I want to be able to run an AC sweep simulation for multiple changes of a parameter. For example, in the attached figure I have a an RC circuit and I am obtaining the frequency response for different capacitance values C=1,C=10, and C=100 (to get the attached figure I ran the simulation 3 times manually.)

I notice that there is an example called "Buck Converter with Parameter Sweep" which explains how to make the parameter change; therefore, I would like to know how to call the AC-sweep analysis directly from the script to make a parameter sweep while running multiple AC-sweeps for each case. 

Kind regards.

asked Oct 19, 2020 by Erick P. (25 points)

1 Answer

+1 vote

It looks like you have already found the "Frequency Response of Passive Circuit" demo model included with PLECS 4.4.  Did you open the included simulation script?  You can access it from the Simulation + Simulation Scripts menu.

The key command here is:

plecs('analyze', 'AC Sweep', simStruct); % start AC Sweep analysis

where 'AC Sweep' refers to the Description field of the preconfigured Analysis Tool.  The scope data is read from a script.

Another good reference to refer to is the "Simulation Scripts in PLECS Standalone" section of the user manual.  The "Starting an Analysis" section of the help describes an alternative to reading the scope data, where the transfer function is returned directly as an array.

 

answered Oct 19, 2020 by Bryan Lieblick (1,841 points)

Thank you.

I haven't noticed that the example has the script with exactly what I needed.

I have an additional query. Is it possible to change the magnitude axis of the AC analysis scope to display results in linear format? It looks like the default configuration is in dB. Is there any way to change it?

 

Within PLECS there is not a way to change the magnitude scale to a linear format.  You'll have to use the return values from the plecs('analyze',...) command.  As of PLECS 4.4 you can now generate Octave plots from within PLECS, or you could save the results to a file for post processing in your tool of choice. 

Here's a sample script:

% parameter definitions, create simStruct with field 'ModelVars'
mdlVars = struct('R', 1, 'C', 100e-6, 'fc', 10e3);  
simStruct = struct('ModelVars', mdlVars);  
 
% clear all traces in frequency response plot window in the current model
plecs('scope', './Analyses/AC Sweep', 'ClearTraces');
 
fcValues = [10e2, 10e3, 10e4]; % cutoff frequencies
legendValues = {};

for ix = 1:length(fcValues)
  simStruct.ModelVars.C = 1/(2*pi*simStruct.ModelVars.R*fcValues(ix)); % RC filter capacitance
  simResult=plecs('analyze', 'AC Sweep', simStruct); % start AC Sweep analysis
  legendStr = ['fc=' mat2str(fcValues(ix)/1000) 'kHz'];
  legendValues(ix) = legendStr;
  plecs('scope', './Analyses/AC Sweep', 'HoldTrace', legendStr); % hold and label trace
  subplot(2,1,1);
  semilogx(simResult.F,abs(simResult.Gr+1i*simResult.Gi));
  hold on;
  subplot(2,1,2);
  semilogx(simResult.F,angle(simResult.Gr+1i*simResult.Gi)*180/pi);
  hold on;
end

% Label plots
subplot(2,1,1);
title('Example of Bode Plot with Linear Magnitude');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
legend(legendValues);
subplot(2,1,2);
xlabel('Frequency (Hz)');
ylabel('Phase (deg)');
legend(legendValues);

Here's the resulting output:

...