peek - Read data from buffer without changing number of unread samples - MATLAB (original) (raw)
Main Content
Read data from buffer without changing number of unread samples
Syntax
Description
[out](#mw%5F32526cd9-896d-429f-b8dc-9eda512dbfe7) = peek([asyncBuff](#mw%5F1baf558d-ac7c-486d-ad1f-8bd2c394b7e0))
returns all unread samples from the buffer, asyncBuff
, without changing the number of unread samples in the buffer.
[out](#mw%5F32526cd9-896d-429f-b8dc-9eda512dbfe7) = peek([asyncBuff](#mw%5F1baf558d-ac7c-486d-ad1f-8bd2c394b7e0),[numRows](#mw%5F4b1d6aa2-2da9-41f1-b705-ca81da7bc889))
returns numRows
samples from each channel (column) of the buffer.
[out](#mw%5F32526cd9-896d-429f-b8dc-9eda512dbfe7) = peek([asyncBuff](#mw%5F1baf558d-ac7c-486d-ad1f-8bd2c394b7e0),[numRows](#mw%5F4b1d6aa2-2da9-41f1-b705-ca81da7bc889),[overlap](#mw%5F02c5ebfa-a27d-4581-affa-4646a2bb48f8))
returns numRows
samples from each channel and overlaps previously read samples by overlap
.
[[out](#mw%5F32526cd9-896d-429f-b8dc-9eda512dbfe7),[nUnderrun](#mw%5F88d96243-a4c6-4252-81b3-b3d86416a726)] = peek(___)
also returns the number of zero-padded rows if underrun occurred, using any of the previous arguments.
Examples
Read data from the async buffer without changing the number of unread samples using the peek
function.
Create a 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]'.
The NumUnreadSamples
is 100, indicating that the peek
function has not changed the number of unread samples in the buffer.
asyncBuff.NumUnreadSamples
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
11
12
13
14
15
⋮
The NumUnreadSamples
is 50, indicating that the read
function has changed the number of unread samples in the buffer.
asyncBuff.NumUnreadSamples
Now peek again at the first three samples. The output is [51 52 53]'. Verify that the NumUnreadSamples
is still 50.
asyncBuff.NumUnreadSamples
Read 50 samples again. The output now contains the sequence [51:100]'. Verify that NumUnreadSamples
is 0.
out4 = 50×1
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
⋮
asyncBuff.NumUnreadSamples
Input Arguments
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.
Number of samples overlapped, specified as an integer. The function returnsnumRows samples from each channel and overlaps previously read samples by overlap
. The total number of samples peeked isnumRows
× NumChann, where_NumChann_ is the number of channels in the buffer. The total number of new samples peeked is (numRows
– overlap
) × NumChann
. If the overlap portion contains samples that are overwritten, and are therefore not contiguously written, the output is zero-padded.
Output Arguments
Data peeked from the buffer, returned as an array of numRows × NumChann samples. If overlap is specified, the function returns (numRows
–overlap
) × NumChann samples. If the requested number of samples is greater than the number of unread samples, the output is zero-padded.
Data Types: double
Complex Number Support: Yes
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.
Data Types: int32
Version History
Introduced in R2018b