How to measure the when a signal is recieved in simlink.

조회 수: 2 (최근 30일)
kripa
kripa 2023년 1월 16일
답변: Dinesh 2023년 3월 9일
Hi i am new to simulink.
i would like to know is there any way to find the time when a simulink model receives a signal from a python script .

답변 (1개)

Dinesh
Dinesh 2023년 3월 9일
Hi Kripa.
I'm assuming that you have a working Simulink model and a Python script that gives a signal to the Simulink model.
To find out when the Simulink model receives a signal, you can use a "MATLAB Function" block and connect the output of the input signal from Python to it by right-clicking and dragging the signal to the input port of the "MATLAB Function" block. This does not disturb the current model that you have built.
In the "MATLAB Function" block, define a function that takes the input signal "u" as an input and outputs a struct containing the signal information and the time at which it was received.
function y = timestamp_signal(u)
persistent time % persistent variable "time" that is shared between different function calls.
% this variable is needed to make sure that the time is calculated only
% once during the first time when a signal is received by the Model
if isempty(time)
% Get the current time when the signal is first received
time = clock;
end
% Output the struct that contains the signal along with the time at which
% it was received
y = struct('signal', u, 'time', time);
Now, the output of this block can be saved using the "To Workspace" block so that the variable can be later accessed when needed to know when the Python script gave a signal to the Simulink model.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by