how to plot on the same bode plot a manual function plot() with function bode()?

I have a a transfer function that I plotted manually using Plot(w,abs(f1(w))) and I have another function that I used directly bode(f2(s)). I would like to plot them both in one bode plot?
the
bode()
hold on
plot()
gives errors

 Accepted Answer

I am not certain that what you want to do is possible with the bode function. The best option is to use the example in Obtain Magnitude and Phase Data and then plot those results together with the data you already have.

4 Comments

since I dont have matlab signal toolbox. I have anlog transfer function f2 that i can plot with bode(f1), and I have FIR filter with its coeeficeints that i plotted using manuel function and in the end I have plot(f2)
so, I want to see both in the same bode plot
I am slightly confused.
  • You have the Control System Toolbox and the bode function.
  • You have computed the transfer function of your FIR filter (without the Signal Processing Toolbox).
If you want to plot them together, use the approach to the bode function that I already described, then plot it together with the transfer function you computed on the same axes.
It is likely not possible to plot them together using the bode function unless you convert your FIR filter to a transfer function and then plot them together, possibly in parallel (using the + operator or the parallel function with the same input and separate outputs). I have never tried that, and I am not certain how to experiment with it.
It would likely be easier to do the same thing as I originally described with both systems (the control system and the FIR filter) and then just plot them using the subplot function, with one subplot for the magnitudes and another for the phases.
Thank you i just did that and I found out there is a slight difference,here the code
close all
w_5 = linspace(10e-3,1e3,10240);
[mag_5,phase_5]=bode(sys_five,w_5);
mag_5_1=mag_5(:,[1:10240]);
%wout_5=w_5(1:71,:);
plot(w_5, 20*log10(mag_5_1))
hold on
opts= bodeoptions;
opts= bodeoptions('cstprefs');
opts.PhaseVisible = 'off';
bode(sys_five,opts);
legend({' exctracted','normal bode plot'});
this the magnitude I get
I am not certain what you are doing, or whether you are starting with the FIR filter or the control system, then synthesising the other from it. (Those are not exact copies of each other, however I cannot determine if they are sufficiently similar to be acceptable to you.)
If you are going from the filter to the control system, and have the System Identification Toolbox, one option is to use the filter impulse resonse (either time-domain or frequency domain), and then estimate a system that will approximate it.
If you are going the other direction (control system to filter), you will need the Signal Processing Toolbox to create a FIR filter using the least-squares or Parks-McClellan procedure to approximate the frequency-domain transfer function of it.

Sign in to comment.

More Answers (1)

You could try:
G = frd(f1(w),w); % assuming f1(w) is a complex numeric vector
bode(G,f2)

Asked:

on 18 May 2020

Answered:

on 10 Jun 2020

Community Treasure Hunt

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

Start Hunting!