- Insert a sine wave block (f=2*pi*0.22 and phase=rand), tf block (your num and den)
- Insert one mux block (three inputs) and the scope
- Now copy and paste the sine wave block two times
- Do the same for the transfer function block (paste it two times)
- Connect the sine waves to each transfer function block
- Connect the transfer functions outputs to the mux and the mux to the scope
How do I run a simulation with a transfer function block and a multi dimensional input ?
22 次查看(过去 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
0 个评论
采纳的回答
Paulo Silva
2011-7-7
I tested a model and found problems doing what you want, my workaround is:
Now with just one simulation you get three waves
3 个评论
Paulo Silva
2011-7-7
You can run the simulation 100 times with a loop and save each output, in the end plot the data, it's easy to do. If you have any new question please ask like you did for this one.
I tried to do the same just with MATLAB but for some reason I can't find the results aren't the same from simulink
syms s
Numerator=[1];
Denominator=[1 0 1];
sys=tf(Numerator,Denominator)
clf
axes
hold all
t=0:0.01:10;
ex=evalc('sys')
[a b] = strread(ex, '%s %s', 'delimiter',char(10));
num=sym(char(a(2)));
den=sym(char(a(3)));
ext=ilaplace(num/den);
ext=subs(ext,'t',t);
for n=1:3
plot(t,ext.*cos(2*pi*0.22*t+rand))
end
更多回答(5 个)
Doug Eastman
2011-7-7
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.
Arnaud Miege
2011-7-7
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
0 个评论
Guy Rouleau
2011-9-20
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.
0 个评论
K E
2013-1-3
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!