Andres
Andres

Reputation: 6200

How to Bode plot an array of transfer functions?

I have some transfer functions corresponding to an LLC converter. Each one is different, I'm changing a single parameter to visualize the changes in the frequency response. I have something like this:

V(1)=Voutput;
V(2)=Voutput2;
V(3)=Voutput3;

Then I plot them using:

figure(1)
optsV = bodeoptions('cstprefs');
optsV.FreqUnits = 'kHz';
bode(V, optsV)

The problem is that every transfer function is being plotted in a different chart:

enter image description here

How can I plot them in a single chart?

Upvotes: 2

Views: 1085

Answers (2)

gg349
gg349

Reputation: 22671

Use something like

bode(V(1),'r',V(2),'g',V(3),'b', optsV)

where V1,V2,V3 are your various transfer functions.

They will be plotted as 3 lines with the three colors red, green, blue.

EDIT, in reply to the comment: if as you write in the comments they are very many, you can create the figure, call hold on, and plot all the transfer functions in a for loop, something like this:

first_tf = tf(1,[1,1]);
%your example of many TF.
V = [first_tf,2*first_tf,3*first_tf];
figure
hold on

for j=1:length(tfdata(V))
    bode(V(j))
end

With output like:enter image description here

Upvotes: 1

Matt
Matt

Reputation: 13923

You can use the following and put all of them in the same command:

bode(V(1),V(2),V(3), optsV)

If you want to use a loop to automatically plot all of the transfer functions you can use the following code:

for i = 1:size(V,2)
    bode(V(i), optsV)
    hold on
end

Here is a short demonstration:

V(1)=tf([1 0 0],[1 1]);
V(2)=tf([1 2 0],[1 1]);
V(3)=tf([1 1 0],[1 1]);

figure(1)
optsV = bodeoptions('cstprefs');
optsV.FreqUnits = 'kHz';

bode(V(1),V(2),V(3), optsV)
legend('V1','V2','V3')

desc

Upvotes: 1

Related Questions