how to store incoming data and then output it after a certain delay in simulink - matlab

I have an incoming data and I would like to store it and then Output this data but after a certain delay, after some milliseconds i Output this data.
I used the Queue block inside an enabled Subsystem and the Trigger Signal is the clock divided by 10, So i have evrery time .. every 0.1 second i Output the values from the block,.. but the data is accumulated, not delayed. any idea why?
Here is the Picture of this Operation
and

EDIT: You now show how are you storing the signal. And The queue block is used wrongly.
If you want just to delay a signal, and output it delayed, then use my answer below. I am unsure what you mean by store it by N time and then output it. Simulink is "continuous" thus you can not output it "in one go" after N time, that makes no sense. The closest thing to that is to delay the singal, and for that, you dont need that enabled subsystem, you just need the Transport delay block.
ORIGINAL
What about the Transport Delay block?
It looks like this:
and It allows you to set the delay time in seconds, isntead of in ticks (as z^-1 does).

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.

Variable transport delay using time after threshold has been reached in Simulink

In Simulink how can I delay the transport block to the exact time of when a certain threshold has been reached?
Basically I have an S-function which switches to an alternate input source, a sine wave, after a certain value has been reached. As soon as the switch occurs I want to start the sine wave. For that I need to delay the wave generation until the switch occurs.
How can I send that time to the Variable transport delay block?
Maybe you can try this way:
you need Variable Integer Delay for example. It changes delay to what you need. Calculate needed value of delay you can in User Defined Function, route to it your threshold value and current time and all other values you need.
Hope i understood your question correctly!

change Frequency of coming data

I Have a Sensor (Gyro) that connected to my python program (with socket UDP) and send data to python console in real-time but with 200 Hz frequency.
I want to change this frequency of coming data to my console but could not find a good way to do it.
I was thinking about doing it with filters like Mean an waiting for idea?
If you want to have regular updates, use a windowing mechanism. Take the last n values and store the average. Then, discard the next two values and take the last n values again. This example would yield values with a frequency of 200 Hz/2.
If you only want to see events when changes have occured, store the last value, compare the current value with the last one and emit an event if it has changed, updating the stored value. As you're dealing with sensors (and thus, a little fuzziness), you probably want to implement a hysteresis.
You can even raise the frequency by creating extra values in between the received ones through interpolation. For a steady frequency, you would have to take care about your timing though.

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 and Monoflops

I'm using Matlab 7 and have a problem in creating a monoflop which shall raise for a specific time to "1" and after that time fall to "0". How can I do this with Matlab/Simulink 7?
I don't have any other version, so I can't use the "Monostable" Block from newer versions.
Any ideas?
greets, poeschlorn
There are a couple of ways to do this, depending on whether or not you want the pulse (i.e. "monoflop") to occur at a predetermined time or in response to another signal (like a rising edge)...
Creating a pulse at a predetermined time:
If you want to create a single pulse that steps from 0 to 1 at time tOnset, then steps back to 0 after a time tDur has elapsed, you can do this using a Step block, a Transport Delay block, and a Sum block. Here is what the layout would look like:
You would set the Step time of the Step block to tOnset, the Time delay of the Transport Delay block to tDur, and then subtract the delayed signal from the original signal.
Creating a pulse in response to a rising edge:
This is will be a bit more complicated. It will require two Detect Increase blocks, a Relay block, a Transport Delay block, a Gain block, and a Sum block. Here's what the layout would look like:
Assuming your input signal is either a 1 or a 0, the first Detect Increase block will output a 1 when the input steps from 0 to 1. By setting the Switch on point to 0.5 and the Switch off point to -0.5 for the Relay block, this will create hysteresis in the Relay such that the output will persist in the "on" state (i.e. an output of 1) after the brief pulse that occurs when the rising edge is detected.
To get the Relay block to switch back into the "off" state (i.e. an output of 0) after a specified time tDur, you would set the Time delay of the Transport Delay block to tDur. The Detect Increase block in the feedback loop will output a 1 when the delayed signal steps from 0 to 1, and this output will then be scaled by setting the Gain of the Gain block to 2.
When subtracted from the input signal, this gain will ensure that the output from the Sum block can be pulled below -0.5 no matter what the positive input is (0 or 1), thus ensuring that the Switch off point of the Relay block is reached and its output is turned off when the delayed signal has a rising edge (i.e. after tDur has elapsed). One result of this is that any additional rising edges occurring in the model input after the first rising edge and during the time tDur will be ignored. Once the output from the model returns to 0, the next rising edge on the model input will trigger another pulse.