Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.AsyncBuffer System object

Description

The dsp.AsyncBuffer System object™ writes samples to and reads samples from a first-in, first-out (FIFO) buffer. The write method writes data to the buffer and the read method reads data from the buffer. When creating the object, you can set the number of samples (rows) of the buffer using the Capacity property. The number of channels (columns) is set during the first call to write. Initialize the buffer by calling write or setup before the first call to read.

The data that you write occupies the next available space in the buffer. If the buffer is full and all the data within it is unread, that is, if asyncBuff.NumUnreadSamples == asyncBuff.Capacity, the object overwrites the oldest data with any new data that comes in. The buffer removes data only when the data is overwritten, so you can reread data from the past. The dsp.AsyncBuffer object supports writing and reading variable frame size signals. For examples, see Read Variable Frame Sizes from Buffer and Write Variable Frame Sizes to Buffer.

To write and read samples from a FIFO buffer:

  1. Create a dsp.AsyncBuffer object and set the properties of the object.

  2. Call write to write samples to the buffer.

  3. Call read to read samples from the buffer.

Construction

asyncBuff = dsp.AsyncBuffer returns an AsyncBuffer object, asyncBuff, using the default properties.

asyncBuff = dsp.AsyncBuffer(cap) sets the Capacity property to cap.

asyncBuff = dsp.AsyncBuffer(Name,Value) specifies properties using Name,Value pairs. Unspecified properties have default values.

Example:

asyncBuff = dsp.AsyncBuffer(200000);

Properties

expand all

Number of writable/readable rows in buffer. The number of rows during each write to the buffer must not exceed the capacity of the buffer. If the buffer is full and all the data within is unread, the object overwrites the oldest data with any new data that comes in. The CumulativeOverrun property returned by the info method gives the number of samples overrun per channel since the last call to reset. The number of samples overrun is the number of unread samples overwritten.

By default, this property is of data type int32.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

This property is read-only.

Number of unread samples in each channel (column) of the buffer. The total number of unread samples in the buffer is NumUnreadSamples × numChann, where numChann is the number of channels in the buffer.

The CumulativeUnderrun property returned by the info method gives the number of samples underrun per channel since the last call to reset. Underrun occurs if you attempt to read more samples than available.

Data Types: int32

Limitations

Before calling the read method, you must initialize the buffer by calling either the write or setup method. For an example, see Why Does the dsp.AsyncBuffer Object Error When You Call read Before write?

Methods

infoGet cumulative overrun and underrun
readRead data from buffer
resetReset internal states of System object
writeWrite data to buffer
Common to All System Objects
clone

Create System object with same property values

getNumInputs

Expected number of inputs to a System object

getNumOutputs

Expected number of outputs of a System object

isLocked

Check locked states of a System object (logical)

release

Allow System object property value changes

Examples

expand all

The dsp.AsyncBuffer System object™ supports reading variable frame sizes from the buffer.

Create a dsp.AsyncBuffer System object. The input is white Gaussian noise with zero mean, a standard deviation of 1, and a frame size of 512 samples. Write the input to the buffer using the write method. Store the data that is read from the buffer in outTotal.

asyncBuff = dsp.AsyncBuffer;
input = randn(512,1);
write(asyncBuff,input);

outTotal = [];
plot(input)
hold on

Plot the input signal and data that is read from the buffer in the same plot. Read data from the buffer until all samples are read. In each loop of iteration, randi determines the number of samples to read. Therefore, the signal is read in as a variable-size signal.

while asyncBuff.NumUnreadSamples ~= 0
    numToRead = randi([1,64]);
    out = read(asyncBuff,numToRead);
    outTotal = [outTotal;out];
    plot(outTotal,'r');
    pause(0.2)
end
hold off

Write a sine wave of variable frame size to the buffer. Compute the FFT of the sine wave and visualize the result on an array plot.

Initialize the dsp.AsyncBuffer, dsp.ArrayPlot, and dsp.FFT System objects.

asynBuff = dsp.AsyncBuffer;
plotter = dsp.ArrayPlot;
fftObj = dsp.FFT('FFTLengthSource','Property','FFTLength',256);

The sine wave is generated using the sin function in MATLAB®. The start and finish variables mark the start and finish indices of each frame. If enough data is cached, read from the buffer and perform the FFT. View the FFT on an array plot.

start = 1;

for Iter = 1 : 2000
    numToWrite = randi([200,800]);
    finish = start + numToWrite;

    inputData = sin(start:finish)';
    start = finish + 1;

    write(asynBuff,inputData);
    while asynBuff.NumUnreadSamples >= 256
        x = read(asynBuff,256);
        X = abs(fftObj(x));
        plotter(log(X));
    end
end

Extended Capabilities

Introduced in R2017a

Was this topic helpful?