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.
- 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
Hope this helps!
