How to make bode plot of transfer function

Hello, i am trying to make a bode plot of the transfer function of a twin-t notch filter, that i am analyzing. I was able to produce the transfer function, and the bode plot by hand, but i am struggling to do it in Matlab, here is what i have so far:
r=320; %Resistance
c=100*10^-9; %Capactiance
p=(1/(r.*c)); %Beta
a=0.95; %Signma, adjusts the wiper of a potentiometer
f=(5000); %Target Frequency
s= (1i*f);
h=((s^2 + p^2) ./ (s^2+4*p*s*(1-a)+p^2)); %Transfer function
mh=abs(h); %Magitude of h
ah=angle(h); %Phase angle of h, in rads.
I am trying to plot the body function, and here is one i made for the transfer function H=2/(s+1):
% Example Transfer Function: g(s) = 2/(s+1)
% Numerator num = [2]; % Denominator den = [1 1];
% Transfer Function G = tf(num, den)
% Plot Frequency Response bode(G), grid
My question is, how would i represent the numerator and the denominator, since they are both powers of of s, which from my understanding the computer understands as s=jw, and thus i solved the transfer function as such. I have tried to understand how exactly the bode function takes it inputs, but i am not understanding that...
Any help would be great!!!
Thanks, Mike

4 Comments

here is the actual example code:
% Numerator
num = [2];
% Denominator
den = [1 1];
% Transfer Function
G = tf(num, den)
% Plot Frequency Response
bode(G), grid
Error in dfasd (line 6)
G = tf(num , den)
I am getting error
@Harsh, No error at line 6, if you run exactly the same code. Unless, you defined something else at lines 2 and 4.
% Numerator % Line 1
num = [2]; % Line 2
% Denominator % Line 3
den = [1 1]; % Line 4
% Transfer Function % Line 5
G = tf(num, den) % Line 6
G = 2 ----- s + 1 Continuous-time transfer function.
% Plot Frequency Response
bode(G), grid

openExample('control/TransferFunctionModelWithInheritedPropertiesExample')

Sign in to comment.

 Accepted Answer

Your transfer function would use:
num = [1 0 p^2];
den = [1 4*p*(1-a) p^2];
I’m certain you can take it from there.
Also, remember that the bode function can output the results of its computations, and the bodeplot function allows you to tweak its behaviour.

6 Comments

Star Strider: Thanks for the help, that input is indeed simple. I produced some wonderful bode plots, however i used another function, 'freqs' to make a plot as well. What exactly am i looking at with the "freqs" command?
% code% Transfer funciton, bode plot, 3rd attempt, Mike Zylla
r=320; %Resistance
c=100*10^-9; %Capactiance
p=(1/(r.*c)); %Beta
a=0.95; %Signma, adjusts the wiper of a potentiometer
f=(5000); %Target Frequency
%H(w)=(s^2+p^2)/(s^2+p^2+4ps(1-a)), is the transfer funciton for twin-t
%notch filter
num = [1 0 p^2]; %Numerator of H
den = [1 4*p*(1-a) p^2]; % Denominator
w={10^2,10^9};
% Transfer Function, note i did not close, as to have it confrim the
% correct output function....
G = tf(num, den)
figure(1);
% Plot Frequency Response
bode(G,w), grid
figure(2);
bodeplot(G)
%Making the frequency response from the transfer function???
w1=logspace(-1,1);
figure(3);
freqs(num,den,w1)
My pleasure.
The freqs function is the Signal Processing Toolbox version of the bode function in the Control Systems Toolbox and System Identification Toolbox. It evaluates continuous transfer functions. I haven’t compared freqs and bode, but I believe they’re doing essentially the same thing. (Another version, freqz, is useful for evaluating discrete systems and digital filters.) There is some overlap between control systems and filters in terms of design and implementation, so there are also overlaps in the functions that create and analyse them.
I think the freqs function can be used to actually make a transfer function, i am currently trying to figure that out.........
Not with freqs (or freqz).
If you want to create a transfer function from a Bode plot, use invfreqs (or invfreqz). You have to tell it the order of the system you want it to return, so it may require some experimentation (unless you already know the order).
If you want really robust solutions, use the System Identification Toolbox.
r=320; %Resistance
c=100*10^-9; %Capactiance
p=(1/(r.*c)); %Beta
a=0.95; %Signma, adjusts the wiper of a potentiometer
f=(5000); %Target Frequency
s= (1i*f);
%h=((s^2 + p^2) ./ (s^2+4*p*s*(1-a)+p^2)); %Transfer function
num = [1 0 p^2];
den = [1 4*p*(1-a) p^2];
h=tf(num,den)
bode(h), grid
Easier —
r=320; %Resistance
c=100*10^-9; %Capactiance
p=(1/(r.*c)); %Beta
a=0.95; %Signma, adjusts the wiper of a potentiometer
f=(5000); %Target Frequency
% s= (1i*f);
s = tf('s');
h=((s^2 + p^2) / (s^2+4*p*s*(1-a)+p^2)); %Transfer function
% num = [1 0 p^2];
% den = [1 4*p*(1-a) p^2];
% h=tf(num,den)
bode(h), grid
.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 15 Apr 2016

Commented:

on 2 Apr 2025

Community Treasure Hunt

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

Start Hunting!