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 Octave console.
% create filename independent path to scope mdl = plecs('get', '', 'CurrentCircuit'); scope = [mdl '/Scope']; % create simStruct with field 'ModelVars' mdlVars = struct('varL', 50e-6); simStruct = struct('ModelVars', mdlVars); plecs('scope', scope, 'ClearTraces'); inductorValues = [50, 100, 200]; for ix = 1:length(inductorValues) % set value for L1 simStruct.ModelVars.varL=inductorValues(ix) * 1e-6; % start simulation, return probed signal values in 'out' out = plecs('simulate', simStruct); % add labeled scope run plecs('scope', scope, 'HoldTrace', ['L=' mat2str(inductorValues(ix)) 'μH']); % find maximum current value and index [maxv, maxidx] = max(out.Values(1,:)); % Output maximum current values to Octave console printf('Max current for L=%dμH: %fA at %fs\n', inductorValues(ix), maxv, out.Time(maxidx)); end
To run the scripted simulation demonstration, select Simulation scripts... from the Simulation menu and run the Parameter Sweep script. The Octave console can be accessed by selecting Show Console from the Window menu.