How can I display on a Simulink Scope a digital signal that I am receiving in packages of N samples from a device via serial communication (i.e. [Nx1] array)

12 Ansichten (letzte 30 Tage)
I am working on a simulink model that receives data from a device via serial communication and performs data processing and visualization.
The device sends the data of a signal in packages of N samples, i.e. every time a read from the serial port and I parse the serial message from the device, I end up with a Nx1 array, where each element of the array is one sample of the signal. How do I display this signal in time using a Scope block (or something equivalent)? If I just connect the Nx1 array to a Scope block, the scope shows N signals.
  1 Kommentar
Beda Alessandro
Beda Alessandro am 9 Feb. 2024
Bearbeitet: Beda Alessandro am 9 Feb. 2024
Update: if you have the DSP Toolbox installed, the solution is go to the Configuration Properties of the Scope block and change the "Input Processing" option from "Elements as channels (sample based)" to "Columns as channels (frame based)". Note that you need to feed a colum vector (i.e., [1xN]) to the Sope block, so you might need to use a "Transpose" block.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pratyush Swain
Pratyush Swain am 7 Feb. 2024
Hi Beda,
I understand when you connect an Nx1 array directly to a Scope block, it interprets each element of the array as a separate signal , hence showing N signals. One workaround is we can leverage "MATLAB function block" to process the data such that it is treated as a sequence of samples from a single signal rather than as multiple signals.
I simulated the Nx1 input by using "repeating sequence block","constant block", and "vector concatenation block".
The "MATLAB function Block" has the following implementation to extract the vector data sequentially:
% y is the single output, u is the vector input %
function y = fcn(u)
% Declaring persistent variables buffer and index
persistent buffer index
% If the buffer is empty, initialize it with zeros
if isempty(buffer)
buffer = zeros(size(u));
index = 1;
end
% Allocate input vector values to buffer and extract value at index
buffer = u;
y = buffer(index);
% Update index
index = index + 1;
% If index exceeds array bounds, initialize it to 1
if index > length(buffer)
index = 1;
end
end
The above function block will ensure the values of the vector are outputted sequentially.The following is the output when three different signals[3X1] are realized in simulink scope(output of vector concatenation block):
After the application of "MATLAB function block" we get a single continous signal as compared to three different signals as follows:
We can also visualize how the above signal is infact made from the values of the three input signal as follows:
For more information on "MATLAB function block" and "vector concatenation block" please refer to:
I have also attached the simulink model for your reference.
Hope this helps.
  7 Kommentare
Pratyush Swain
Pratyush Swain am 9 Feb. 2024
Hi Beda,Do you specifically require licenses to set the configuration settings of scope block ?
Beda Alessandro
Beda Alessandro am 9 Feb. 2024
only for changing "Input Processing" configuration settings, not for the other settings

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by