Open this model

Buck Converter with Parameter Sweep

This demonstration is based on the Buck converter with analog controls demo model. It performs a parameter sweep by modifying the value of inductor L1 from a simulation script.

For each parameter value a simulation is performed. The result of each simulation is displayed as a new trace in the scope. The script also analyzes the simulation result and prints the peak current value into the MATLAB command window.

% create path to scope
scope = ('plBuckParamSweep/Circuit/Scope');

% clear previous traces from scope
plecs('scope', scope, 'ClearTraces');

% parametric values to be swept
inductorValues = [50, 100, 200];

for ix = 1:length(inductorValues)
  % set value for L1
  varL = inductorValues(ix) * 1e-6;
  % start simulation, return probed signal values to workspace
  [t, x, y] = sim('plBuckParamSweep');
  % add labeled scope run
  plecs('scope', scope, 'HoldTrace', ['L=' mat2str(inductorValues(ix)) 'μH']);
  % find maximum current value and index
  [maxv, maxidx] = max(y(:,1));
  % Output maximum current values to MATLAB command window
  fprintf('Max current for L=%dμH: %fA at %fs\n', inductorValues(ix), maxv, t(maxidx));
end

To run the scripted simulation demonstration, first open this model. Then select Open from the File menu and browse to the m-file "plParamSweep.m". You may need to change the file format to "All MATLAB files" to open the m-file. You can then view the script and run it.