- https://www.mathworks.com/help/simulink/sfg/sample-times-matlab.html
- https://www.mathworks.com/help/simulink/ug/how-to-specify-the-sample-time.html#brz5u9a
Simulink Coder S-Functions
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a Simulink model that has multiple different inputs and outputs of varying types and sample rates. Some of the inputs and outputs are busses, others are vectors. The signals also have different sample rates. When I compile this model in Matlab/Simulink 2013b the resultant S-function only shows a single sample rate for all input and output signals which causes numerous rate errors in the rest of the model. If I specify the data types and sample rates of the input/output ports then the generated S-function just sets the input/outputs of the parent subsystem which is not valid as upsampling/downsampling causes artifacts to appear in the signals corrupting the results. Is there a limitation with generating S-functions that I missing?
I have compiled subsystems with varying sample rates in older versions of Matlab/Simulink and have had zero problems. The sample rates of the input/output ports is maintained.
0 comentarios
Respuestas (1)
Kanishk
el 7 de Feb. de 2025
When working with S-functions in Simulink handling multiple sample rates can be challenging. Here are some suggestions that might help address the issues you're facing:
1. Use Rate Transition Blocks:
- To handle different sample rates, consider using Rate Transition blocks at the boundaries of your S-function. This can help manage the transition between different rates and avoid artifacts caused by upsampling/downsampling.
2. Specify Sample Times in the S-Function:
- If possible, explicitly specify the sample times for each port in your S-function. This requires modifying the S-function code to support multiple rates, which can be complex but may resolve the issue.
You can specify port-based sample times in a Level-2 MATLAB S-function by using the below code.
block.InputPort(1).SampleTime = [-1 0];
block.OutputPort(1).SampleTime = [-1 0];
You can learn more about specifying sample times in S-Function by following the below MATLAB documentation.
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Simulink Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!