MATLAB:Transfer Functions

From PrattWiki
Revision as of 23:31, 6 September 2010 by DukeEgr93 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Example

Assume you have a transfer function \(G(s)\) for a low-pass \(RC\) circuit where you have a function for the ratio of the Laplace transform of the voltage across the capacitor to the voltage across the series combination of a capacitor and a resistor:

\( \begin{align} H(s)=\frac{\frac{1}{sC}}{R+\frac{1}{sC}}=\frac{1}{(RC)s+1} \end{align} \)

There are a few different ways to examine the magnitude and phase content of this transfer function over a range of frequencies. This document will show how to use MATLAB's tf function to set up and analyze the magnitude and phase of the transfer function of circuit.

%% Circuit constants
R = 10000;
C = 22e-9;

%% Set up transfer function
%  Create "s" as a transfer function for use later
s = tf([1 0], [1]);
%  Use s to generate transfer function for circuit
H = 1 / (s * R * C + 1);
%  Generate list of frequencies
F = logspace(1, 5, 1000);
Omega = 2 * pi * F;
%  Use bode command to analyze transfer function
[HMag, HPhase, HOmega] = bode(H, Omega);
HMag = squeeze(HMag);
HPhase = squeeze(HPhase);

%% Make plot
figure(1); clf
%  Magnitude plot on top
subplot(2,1,1)
semilogx(HOmega, 20*log10(HMag), 'r-')
xlabel('\omega, rad/s')
ylabel('|H|, dB')
%  Phase plot on bottom
subplot(2,1,2)
semilogx(HOmega, HPhase, 'r-')
xlabel('\omega, rad/s')
ylabel('\angle H, rad')