필터 지우기
필터 지우기

Can a Level 2-s function block output a transfer function?

조회 수: 1 (최근 30일)
Danial Waleed
Danial Waleed 2018년 3월 26일
댓글: Birdman 2018년 3월 27일
I am working on a code whose output is a transfer function. I want to implement this code in Simulink and I am using the Level 2-sfunction block in order to implement it. The main issue is that once the code runs in Simulink. It gives me the following error.
" An error occurred while running the simulation and the simulation was terminated Caused by: Error evaluating registered method 'Outputs' of MATLAB S-Function 'run_1' in 'test/Level-2 MATLAB S-Function'. The following is the MATLAB call stack (file names and line numbers) that produced this error: ['C:\Previous computer\dani usb 2 backup\AUS University\Master\4th semester\MTR 690\MTR projects\Level-2 S function\ninteger\run_1.m'] [219] Invalid assignment in 'test/Level-2 MATLAB S-Function'. Data must be a numeric or logical array Component:Simulink | Category:Block error "
I would like to know if there is a way to output a transfer function using the Level 2-s function block. The reason I need it is because I need to keep on updating variables that need to be fed into the function.
  댓글 수: 2
Birdman
Birdman 2018년 3월 26일
Can you share your code?
Danial Waleed
Danial Waleed 2018년 3월 26일
The code requires other dependent functions in order to work properly. I am sending you the files just extract them and run the test.slx file in order to see the simulink file. The code which the level-2 s function block uses is called run_1.m. thanks for your prompt feedback.

댓글을 달려면 로그인하십시오.

답변 (2개)

Birdman
Birdman 2018년 3월 26일
The problem seems to be with your output. You tried to output a datatype of tf, which is not supported by Simulink. Simulink works only with numerical values, therefore it is possible for you to work with them. In your run_1.m file, I changed the output accordingly. Please check that. I also set the Save output format to Array, in which you can easily see the coefficients being logged at every sample. You can change the formats according to your desire. The key change was this:
block.OutputPort(1).Data=[y.Numerator{1};y.Denominator{1}];
Hope this helps. Let me know if it works for you.
  댓글 수: 6
Danial Waleed
Danial Waleed 2018년 3월 27일
I will see what I can do.
Birdman
Birdman 2018년 3월 27일
Ok, looking forward for your further questions.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2018년 3월 27일
No, Level 2 S function must output signals, and tf are not signals. There is provision for creating custom data types for signals but the components are limited to double, int32, logical, char, and char with restricted values
https://www.mathworks.com/help/simulink/ug/simulink-data-class-extension-using-matlab-class-syntax.html
You could potentially create vectors of coefficients and current state and output those to be processed by a later S function or MATLAB Function Block, but you cannot output a tf and you cannot output a Simulink Block as a signal.
In some cases you might be able to use the S function to do the equivalent of set_param or to tune parameters of an existing transfer function block.
  댓글 수: 1
Danial Waleed
Danial Waleed 2018년 3월 27일
Understood, I think I will look into alternative than using Level-2 s function because there are so many limitations that I believe other alternatives could be better.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by