# Time delay threshold for constant output

4 views (last 30 days)
Mirko Novakovic on 28 Jan 2023
Answered: Andy Bartlett on 31 Jan 2023
Hi,
I have a Simulink project where I have to make sure that when input signal stays for some amount of time (etc 3 sec), the output will then stay the same, even if the input signal changes (like when holding a switch for a longer time triggers a conitnuous movement even if you release the switch).
Is this solvable with some Simulink Ramp element, or some Delay element,... and how practically?
I also have to show that emulated lamp element is "blinking" (0 to 1 and back) at a frequency of 0.5 Hz if there is change in some signal? What would you suggest for that?
Best regards,
M.

Andy Bartlett on 31 Jan 2023
I suggest you start by writing down on paper the equations or pseudo code that you think will solve the requirements of your problem.
For a discrete-time implementation, difference equations are great.
Mini-review of difference equations.
v(k) = the value of signal v at the k-th time step
v(k-1) = the value of signal v at the at the (k-1)-th time step
Less formally, you might describe this as
v(k) is the value of signal v "NOW"
v(k-1) is the "PREVIOUS" value of signal v
Note: to understand what time step k corresponds to you need to multiply by the sample rate.
For example, if the sample rate is 0.125 seconds for the unit delay then the k-th time step corresponds to time k * 0.125 seconds.
In Simulink, let's assume a wire represent a signal v.
At any time step k, the value on that signal wire will be v(k).
If you pass that signal as input to a unit delay, then the output will be v(k-1).
When you convert your difference equations to a Simulink model, unit delay blocks will be key elements in your discrete time design.
As you experiement with possible solutions and debug your wiring up of the Simulink diagram, it will be very helpful to drop in display blocks connected to each signal of interest. Use the Simulink stepper to move the simulation forward one step at a time. Look at each of the display blocks to see if the values shown agree with your mental model of what should be happening. This process should quickly identify errors and misunderstandings and build your expertise.

### Categories

Find more on Signal Attributes and Indexing in Help Center and File Exchange

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!