write
Write data to buffer
Description
Examples
Write Variable Frame Sizes to Buffer
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
Input Arguments
asyncBuff
— Async buffer
dsp.AsyncBuffer
System object™
dsp.AsyncBuffer
Async buffer, specified as a dsp.AsyncBuffer
System object.
x
— Data input
vector | matrix
Data written to the buffer, specified as a vector or a matrix. The maximum number of
rows in the buffer is determined by the Capacity
property of
asyncBuff
. The number of channels in the buffer is determined by
the second dimension of the first data written to the buffer. Successive data inputs can
vary in the number of rows, but the number of channels must remain fixed. To change the
number of channels, you must call release
on the buffer.
For example, the following is accepted:
asyncBuff = dsp.AsyncBuffer; % First call to write write(asyncBuff,randn(15,5)); % Add more data with a different number of rows write(asyncBuff,randn(25,5)); write(asyncBuff,randn(5,5));
The following is not accepted and errors out:
asyncBuff = dsp.AsyncBuffer; % First call to write write(asyncBuff,randn(15,5)); % Add more data with a different number of columns write(asyncBuff,randn(15,15));
To change the number of channels, call release
on the
buffer.
asyncBuff = dsp.AsyncBuffer; % First call to write write(asyncBuff,randn(15,5)); release(asyncBuff) % Add more data with a different number of columns write(asyncBuff,randn(15,15));
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Complex Number Support: Yes
Output Arguments
nOverrun
— Number of samples overrun
scalar
Number of samples overrun in the current call to write
. The number of samples overrun is the number of unread samples
overwritten. If x
is a multichannel input, then
nOverrun
is the number of rows of data overrun.
Data Types: int32
Version History
Introduced in R2017a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)