fifo芯片 matlab,FIFO buffer

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 a mean of 0, a standard deviation of 1, and a frame size of 512 samples. Write the input to the buffer using the write method.

asyncBuff = dsp.AsyncBuffer;

input = randn(512,1);

write(asyncBuff,input);

plot(input)

hold on

93c1c09d29761356339e77f6c848213c.png

Store the data that is read from the buffer in outTotal.

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 iteration of the loop, randi determines the number of samples to read. Therefore, the signal is read in as a variable-size signal. The prevIndex variable keeps track of the previous index value that contains the data.

outTotal = zeros(size(input));

prevIndex = 0;

while asyncBuff.NumUnreadSamples ~= 0

numToRead = randi([1,64]);

out = read(asyncBuff,numToRead);

outTotal(prevIndex+1:prevIndex+numToRead) = out;

prevIndex = prevIndex+numToRead;

end

plot(outTotal,'r')

hold off

660ecb660548f3d76e5566d1f7a4b265.png

Verify that the input data and the data read from the buffer (excluding the underrun samples, if any) are the same. The cumulative number of overrun and underrun samples in the buffer is determined by the info function.

S = info(asyncBuff)

S = struct with fields:

CumulativeOverrun: 0

CumulativeUnderrun: 28

The CumulativeUnderrun field shows the number of samples underrun per channel. Underrun occurs if you attempt to read more samples than available.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值