import a continuous bitsream from workspace into simulink using "In" block and then buffer it using "buffer" block - matlab

how to import a bitsream form binary vector from workspace into simulink.Actually I have found that I can use simin block or In block but my binary vector is independant of time. I tried to use Const block and it works but afer that when I wanted to put my output in the Buffer block in simulink, it didn't work because the input is continuous and not discrete. So I am asking if it's a way to add time to my binary uni-dimensional without having any influence on the result?and how can I do it?
Or is there another way to import this date to avoid this problem with Buffer block?

Your screenshot shows your constant block to have a sample time of Inf. As the error message suggest, you need to change that to a discrete sample time. In addition, you should also:
check your model is using a fixed-step solver
check what time step you are using for your chosen fixed-step solver (ideally the same as your constant).
You can have multi-rate models, but you need to manage the rate transitions with Rate Transition blocks. For more details on sample times, see the documentation, in particular how to view sample time information in a Simulink model. You should probably also have a quick look at the Choose a Solver section.

Related

Setting a Matlab function block's sample time in Simulink

Is it possible to explicitly set the sample time of a Matlab function block in a Simulink model? If yes, how? If not, how can you change the sample time of a signal coming from a Matlab function block?
For instance, how can one make sure that the sample time of a (possibly variable-sized) signal coming out of a block will be discrete?
Your best option is to use the Rate Transition block.
Also have a look at the Convert Signals Between Continuous Time and Discrete Time example to see how it's being used in practice.
Using the Matlab Function block you can Right click > Block Parameters > Sample time. Change from -1 to the sample time you want.
To make sure your simulation is using the correct sample time you can select the double arrows in the left panel and click on "Colors". Then, back in the double arrows, select "Sample Time Legend". Now, the different colors represents different rates in which Simulink is running.

Set step-time as a variable in Simulink exported code

I've developed a controller in Simulink and am trying to export it as a pure C class using Simulink coder for deployment on our microcontroller. We are using a fixed step solver in simulation, however, when the exported code gets used on our actual plant, the actual step size may change depending on load of the processor.
My concern is this: say I have set the fixed time step as 0.05s in simulation (and therefore the exported code assumes it is being executed every 0.05s), but then the microprocessor sometimes executes after 0.1s, and sometimes after 0.03s, etc. I think this would cause some unwanted behaviour.
Is there a way to have Simulink coder create a variable for step-time that we can adjust during run time? That is, measure how long it has been since the last execution, and then fill in the variable during each execution.
For an analogy, in videogame programming the update functions usually include a dt parameter so we know how long its been since the last frame.
The only solution I can find is to manually search and replace the step size in all the integrator blocks after the code has been generated. This, however, seems error prone.

Simulink Set sample time the same as Data

I am trying to make a simulation in Simulink, with the fuzzy model.
As inputs, I have set four time series variables from the workspace (compatible to simulink after performing Simulink.Timeseries function): every row of the variables has a linked time starting from 0 to 10566 (seconds, I believe). How can I set the sample time in simulink source block in order to pick every exact case without interpolation?
Thank you for your kind answers,
Phalaen
Are you using the From Workspace block? If so, it's simply a matter of specifying the sample time in the block parameters and unticking "Interpolate data". You can also display the sample time information of the model to check which sample time each block is using, see View Sample Time Information in the documentation.

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.

Simulink Storing Data to Workspace has time nonmonotonic

I am running a simulink simulation using the fixed-step discrete solver. I've even specified the fixed-step size. I save some data via a "To Workspace" block (I've used the Scope to save to workspace as well with equivalent results). When I look at the time data in the object, the time is not monotonically increasing.
The time value is constant for 5-10 samples, then continues. Any ideas why this happens?
I took a screen shot of the Time vector. You can see it goes flat, then continues, then is flat. I expected a single line.
I asked on the Mathworks site as well. I'll update both if I get an answer.
EDIT: I am working with Mathworks now too. They did show me how to visually inspect sample times. Navigate to Format > Sample Time Display > All. This will show all of the sample times in the simulation.
This problem was caused, at least partly by the existence of algebraic loops. Since Simulink was recalculating the algebraic loops, the output was capturing these changes.
I was able to click the "minimize algebraic loop occurrences" in the
Configurate Parameters > Model Referencing
and my loops were eliminated. This is a YMMV answer, but its the best I've found working with Mathworks support.