Read data from buffer without changing number of unread samples
Read data from the async buffer without changing the number of unread samples using the
dsp.AsyncBuffer System object™. The input is a column vector of 100 samples, 1 to 100. Write the data to the buffer.
asyncBuff = dsp.AsyncBuffer
asyncBuff = AsyncBuffer with properties: Capacity: 192000 NumUnreadSamples: 0
input = (1:100)'; write(asyncBuff,input);
Peek at the first three samples. The output is [1 2 3]'.
out1 = peek(asyncBuff,3)
out1 = 3×1 1 2 3
NumUnreadSamples is 100, indicating that the
peek function has not changed the number of unread samples in the buffer.
ans = int32 100
After peeking, read 50 samples using the
read function. The output is [1:50]'.
out2 = read(asyncBuff,50)
out2 = 50×1 1 2 3 4 5 6 7 8 9 10 ⋮
NumUnreadSamples is 50, indicating that the
read function has changed the number of unread samples in the buffer.
ans = int32 50
Now peek again at the first three samples. The output is [51 52 53]'. Verify that the
NumUnreadSamples is still 50.
out3 = peek(asyncBuff,3)
out3 = 3×1 51 52 53
ans = int32 50
Read 50 samples again. The output now contains the sequence [51:100]'. Verify that
NumUnreadSamples is 0.
out4 = read(asyncBuff)
out4 = 50×1 51 52 53 54 55 56 57 58 59 60 ⋮
ans = int32 0
asyncBuff— Async buffer
Async buffer, specified as a
numRows— Number of samples peeked from each channel
Number of samples peeked from each channel (column) of the buffer, specified as a positive integer. This operation does not change the number of unread samples in the buffer. If the requested number of samples is greater than the number of unread samples, the output is zero-padded.
overlap— Number of samples overlapped
Number of samples overlapped, specified as an integer. The function returns
numRows samples from each channel and overlaps previously read
overlap. The total number of samples peeked is
numRows × NumChann, where
NumChann is the number of channels in the buffer. The total number
of new samples peeked is (
NumChann. If the overlap portion contains samples that are
overwritten, and are therefore not contiguously written, the output is
out— Data peeked from buffer
Data peeked from the buffer, returned as an array of
× NumChann samples. If
specified, the function returns (
overlap) × NumChann samples. If the
requested number of samples is greater than the number of unread samples, the output is
Complex Number Support: Yes
nUnderrun— Number of zero-padded samples in each channel
Number of zero-padded samples in each channel (column) if underrun occurred. Underrun occurs if you attempt to peek more samples than available. Samples that are zero-padded in overlapped portions are not counted as underrun.