DSP Blockset | ![]() ![]() |
Store inputs into a LIFO register.
Library
Signal Management / Buffers
Description
The Stack block stores a sequence of input samples in a LIFO (last in, first out) register. The register capacity is set by the Stack depth parameter, and inputs can be scalars, vectors, or matrices.
The block pushes the input at the In
port onto the top of the stack when a trigger event is received at the Push
port. When a trigger event is received at the Pop
port, the block pops the top element off the stack and holds the Out
port at that value. The last input to be pushed onto the stack is always the first to be popped off.
A trigger event at the optional Clr
port (enabled by the Clear input check box) empties the stack contents. If Clear output port on reset is selected, then a trigger event at the Clr
port empties the stack and sets the value at the Out
port to zero. This setting also applies when a disabled subsystem containing the Stack block is re-enabled; the Out
port value is only reset to zero in this case if Clear output port on reset is selected.
When two or more of the control input ports are triggered at the same time step, the operations are executed in the following order:
The triggering event for the Push
, Pop
, and Clr
ports is specified by the Trigger type pop-up menu, and can be one of the following:
The Push full stack parameter specifies the block's behavior when a trigger is received at the Push
port but the register is full. The Pop empty stack parameter specifies the block's behavior when a trigger is received at the Pop
port but the register is empty. The following options are available for both cases:
The Push full stack parameter additionally offers the Dynamic reallocation option, which dynamically resizes the register to accept as many additional inputs as memory permits. To find out how many elements are on the stack at a given time, enable the Num
output port by selecting the Output number of stack entries option.
Example 1
The table below illustrates the Stack block's operation for a Stack depth of 4
, Trigger type of Either edge, and Clear output port on reset enabled. Because the block triggers on both rising and falling edges in this example, each transition from 1
to 0
or 0
to 1
in the Push
, Pop
, and Clr
columns below represents a distinct trigger event. A 1
in the Empty
column indicates an empty buffer, while a 1
in the Full
column indicates a full buffer.
Note that at the last step shown, the Push
and Clr
ports are triggered simultaneously. The Clr
trigger takes precedence, and the stack is first cleared and then pushed.
Example 2
The dspqdemo
demo provides an example of the related Queue block.
Dialog Box
Push
port when the register is full.Pop
port when the register is empty. Tunable.Empty
output port, which is high (1
) when the stack is empty, and low (0
) otherwise.Full
output port, which is high (1
) when the stack is full, and low (0
) otherwise. The Full
port remains low when Dynamic reallocation is selected from the Push full stack parameter.Num
output port, which tracks the number of entries currently on the stack.Clr
input port, which empties the stack when the trigger specified by the Trigger type is received.Out
port to zero (in addition to clearing the stack) when a trigger is received at the Clr
input port. Tunable.See Also
Buffer |
DSP Blockset |
Delay Line |
DSP Blockset |
Queue |
DSP Blockset |
![]() | Spectrum Scope | Standard Deviation | ![]() |