Accessing signal sample times programatically in Simulink

1 view (last 30 days)
Hello all -
I am working with a rather large simulink model. I want be able to set the decimation of specific signals for signal logging based on a desired frequency of logging. I should be able to do this by getting the sample time of the signal, and computing the decimation necessary to log at my frequency. Currently, I have a working function (log_on) that takes a list of signals in the model and sets their decimation for signal logging (The old method was to simply declare the decimation along with the signal name for logging). I am attempting to change this procedure so that users can specify the frequency of logging rather than the decimation. To do this I need to access the sample time of the signals in the model, and have the log_on function calculate the desired decimation from the sample time and desired frequency. Right now I have a sample time retrieval code that finds all labelled signals in the model, and gets the sample rate of the block that it is departing from using Simulink.Block.getSampleTimes. If the signal is leaving a subsystem, the code accesses the corresponding outport one level into the subsystem and uses that sample time. These sample times are stored in a mat file, and are used by the log_on function to set decimation. This procedure works okay, however there are some issues....
1 - If the signal is leaving a bus selector that has signals with different sample times in it, the block is considered hybrid. Because of this I cant get the sample time of a signal leaving these blocks with this method. I can't think of a work around for this one. I thought about using the destination block in this case but that has the same hybrid limitations.
2- The code takes a pretty long time to execute. This issue isn't as critical, I can just run it every night or something but this is inconvenient. Simulink.Block.getSampleTimes updates the diagram each time it retrieves a sample time which seems excessive, is there any way to prevent it from doing this? I want to just update the diagram once, then get all my sample times, not have to update each time.
So does anyone know of a better way to get the sample time of all signals in a model than what I am currently attempting, or have any insight into issues 1 & 2 above?
Any help or opinions are much appreciated.
Thanks in advance
Collin

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!