Initial value of signal in Simulink model - matlab

I have some questions regarding the simulink model, below.
Given an input in In1, what is the initial input of the 1 tagged in red?
What is the meaning of the block 1/s tagged with 2 in red?

It may be easier to answer these questions in reverse:
2) What is the meaning of the block 1/s tagged with 2 in red?
Answer: This is the Integrator block. It outputs the integral of its input at the current time step. Note that at the first time step, it will output whatever you have specified as its initial condition. By default, I believe that the initial condition is 0. (See the linked doc above for more info on setting various parameters for this block, including initial condition).
1) Given an input in In1, what is the initial input of the 1 tagged in red?
Answer: The initial input at 1 is actually completely independent of In1. It will depend only on the initial conditions of the blocks that feed into it at a given timestep.
You have to take into consideration the execution order of the blocks. In this model, the first block to execute will probably be the integrator block that you have marked with a 2. Following this will be the next integrator block and the gain blocks that they feed. One of the last blocks to execute will actually be the Subtract block that In1 feeds into. This is because this Subtract block needs to know what its input are before it can do any sort of calculations on them, therefore, the other blocks need to execute first.
This may be a little bit confusing considering that there is a loop here and therefore the Subtract block ends up feeding in to the Integrator blocks. This ends up not being an issue because the Integrator blocks do not have direct-feedthrough. This means that the current output of the integrator is not a direct function of the current input. Rather it is calculate based on the current state of the integrator block (which is determined mainly by the input at previous timesteps). This means that the Integrator block doesn't need to know its current input in order to calculate its current output.
So at the first time-step, the output of the integrator block is just the initial condition that you set (or the default initial condition of 0). So most likely, the initial value at 1 is 0.
(This link has some more info on algebraic loops and direct-feedthrough).
See here for more info on execution order in Simulink. This link also shows how to display the execution order in a model, which can sometimes be extremely useful to know.

Related

How to store a specific time that a signal value is changed in another parameter in Matlab simulink?

I have two Matlab function blocks that one is producing zero signal for the other. I want to store the exact time that signal changes to one in another parameter in order to use it elsewhere.
How can I do it?
This type of functinality is achieved using a Triggered Subsystem, as per the image below,
The output of the trigger block will take on value of the input (which in this case is the simulation time) every time the trigger signal rises. Look at the parameters of the Trigger block inside the subsystem for other options such as falling edge, or both edge, triggering.

Which input block is used in Matlab simulink that provide random values with time?

I am a new user of Matlab Simulink and currently i am working with Fuzzy Logic Controller with Simulation. In the Simulink, i want to input the values(i highlighted in the picture below), that changes with time.
Here, i am using Uniform Random Number Block which sends four values(which i feed) at same time but i want one value must input first, then another and so on. My target is to use Scope block(the one which is highlighted in the right side) and check the output that varies with time. But with current configuration, i just input ONLY one value. Please help?

Can state space matrix initial conditions be set by signals in simulink

I want to feed the initial conditions in state space matrix block in simulink by using signals "from-go to signal blocks". I m trying it with signal blocks but some errors pop up at the end and it says that the signal variables used as initial conditions are all undefined variable. In other words there exists "Undefined function or variable".
Any help appreciated, thank you
I take it you are using the State-Space block. The "initial conditions" parameter for the block is just that, a parameter:
You need to understand the difference between a parameter and a signal: a parameter is something that is constant throughout the simulation (e.g. a variable in the MATLAB workspace), whereas a signal is something whose value is updated at each time step. You cannot use a "signal" to parameterise a block, it's not possible, you can only use a parameter. Hope that clears things up.
If I misunderstood your question, please provide more details, including which block(s) you are using and if possible a screenshot of the model and the relevant block parameters.

Simulink: How to convert event based signal with zero duration values to a time based signal without losing information

I have a matlab function block (which is not relevant) whose input is his previous output (loop). For example, if in a sample period the output is X, his input in the next sample period will be X, and so on.
This image shows a simplification of my simulation. I initialize the input of my function for the first loop.
The problem is that matlab functions recieves an event based signal from de initialization block in the first sample period (zero-duration), which I must convert to a timed based signal (so I can apply the unit delay that avoids an inifite loop, and allows to generate the next input as explained before). So, when I do so, I lose the information contained in the event-based signal (due to the zero-duration values) and the loop does not work.
If there was a way to intialize the loop in the time-based domain (green part of the image) so, in the first sample time, it is not a zero-duration signal, it would avoid the problem.
Is there any way to do so? Or, a different approach for this problem?
Two approaches come to mind
The initial condition can be set in the Unit Delay block, so it's not clear from your simplified example why you need the specific Initialization block.
You could just use a persistent variable inside the MATLAB Function block to maintain the state from one execution of the block to the next (noting that since it is event driven the block may not get called at every time step, only at each event triggger).

Simulink From Workspace: can't use timestamps from matrix

I'm using the simulink block From Workspace to read in some audio data provided by a script. I have formatted the data in a matrix with 2 columns, the first is the timestamp and the second is the data.
In the configuration paramaters, I have specified Fixed-Step and Discrete solver. The Start time and Stop also need to be configured manually and don't seem to come from the data.
Also, in the From Workspace block configuration, I need to specify the sample time (1/44100) or I get a warning if I specify -1, to inherit from the data and then get strange sample times.
So, how can I get simulink to use only the sample times in the matrix and use the first and last timestamps as the start and stop time of the simulation?
You should be able to do what you want by doing the following:
Firstly note that your problem is by definition not fixed step, hence you cannot use a fixed-step solver, which by definition is ... fixed-step.
You must use a variable step solver.
Assuming your (2 column) input data is called simin then set the start and stop times to be simin(1,1) and simin(end,1) respectively.
In your From Workspace block set the sample time to be 0 (which should have been the default).
Also de-select the Interpolate data option; and set "Form the output after final data value by:" to zero (you won't be using anything past the end of your data set so this should be OK.
Then you need to tell the solver to take additional steps to those that it would naturally want to take.
Do this on the Data Import/Export pane of the Model Configuration Parameters.
Near the bottom of the pane there is a selection box and an edit box for doing this.
Note however that this does not prevent the solver from taking steps at other time points, it just forces it to take additional steps at the times you specify.
But because you have your From WOrkspace block to not interpolate this shouldn't be a problem either. You should put simin(:,1) in here so that the solver is guaranteed to take steps at the time points in your input data.
Note that if you want an input block that only samples at the time points in the simin time vector then the only way to do this is to write an S-function that uses the mdlGetTimeOfNextVarHit method to tell the solver what the next sample time (for this block) should be.