Simulink: Buffer with constant input due to delay of input

14 views (last 30 days)
Hi,
We are trying to use Simulink to communicate between two computers by using DVBS2 (commdvbs2). One computer is the Transmitter (TX) and the second is the receiver (RX). When we have the diagram on the same computer, everything works, but when we try to separate them, we get the following error with the buffer that can't accept to wait for the next frame: " Error in 'DVBS_COM_RX/Buffer': All sample times must be discrete. No continuous or constant sample times are allowed."
We have trying the following diagram to reproduce the buffer, but it seems than there is something wrong with the switch. We are trying to just put the output to a terminator when the buffer is not full and send the data when the buffer is full. We can only have one output than will be connected to the rest of the diagram of DVBS2. The output of the buffer are complex values that will be send to the demodulation. Other solution than create a new version of the buffer will also be appreciate.
The diagram of the Buffer we are trying to do. We use a constant values has input for the test to reproduce an entry with latency acting like a constant value:
Code of the MATLAB Function (input always have the same length):
function [data_out, buffer_was_full] = fcn(data_in)
%#codegen
persistent buffer emtpy_data pos_data size_buffer size_data
buffer_was_full = 0;
if isempty(buffer)
size_buffer = 1843200;
buffer = complex(zeros(size_buffer, 1));
emtpy_data = buffer;
pos_data = 1;
size_data = numel(data_in);
end
end_data = pos_data + size_data;
%Case when buffer is not full
if end_data < size_buffer
buffer(pos_data:(end_data-1)) = complex(data_in);
pos_data = pos_data + size_data;
buffer_was_full = 0;
data_out = emtpy_data;
%Case when (size_buffer/size_data) is a integer and buffer is full.
elseif end_data == size_buffer
buffer(pos_data:end) = complex(data_in);
data_out = buffer;
buffer = emtpy_data;
pos_data = 1;
buffer_was_full = 1;
%If buffer will be full by adding data_in. Security in case
%(size_buffer/size_data) is not a integer.
else%if end_data > size_buffer
emtpy_space_buffer = (size_buffer - pos_data);
buffer(pos_data:end) = complex(data_in(1:emtpy_space_buffer));
data_out = buffer;
buffer_was_full = 1;
other_part_data = (size_data-emtpy_space_buffer);
buffer(1:other_part_data) = data_in(other_part_data:end);
end
end

Answers (1)

Jim Riggs
Jim Riggs on 26 Jan 2018
The default sample time for a constant block is "inf". Based on the error message, the first thing I would check is the sample time setting in the block parameters for the constant block.
  1 Comment
Vincent lassena
Vincent lassena on 29 Jan 2018
Edited: Vincent lassena on 29 Jan 2018
The program is able to run with the sample time of inf or (for example) -1. But, the trouble is the fact that we need to reject the output of the Matlab function when the buffer is not full (buffer_was_full == 0) and keep the output only when buffer is full (buffer_was_full == 1). With this, we will only get an output to "simout" when buffer is full, so it will reproduce the buffer block and will work even if the output is constant.
If you get a error message when you try to run this program, is probably because you I also have to do some modification on the parameters of the Matlab function to sayd to Matlab the fixed size of the output "data_out" and the fact than "data_out" has complex number.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!