MATLAB Answers

How do I run a simulation with a transfer function block and a multi dimensional input ?

조회 수: 111(최근 30일)
Hello everyone,
[Context] I want to simulate a complex system many times in order to calculate the average behaviour of the system and I want to avoid the many compilations that would occur in a loop containing the sim(mdl) command. Notice that the only thing changing between each simulation of the system is the input signal values...
[Situation] Let’s take a very simple example to be clear : Create a new model with a “Sine Wave” block with the following parameters :
Sine Type : Time-based (Default)
Time (t) : Use simulation Time (Default)
Amplitude : [ 1 1 1 ]
Bias : [ 0 0 0 ]
Frequency : [1 1 1 ]*2*pi*0.22
Phase : rand(1,3) %Here is the only param that changes between simulations
Sample Time: 0
[Uncheck] Interpret vector parameters as 1-D
Add a “Transfer Fcn” block with the following parameters (for example) :
Numerator : [1]
Denominator : [1 0 1]
(Others to default value)
Connect the “Sine Wave” block to the “Transfer Fcn” block and the output of the “Transfer Fcn” to a “Scope” block. No need to change Configuration Parameters of simulation (Stop time etc...)
[Aim] Instead of running the simulation many times with one sinewave I want to exploit the possibility of generating many (=3 here) sinewaves once and run only one simulation...
[Problem] The simulation throws errors : “Error in port widths or dimensions.[...]” I know that the “Transfer Fcn” block does not feature Scalar expansion so do you have a solution to this problem or a workaround that avoids the repetitive compilations of the model ?
Thank you

채택된 답변

Paulo Silva
Paulo Silva 7 Jul 2011
I tested a model and found problems doing what you want, my workaround is:
  1. Insert a sine wave block (f=2*pi*0.22 and phase=rand), tf block (your num and den)
  2. Insert one mux block (three inputs) and the scope
  3. Now copy and paste the sine wave block two times
  4. Do the same for the transfer function block (paste it two times)
  5. Connect the sine waves to each transfer function block
  6. Connect the transfer functions outputs to the mux and the mux to the scope
Now with just one simulation you get three waves
  댓글 수: 3
Pham Dang
Pham Dang 8 Jul 2011
This is a good idea too.
The difference between Simulink and your code comes from a little mistake : the operation between "ext" and "cos(.)" should be a convolution.
Replacing ".*" with a convolution, I get similar results between Simulink and Matlab but they are not identical (though phase values are the same for both test)... I think this difference is out of scope of this topic.
But in the end, my original system is too complex to be written as a transfer function. So I can't have the "magic" ext vector.
The idea of Doug seems to be more appropiate to my special case.
Thank you very much for your help
Best regards

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

추가 답변(5개)

Doug Eastman
Doug Eastman 7 Jul 2011
Another option is to discretize the transfer function because a discrete transfer function does allow a vector input signal.
If you have the Control System Toolbox, you can automatically calculate the discrete form of the transfer function using C2D.
  댓글 수: 1
Pham Dang
Pham Dang 8 Jul 2011
Hi Doug, great idea !
It's the technique that provides the fastest simulations ! and above all, outputs are exactly the same as the reference continuous time testbench. Moreover, I can keep the original complex structure and I can benefit from scalar expansion.
Eventually, your answer is THE answer to my problem.
Thank you !
BR

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


Arnaud Miege
Arnaud Miege 7 Jul 2011
The transfer function block only supports scalar input signals, hence the error, see the documentation:
"The block can model single-input single-output (SISO) and single-input multiple output (SIMO) systems."
As Paulo suggests, make multiple copies of the block.
Arnaud

Pham Dang
Pham Dang 17 Sep 2011
Hi all, I finally found another workaround to speed up time compilation problem and time simulation : I use the Real Time Workshop with the "rsim" target. Using this technique, I only have to compile the model once, moreover the generated exectuable is very fast !
More information in Matlab
doc rtwdemo_rsim_batch_script
or
open rsimdemo1
I hope this may help others

Guy Rouleau
Guy Rouleau 20 Sep 2011
Hi Pham, In R2011b, place the transfer function inside the For Each subsystem.
The For Each subsystem now support continuous time, so it can vectorize any algorithm very easily.

K E
K E 3 Jan 2013
Would it be possible to make one input time series which has all the desired sine waves concatenated into 1 series, and then just run 1 long simulation? You would need to know the start/end of each sine wave in order to extract each segment in postprocessing. Just mentioning in case that makes implementation easier.

Community Treasure Hunt

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

Start Hunting!

Translated by