Buffer - Buffer input sequence to smaller or larger frame size - Simulink (original) (raw)
Buffer input sequence to smaller or larger frame size
Libraries:
DSP System Toolbox / Signal Management / Buffers
Description
The Buffer block always performs frame-based processing. The block redistributes the data in each column of the input to produce an output with a different frame size. Buffering a signal to a larger frame size yields an output with a_slower_ frame rate than the input. For example, consider this illustration for a scalar input.
Buffering a signal to a smaller frame size yields an output with a_faster_ frame rate than the input. For example, consider this illustration of a scalar output.
The block coordinates the output frame size and frame rate of nonoverlapping buffers such that the sample period of the signal is the same at both the input and output:Tso =Tsi.
This block supports triggered subsystems when the block input and output rates are the same.
Examples
Ports
Input
To buffer single-channel signals, input a scalar or column vector. To buffer multichannel signals, input a row vector or matrix. To buffer single-channel signals, input a scalar or column vector of the size_Mi_-by-1, where_Mi_ is the input frame size.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Boolean
| fixed point
Complex Number Support: Yes
Output
The buffered input signal returned as a vector or a matrix.
When the input is a single-channel signal:
- 1-by-1 (scalar) — Output is an_Mo_-by-1 vector.
- _Mi_-by-1 (column vector) — Output is an_Mo_-by-1 vector.
where
- Mi — Input frame size
- Mo — Value of the Output buffer size parameter
The input frame period is_Mi_ ·Tsi, where_Tsi_ is the input sample period. The output frame period is (Mo−L)Tsi, where L is the value of theBuffer overlap parameter and_T_si is the input sample period. When you set the Buffer overlap parameter to _M_o – 1, the output frame period equals the input sample period.
When the input is a multichannel signal:
- 1-by-N — Output is an_Mo_-by-N matrix.
- _Mi_-by-N — Output is an_Mo_-by-N matrix.
where
- N — Number of channels in the signal
- Mi — Input frame period
- _M_o is the value of the Output buffer size parameter and can be greater or less than the input frame size,Mi. The block buffers each of the N input channels independently.
The input frame period is_Mi_ ·Tsi. The output frame period is (Mo−L)Tsi, which equals the sequence sample period when the Buffer overlap is Mo−1. Thus, the output sample period_Tso_ is related to the input sample period_Tsi_ by
The output has the same data type and complexity as the input
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Boolean
| fixed point
Complex Number Support: Yes
Parameters
Specify the number of consecutive samples,Mo, from each channel to buffer into the output frame.
Data Types: double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Specify the number of samples, L, which specifies the amount of overlap or underlap in each successive output frame.
To overlap the data in the buffer, specify a value of_L_ in the range 0≤L<Mo, where Mo is the value of the Output buffer size parameter. The block takes L samples (rows) from the current output and repeats them in the next output. In cases of overlap, the block acquires Mo−L_new_ input samples before propagating the buffered data to the output.
When L<0, you are buffering the signal with underlap. The block discards L input samples after the buffer fills and outputs the buffer with period (Mo−L)Tsi, which is longer than in the zero-overlap case.
The output frame period is (Mo−L)Tsi, which equals the input sequence sample period,Tsi, when theBuffer overlap is Mo−1.
Data Types: double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Specify the value of the block's initial output, in cases of nonzero latency, as a scalar, vector, or matrix.
For all cases of single-tasking operation other than those listed inZero-Tasking Latency, the Buffer block's buffer is initialized to the value(s) specified by the Initial conditions parameter. The block reads from this buffer to generate the first D output samples, where
The dimensions of the Initial conditions parameter depend on the Buffer overlap,L, and whether the input is single-channel or multichannel:
- When L≠0, the Initial conditions parameter must be a scalar.
- When L=0, the Initial conditions parameter can be a scalar, or it can be a vector with either of these constraints:
- For single-channel inputs, theInitial conditions parameter can be a vector of length_Mo_ if_Mi_ is 1, or a vector of length_Mi_ if_Mo_ is 1.
- For multichannel inputs, theInitial conditions parameter can be a vector of length_Mo_ *N if_Mi_ is 1, or a vector of length_Mi_ *N if_Mo_ is 1.
For all multitasking operations, use the rebuffer_delay function to compute the exact delay in samples that the Buffer block introduces for a given combination of buffer size and buffer overlap.
For general buffering between arbitrary frame sizes, theInitial conditions parameter must be a scalar, which is then repeated across all elements of the initial output(s). However, in the special case where the input is a 1-by-N row vector, and the output of the block is an_Mo_-by-N matrix, Initial conditions can be:
- An_Mo_-by-N matrix
- A length-Mo vector to be repeated across all columns of the initial output(s)
- A scalar to be repeated across all elements of the initial output(s)
In the special case where the output is a 1-by-N row vector, which is the result of unbuffering an_Mi_-by-N matrix, the Initial conditions can be:
- A vector containing_Mi_ samples to output sequentially for each channel during the first_Mi_ sample times
- A scalar to be repeated across all elements of the initial output(s)
For more information on latency and the Simulink® tasking modes, see Excess Algorithmic Delay (Tasking Latency) and Time-Based Scheduling and Code Generation (Simulink Coder).
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Boolean
| fixed point
Complex Number Support: Yes
Block Characteristics
Data Types | Boolean | double | fixed point | integer | single |
---|---|---|---|---|
Direct Feedthrough | no | |||
Multidimensional Signals | no | |||
Variable-Size Signals | no | |||
Zero-Crossing Detection | no |
More About
Zero-tasking latency means that the first input sample, received at t = 0, appears as the first output sample. In the Simulink single-tasking mode, the Buffer block has zero-tasking latency for these special cases:
- Scalar input and output (Mo=Mi=1) with zero or negative Buffer overlap (L≤0)
- Input frame size is an integer multiple of the output frame size
where k is an integer with zeroBuffer overlap (L=0); notable cases of this include:- Any input frame size_Mi_ with scalar output (Mo=1) and zero Buffer overlap (L=0)
- Equal input and output frame sizes (Mo=Mi) with zero Buffer overlap (L=0)
The Buffer block cannot be used in an enabled subsystem under the following conditions:
- In a multirate, multitasking environment
- When the Buffer overlap parameter is set to a negative value
The Buffer block has an internal reservoir that temporarily stores data. When the Buffer block is used in an enabled subsystem, there is the possibility that the reservoir can overrun or underrun. The block implements safeguards against these occurrences.
Overrun occurs when more data enters the buffer than what it can hold. For example, consider buffering a scalar input to a frame of size three with a buffer that accepts an input every second and outputs every three seconds. If you place this buffer inside an enabled subsystem that is disabled every three seconds at t = 3s, t = 6s, and so on, the buffer accumulates data in its internal reservoir without being able to empty it. This condition results in an overrun.
Underrun occurs when the buffer runs out of data to output. For example, again consider buffering a scalar input to a frame size of three with a buffer that accepts an input every second and outputs every three seconds. If you place this buffer inside an enabled subsystem that is disabled at t = 10s, t = 11s, t = 13s,t = 14s, t = 16s, and_t_ = 17s, its internal reservoir becomes drained, and there is no data to output at t = 18s. This condition results in an underrun.
To protect from an overrun or an underrun, the Buffer block keeps a record of the amount of data in its internal reservoir. When the Buffer block reads data, the amount of data in its reservoir goes up. When the Buffer block outputs the data, the amount of data in its reservoir goes down. To protect from overrun, the oldest samples in the reservoir are discarded whenever the amount of data in the reservoir is larger than the actual buffer size. To protect from underrun, the most recent samples are repeated whenever an output is due and there is no data in the reservoir.
Extended Capabilities
The Buffer block supports code generation for Simulink Real-Time™. The code generated for this target is executed concurrently. To generate this code, set the system target file of the model to speedgoat.tlc
or to any other target file supported by Simulink Real-Time. The Buffer block also needs to satisfy certain conditions.
To set the system target file:
- In the Simulink model window, in the Modeling tab, click Model Settings.
- In the Model Settings > Code Generation pane, set the System target file to
speedgoat.tlc
or to any other target file supported by Simulink Real-Time.
In addition, the Buffer block must satisfy the following conditions:
- Ratio between output and input buffer size must be a pure integer, that is 1/N or_N_/1. Ratios such as 3/12, 1/7, 7/1, or 2/4 are all valid ratios. In the Buffer block, you can specify the appropriate output buffer size using theOutput buffer size (per channel) parameter.
- There should be no overlap between frames. In theBuffer block, set the Buffer overlap parameter to
0
.
Version History
Introduced before R2006a