How to measure the when a signal is recieved in simlink.
2 次查看(过去 30 天)
显示 更早的评论
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 .
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!