Graphing and analyzing transfer functions

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
50_RAIDs_of_Cray
 
Posts: 34
Joined: Sun Oct 28, 2012 10:29 am

Graphing and analyzing transfer functions

Post by 50_RAIDs_of_Cray »

Hi everyone, I've made a short Octave script (Octave is the open source version of Matlab) which helps a person analyze transfer equations, of the form
A(s) = [DC gain * zeros]/[poles]

The control toolbox in Octave is great and offers lots of nice ways to plot a transfer function, including highlighting the poles and zeros in an x-y plane to help with placing compensation poles, or just producing normal Bode plots. These are important for anyone building amplifiers with feedback to prevent unwanted oscillations and instability, and also figure out what the gain is at different frequencies.

The code is available here on my git: https://github.com/Erik-k/transfer and I welcome any advice, pull requests or questions! This program was originally created as part of an overnight hackathon last week.

Image
Retro! This uses Gnuplot, and works by default if you're ssh'd into a beaglebone or some other embedded device which is doing the calculations.

Image
Gain margin and phase margin highlighted in a bode plot.

User avatar
ADearUser
 
Posts: 98
Joined: Thu Mar 12, 2015 11:07 am

Re: Graphing and analyzing transfer functions

Post by ADearUser »

Nice code :) You might want to include a piece in the readme about `apt-get install octave ` and those dependencies for a debian based system. Also, I read through your repo. I'm kind of a h/w noob and don't know a whole lot of the stuff that's out there.

After reading through the docs, I noticed you left thoughtful links to references, but I still couldn't sort out how people use transfer functions in there projects. It pertains to amplifier circuitry? Does that include audio amplifiers? If this helps make guitars sound more distorted, you should definately include a note of that in the readme along with an elementry link that people can use to 'first get into' amplifier circuits? Your repo is really friendly other than that one aspect of handling the absolute entry level person's visit :)

User avatar
50_RAIDs_of_Cray
 
Posts: 34
Joined: Sun Oct 28, 2012 10:29 am

Re: Graphing and analyzing transfer functions

Post by 50_RAIDs_of_Cray »

Thanks for the comment! I initially wrote this aimed at Debian users, so the transfer.sh shell script acts as a wrapper to prompt for dependencies and try to install them. And yes, these techniques apply to audio amps.

Transfer functions are related to amplifiers and feedback loops because when an amplifier is designed, if it is "open loop" and has no feedback, then you can just assume the inputs go in, get amplified depending on frequency (that's where the Bode plot comes in) and then pop out as outputs. The Bode plot shows amplification in decibels vs. frequency. For example, a low-pass filter would amplify low frequency signals, but then attenuate higher frequencies. The shape of the Bode plot in the ASCII image is what a low-pass filter looks like.

Things get more complicated when feedback is introduced. As frequency increases, the "phase" of the output changes relative to the input. Think sines and cosines: A cosine is just a sine wave that has been shifted by 90 degrees of phase. But if you take a sine wave and shift it by 180 degrees, it is inverted.

Why does this matter? Well, for a simple feedback loop like the one shown here (https://en.wikipedia.org/wiki/Feedback# ... _model.svg) if you want the output to be subtracted from the input, then when a 180 degree phase shift occurs you're now adding the output to the input because there was a sign change from + to -. This messes things up and causes an oscillation, where the amplifier will produce a sinusoidal output that is not related to the input. It's doing its own thing, and that behavior is usually undesirable. Engineers say it "blows up" at that frequency. I've seen amplifiers that normally operate at 5-10mA suddenly draw two amps because they hit that oscillation frequency and went nuts.

The way to prevent this is to make sure the feedback gain (shown as B in that diagram) is less than 1 at the 180 degree phase shift so that it attenuates the signal at that point. Then, even though the sign change has messed things up, it doesn't go crazy because it gets damped by being multiplied by a number less than 1. (To get more detailed, we actually need to be sure that the feedback gain B multiplied by the amplifier's original gain A is less than 1 at that frequency. So A(180)*B < 1.)

These graphs let people visualize their system and see how much safety margin they have on the gain and phase. If there isn't any gain margin, meaning that the gain is still positive and greater than 1 at the point where the 180 degree phase shift occurs, then they need to add another "pole" into the denominator to make the amplifier attenuate more before it hits that point.

User avatar
ADearUser
 
Posts: 98
Joined: Thu Mar 12, 2015 11:07 am

Re: Graphing and analyzing transfer functions

Post by ADearUser »

That's so interesting, thanks for the well written knowledge. It's kind of an advanced topic to me, I haven't quite gotten into waves yet, but I'm slowly acquiring RF and audio gear for fun engineering adventures and this code base is sure to be handy =)

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”