Main Content

peek

Read data from buffer without changing number of unread samples

Description

out = peek(asyncBuff) returns all unread samples from the buffer, asyncBuff, without changing the number of unread samples in the buffer.

example

out = peek(asyncBuff,numRows) returns numRows samples from each channel (column) of the buffer.

out = peek(asyncBuff,numRows,overlap) returns numRows samples from each channel and overlaps previously read samples by overlap.

[out,nUnderrun] = peek(___) also returns the number of zero-padded rows if underrun occurred, using any of the previous arguments.

Examples

collapse all

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]'.

out1  = peek(asyncBuff,3)
out1 = 3×1

     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
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
      ⋮

The NumUnreadSamples is 50, indicating that the read function has changed the number of unread samples in the buffer.

asyncBuff.NumUnreadSamples
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

asyncBuff.NumUnreadSamples
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
      ⋮

asyncBuff.NumUnreadSamples
ans = int32
    0

Input Arguments

collapse all

Async buffer, specified as a dsp.AsyncBuffer System object.

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 returns numRows samples from each channel and overlaps previously read samples by 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 (numRowsoverlap) × NumChann. If the overlap portion contains samples that are overwritten, and are therefore not contiguously written, the output is zero-padded.

Output Arguments

collapse all

Data peeked from the buffer, returned as an array of numRows × NumChann samples. If overlap is specified, the function returns (numRowsoverlap) × 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

See Also

Functions

Objects