Why is my MATLAB's bode plot wildly off?
Show older comments
I will give out all the details in case it is relevant. I have a MIMO state space system. I find its bode plot using MATLAB and separately using Mathematica. The plot from MATLAB is wildly off compared to the correct bode plot. However, the Mathematica plot is quite close to the correct one. Here's the interesting thing. The transfer function whose bode plot is being taken in both the softwares is calculated to be the same. Have I made some mistake or is it numerical errors contributing to the problem? Here is relevant part of my code:
A=[0,0,0,0,1,0,0,0;
0,0,0,0,0,1,0,0;
0,0,0,0,0,0,1,0;
0,0,0,0,0,0,0,1;
-297.3,163.5,0,0,0,0,0,0;
162.9,-267.2,104.2,0,0,0,0,0;
0,57.8,-74.2,16.4,0,0,0,0;
0,0,16.4,-16.4,0,0,0,0];
B=[0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
131.4,0.046,0,0,0;
0,0,0.045,0,0;
0,0,0,0.025,0;
0,0,0,0,0.25];
S=[1,0,0,0,0,0,0,0;
0,0,0,1,0,0,0,0];
D=zeros(2,5);
sys=ss(A,B,S,D)
systf=tf(sys);
s1a1=systf(1,2);
bode(s1a1);
I have attached the plots.
Upper one is MATLAB and the other Mathematica 
4 Comments
madhan ravi
on 20 Jun 2020
Edited: madhan ravi
on 20 Jun 2020
Wildly off, what does mean? You told everything but forgot to share the SS equation xD.
Niket Parikh
on 20 Jun 2020
Edited: Niket Parikh
on 20 Jun 2020
madhan ravi
on 20 Jun 2020
Share the ss equation in LaTeX form and the Mathematica input just to be sure you have the same equations used.
Niket Parikh
on 20 Jun 2020
Accepted Answer
More Answers (1)
How do you know what the correct Bode plot is that your taking as your reference for comparison?
Basically repeating from Star's comment for completeness: In Matlab, you are geting the Bode plot from the second input to the first output. Is that what you want? From the name s1a1 and from the title on the Mathematica plot, it looks like you may have wanted the Bode plot from the first input to first output. And be careful with the Hz vs. rad/s thing.
The bode function in the CST takes great care in selecting its frequency vector if not specified by the user (as in your case) in an attempt to make sure it captures important dyanmics. In your case, all of the poles and zeros of s1a1 are basically on the imaginary axis. If you don't catch exactly the right frequency to evaluate you'll miss a peak. Try this and see what you get:
bode(s1a1,logspace(-1,2,300))
What frequency vector did Mathematica use?
Finally, once you have the state space model, there's no reason convert to tf first. In fact, I'm quite certain that documentation for older versions of the CST specifically recommended NOT doing this. Don't know if that's the case now, but I'm pretty sure that if you start with a ss representation, you should just use it and not bother converting to the other forms. If all you wanted is the Bode plot from the second intput to the first output you get that directly:
bode(sys(1,2))
1 Comment
Niket Parikh
on 20 Jun 2020
Edited: Niket Parikh
on 20 Jun 2020
Categories
Find more on Uncertainty Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


