I am working on my simulation model in Simulink, where I am using "NN Predictive controller" module. I am trying to display the output of the NN Controller in Scope 2.
As you can see in the picture I have 2 signals from workspace. Both are discrete signals (sampling frequency 360 Hz) - both are vectors of 3600 rows.
In NN Predictive controller I have trained neural network to signals of the same size and set the sampling interval to 0.1.
When I run this simulation it runs approximately for 10 hours. Is there any way to minimize the simulation time without increasing the sampling interval in NN Controller? My second question: Why it takes so long?
If you need additional inforation about this model please let me know.
Thank you
Picture:
Use Accelerator Mode or Rapid Accelerator Mode in SL. You can switch the mode in the drop-down list where currently normal is selected.
In the Accelerator Mode part of the Modell is compiled. In the Rapid Accelerator Mode additionally all scopes are deactivated. For data evaluation you than need to store to the workspace and/or file and analyse it later.
See: http://de.mathworks.com/help/simulink/ug/how-the-acceleration-modes-work.html
and: http://de.mathworks.com/company/newsletters/articles/improving-simulation-performance-in-simulink.html
Related
I'm trying to simulate some electronics stuff in Simulink. Current mode PWM, so I need to compare MOSFET current with constant.
I tried to use "Relational operator" and "Compare to zero" with the same result.
In Continuous simulation mode, it reacts all over the place, like +-5e-6 sec and it is no help when the PWM signal is 20e-6 sec period.
When I run it in Discrete mode on 5e-8 sec sample time it works all right.
In tutorials, all electronics simulation runs in continuous mode, and calculating blocks seem to work right but not those blocks. Are there some settings for this?
The system is based on Simscape / Electrical / Specialized Power Systems blocks
Like this example: https://www.mathworks.com/help/physmod/sps/ug/boost-converter.html
I am new to Simscape. I would like to find a minimalist way to display voltage and current at various points in a circuit. Ideally just floating text labels with no 'wires' or connections visible. For example "Vbe 0.4v" or "Ic 20mA"
Currently I am using 3 standard blocks to achieve this and the circuit looks cluttered.
Is there a way to do what I want with some coding?
Currently, you have several options, some involve more work. Here are two ideas:
A) If your circuit is 3-phase, you can use the Busbar block and enable Frequency and Time solver in the Solver Configuration block, to display the initial voltages (and also power flows). This uses the Load-Flow Analysis feature starting R2019b. Check out this simple example.
B) Connect Voltage Sensor blocks to the nodes you want to sense voltage on, and connect the voltage PS output to a Simulink Display block, which will display the numerical value in real-time.
An outside Library (from PreScan) requests 200 Hz while my control plant model needs to run at 100 Hz. Therefore, my question is that how can I coordinate these two activities? My concern is that if I use 200Hz in Simulink, it may compromise my control plant’s fidelity.
Is it possible to set simulink time step as 1/100 while keep the outside library to run at 200Hz?
Simulink works perfectly happily with multi-rate models. The thing (it appears) that you don't understand is the difference between the overall model sample rate - i.e. the settings of your solver - and the sample rate of individual blocks within your model.
It's very typical to have some blocks in your model sampled at say 100Hz, while other parts of your model sampled at 200Hz. In this case you would choose a discrete solver and give it a sample time of 200Hz. The 200Hz blocks would get executed at every solver time step, while the 100Hz blocks would get executed every second solver time step.
You should look at the Sample Times in Systems section of the documentation.
You can use both explicit and implicit rate control in Simulink.
Sample Time
To set the fundamental sample time go to: Configuration Parameter>Solver>Fixed-step size. You can also use the Simulink API:
get_param(bdroot, 'FixedStep')
set_param(bdroot, 'FixedStep', '0.005') % 200Hz
Colors
To activate the Sample Time colors go to: Display>Sample Time>All. The Sample Time Legend will help you understanding how the implicit rate control works.
Sample time Option
You can control the tasking and sample time options via: Configuration Parameter>Solver>Tasking and sample time options.
At the beginning you can activate the automatic handling of rate transition for data transfer. Then you shall analyse what colors your model elements are and place the Rate-Transition blocks on the data signal lines between the model elements with different sample rates.
Now the rate control is implicit. If you use the function calls to explicitly call your subsystems at a required rate by involving a predefined scheduler, than the rate control is explicit.
You can open build in Simulink examples to see how it works:
sf_ladder_logic_scheduler
sf_loop_scheduler
I'm running a simulink model from simulink using matlab. My system is mainly in matlab, but I run the slx file and export the outputs to be used in matlab. The simulation is run for 48 seconds (1 second representing an hour). When I get the outputs, I'm expecting it to be the same quality as when I view it in simulink, but it's not. Here is an example of what my data looks like in simulink:
Here is how it looks like when I plot it in matlab (the number of samples becomes 307 when exported)
I tried to change the step size in simulink or change the solver, but this distorted my simulink output as the following.
My solver is ode45, how do I control the sampling frequency of my data so that I don't get different resolution after exporting it to matlab.
P.S Once I export it, I will interpolate the data so that I get samples in between the hours (a sample every minute instead of every hours). If I can do it at once by changing the step size then that will be perfect.
following your advice, I got this plot when I plot it vs time instead of samples
Thank you
You are using a variable-step solver (ODE45) and thus there is a very high chance you won't get a consistent sampling frequency.
The only way to ensure/control the sampling frequency is to use a fixed-step solver (ode4 for instance).
However, as to why the data looks different between the Simulink scope and the plotted data, for variable timestep solvers there is refine factor (configuration parameters -> Data Import/Export -> Additional Parameters). This is by default set to 1. Set this to 100 and you should get a more consistent-looking sample density.
What should be known about the refine factor?
To get smoother output and have a better time resolution, it is much faster to change the refine factor instead of reducing the step size.
When the refine factor is changed, the solvers generate additional points by evaluating a continuous extension formula at those points.
The refine factor applies to variable-step solvers and is most useful when you are using ode45.
Usually a value of 4 produces much smoother results.
https://blogs.mathworks.com/simulink/2009/07/14/refining-the-output-of-a-simulation/
https://uk.mathworks.com/help/simulink/gui/refine-factor.html
I am trying to fit a model to some measurements to model a battery.
Input of my model is current and the output is voltage of battery terminal.
I am using some 3D lookup tables in my model.
The breakpoints (dimensions) are: SOC (state of charge), temperature, and current amplitude and the table data in the impedance value of battery circuit elements.
The measurements are done using very small values for the current (in range of 2 A).
After completing the model I am supposed to validate the model using a standard signal for current input that includes very high current amplitudes (in range of 250 A).
Then comparing the output of my model (voltage) with the one from the measurements using that standard signal for the current.
Now when I try to run the model I get singularity error over one of the integrators. I am sure this is caused by the high amlitude of current as the input, but the problem is that I can not limit the amplitude using e.g. saturation blocks. I also tried to solve the problem with different solvers but could not fix the problem. Does anyone have an idea how to resolve this problem?
Please access my files from here.