Moving window in a Queue FIFO buffer

2 visualizaciones (últimos 30 días)
Peter
Peter el 12 de Mzo. de 2025
Respondida: Jack el 12 de Mzo. de 2025
I'm trying to find how often an event occurs over a moving time window in Simulink - say, how many times a boolean input goes true over the past 60 seconds. I see the Queue block will act as a FIFO buffer and can report the number of entries in the block, or if the block is full. But I'd also like to drop/pop any entries older than 60 seconds.
Can this be accomplished?

Respuestas (1)

Jack
Jack el 12 de Mzo. de 2025
You can implement a moving window by storing the timestamps of each event (when the boolean input goes true) in a FIFO buffer and then continuously removing (or “popping”) any timestamps that are older than 60 seconds. One straightforward approach is to use a MATLAB Function block to maintain an array of event timestamps. When an event occurs, you append the current simulation time to the array. At each simulation step, compare the current time to each stored timestamp and remove any that are older than (current time – 60 seconds). The number of remaining timestamps in the buffer represents the count of events in the last 60 seconds.
Follow me so you can message me anytime with future questions. If this helps, please accept the answer and upvote it as well.

Categorías

Más información sobre Subsystems en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by