I need Matlab help comparing bode plots neatly

  • Context: MATLAB 
  • Thread starter Thread starter Vagabond7
  • Start date Start date
  • Tags Tags
    Bode Matlab Plots
Click For Summary
SUMMARY

The discussion focuses on overlaying gain and phase plots onto a Bode plot in MATLAB. The user successfully utilized the "hold on" command to achieve the desired overlay effect. The specific MATLAB code provided includes the definition of a transfer function using tf and the generation of plots using bodeplot and semilogx. The final solution involves strategically placing the "hold on" command between the plotting commands to ensure proper layering of the plots.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of transfer functions in control systems
  • Knowledge of Bode plots and their significance
  • Experience with plotting functions such as semilogx and bodeplot
NEXT STEPS
  • Explore advanced MATLAB plotting techniques for better visualization
  • Learn about MATLAB's subplot function for organizing multiple plots
  • Investigate the use of legend and xlabel for enhancing plot clarity
  • Study the principles of control system analysis using Bode plots
USEFUL FOR

Engineers, researchers, and students working with control systems and signal processing who need to visualize and compare theoretical and experimental data using MATLAB.

Vagabond7
Messages
50
Reaction score
11
This definitely isn't a homework question as the work is already done, I'm just trying to make my presentation neater for some reports I'm turning in.

I am comparing theoretical data collected from a filter, to the actual data collected. I want to overlay the two to make the comparison. I am trying to do this for both the gain, and the phase difference. I have a plot for the gain, I have a plot for the phase difference, and I have the bodeplot that has both. But I can't seem to overlay everything.


Here is the code I have if any MATLAB whizzes can help me figure out how to do it. All of the plots themselves are correct, I don't need help with them. I just want to overlay the gain plot and phase plot over the respective parts of the bode plot.

sys=tf([0 -8200], [0 .12874 1570])
bodeplot(sys) %this is the bodeplot for the theoretical values

x=[100 1885 3142 10681 12566 14451 31416 628318 1000000]; %start of the gain plot for data
V=[10.2 10.2 9.8 7.6 7 6.4 3.8 .3 0];
y=20*log10(V./2);
subplot(2,1,1); semilogx(x,y,'r') %this is the end of gain plot for data

P=[189 189 165 140 136 126 116 92 92];
subplot(2,1,2); semilogx(x,P,'r') %This is the phase plot for real data

% subplot plots both the gain and phase plots together


simply adding a "hold on" command in there doesn't over lay the bode plot on the other plots. Any suggestions or commands anybody can think of the get everything lined up?
 
Physics news on Phys.org
I figured it out. The "hold on" command works in the order that the plots are listed so essentially the form of the code that worked was

gain plot
hold on
bode plot
hold on
phase plot

and then it overlapped everything the way I wanted it. Just in case anybody else wants to know.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 14 ·
Replies
14
Views
9K