Advertisement
Guest User

level 2 s-function

a guest
May 13th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.38 KB | None | 0 0
  1. function park(block)
  2.  
  3. %call setup function
  4.  
  5. setup(block);
  6.  
  7. %endfunction
  8.  
  9.  
  10. function setup(block)
  11.  
  12. % Register number of ports
  13. block.NumInputPorts = 3;
  14. block.NumOutputPorts = 2;
  15.  
  16. % Setup port properties to be inherited or dynamic
  17. block.SetPreCompInpPortInfoToDynamic;
  18. block.SetPreCompOutPortInfoToDynamic;
  19.  
  20. % Register parameters
  21. block.NumDialogPrms = 0;
  22.  
  23. % Register sample times
  24. % [0 offset] : Continuous sample time
  25. % [positive_num offset] : Discrete sample time
  26. %
  27. % [-1, 0] : Inherited sample time
  28. % [-2, 0] : Variable sample time
  29. block.SampleTimes = [0 0];
  30.  
  31. block.SimStateCompliance = 'DefaultSimState';
  32.  
  33.  
  34. block.RegBlockMethod('Outputs', @Outputs); % Required
  35. block.RegBlockMethod('SetInputPortFrameData', @SetInpPortFrameData);
  36. block.RegBlockMethod('Terminate', @Terminate); % Required
  37.  
  38. %end setup
  39.  
  40. %%
  41. %% Outputs:
  42.  
  43. function Outputs(block)
  44.  
  45. teta = block.InputPort(1).Data;
  46. ia = block.InputPort(2).Data;
  47. ib = block.InputPort(3).Data;
  48.  
  49. id=ia*cos(teta)+ib*sin(teta);
  50. iq=-ia*sin(teta)+ib*cos(teta);
  51.  
  52. block.OutputPort(1).Data = id;
  53. block.OutputPort(2).Data = iq;
  54.  
  55. %end Outputs
  56.  
  57. function SetInpPortFrameData(block, idx, fd)
  58.  
  59.     block.InputPort(idx).SamplingMode = fd;
  60.     for i=1:block.NumOutput.Ports
  61.         block.OutputPort(i).SamplingMode = fd;
  62.     end
  63.    
  64. %end SetInpPortFrameData
  65.  
  66. %%
  67. %% Terminate:
  68. function Terminate(block)
  69.  
  70. %end Terminate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement