Please send me some feedback
creatingrf [@] gmail.com
~ Octave
~ Meep
~ MPB



Matlab vs Octave
Octave Intro
Toolbox Examples
Toolbox Download

calcBJTBiasBasic.m
calcCascadedNoise.m
calcMicrostripEL.m
calcMicrostripEre.m
calcMicrostripL.m
calcMicrostripMenu.m
calcMicrostripW.m
calcMicrostripZo.m
calcStabilityCircles.m
calcVSWRcircle.m
csv2mdf.m
db2r.m
dbm2watt.m
example1.m
example2.m
example3.m
example4.m
gamma2rl2vswr.m
gammaLoad2gammaIn.m
getFreqDistribution.m
getNextPlotStyle.m
getRandomColor.m
gtoz.m
importCsvColData.m
importCsvFolder.m
importS2P.m
listDir.m
loadMdf.m
materialProperties.m
plotStabilityCircles.m
ptor.m
r2db.m
rtop.m
saveMdf.m
scAddCircle.m
scAddLabels.m
scAddPoint.m
scCreate.m
singleFreqSparams.m
testStability.m
watt2dbm.m
ztog.m


Toolbox Examples

I call it a toolbox because it was intended to make your job easier. You will notice the scripts range in size, from a simple script with four lines of code, to the large interactive program. The intent was to create small functions that could be used together in a larger program.

I believe the most useful source will be the help file for each function. To view the help file in a terminal, navigate to the location of the desired .m file and enter "help filename". This will print any commented text at the beginning of the function file.

Example 1: Smith Chart Plotting
Tools used: scCreate.m, scAddPoint.m, scAddCircle.m

Plot an impedance point and a circle on a smith chart. This example plots a random circle but the same method can be used to plot stability circles, gain circles, or VSWR circles. These are the basic functions to use when working with a smith chart.

Octave script:

######################### START example1.m #####################################
# Create a smith chart
# plot a point and circle
function example1()

# Inputs
# Specify an impedance and normalize it
Zo = 50;
Z1 = 10-20i;
z1 = Z1/Zo;

# Specify location of circle in polar form
circle_center_mag = 0.6;
circle_center_ang = 50;
circle_radius = 0.2;
circle_color = "b";

# Create a smith chart
scCreate;

# Plot a normalized impedance point
scAddPoint(z1);

# Plot a circle
scAddCircle(circle_center_mag,circle_center_ang,circle_radius,circle_color);

# Tell the plot nothing will be added
hold off;

endfunction
######################### END example1.m #######################################


Results:



Example 2: Calculating reflection coeff. and switching coordinates
Tools used: ztog.m, ptor.m, rtop.m, gtoz.m

This example demonstrates a common need to go from impedance to reflection coeff. or from reflection coeff. to impedance. It also demonstrates another common need to switch from rectangular to polar coordinates or polar to rectangular coordinates. Run the script and look at the outputs. The last output (ZL2) should be equal to the original load impedance (ZL). This script does not serve any purpose except to demonstrate a few tools. These are basic building blocks used in more practical scripts.

Octave script:

######################### START example2.m #####################################
# Calculate the reflection coeff. of a given load impedance.
# Convert the reflection coeff. form from polar to rectangular, and back to polar
# Convert reflection coeff. back to its original load impedance
# Demonstrates how to use the tools: ztog, ptor, rtop, and gtoz
function example2()

# Inputs
# Characteristic impedance, Load impedance, and normalized load impedance
Zo = 50
ZL = 10-20i
zL = ZL/Zo

# Calculate reflection coeff.
[refl_mag,refl_ang] = ztog(ZL,Zo)

# Convert reflection coeff. to rectangular coordinates
refl_rect = ptor(refl_mag,refl_ang)

# Convert reflection coeff. back to polar form
[refl_mag2,refl_ang2] = rtop(refl_rect)

# Convert reflection coeff. back to impedance
[zL2,ZL2] = gtoz(refl_mag2,refl_ang2,Zo)

endfunction
######################### END example2.m #######################################


Results:

octave:32> example2
Zo = 50
ZL = 10 - 20i
zL = 0.20000 - 0.40000i
refl_mag = 0.70711
refl_ang = -135
refl_rect = -0.50000 - 0.50000i
refl_mag2 = 0.70711
refl_ang2 = -135
zL2 = 0.20000 - 0.40000i
ZL2 = 10.000 - 20.000i


Example 3: Import S parameters from .s2p file
Tools used: importS2P.m, singleFreqSparams.m

This example shows how to get s-parameter data from a .s2p file into octave and extract the parameters for a single frequency. S2p files are usually supplied by the company on a product page. Say you're designing an amplifier. Most companies will provide an s2p file for the transistor you plan on using. Download the s2p file and use the following method to import it into octave. Once the s-parameters are in octave, you can plot stability circles, gain circles, or anything else one would do with s-parameters.

Here's an example s2p you can use to test out this example.

example2data.s2p

! FILENAME: example2data.S2P VERSION: 14.1
! PART NUMBER: Test123 DATE: 10/03
! BIAS CONDITIONS: VC = 1.000 V, IC = 5.000 MA
# GHZ S MA R 50
2.800 0.510 -166.01 4.992 62.52 0.090 13.26 0.382 -96.78
2.850 0.506 -167.91 4.920 61.35 0.091 13.02 0.379 -97.89
2.900 0.504 -169.70 4.846 60.20 0.091 12.70 0.376 -98.74
2.950 0.501 -171.20 4.756 59.21 0.091 12.12 0.376 -99.36
3.000 0.502 -172.55 4.693 57.94 0.092 11.46 0.371 -100.53
3.050 0.500 -174.40 4.631 56.83 0.092 11.21 0.369 -101.30
3.100 0.496 -176.46 4.561 55.72 0.092 10.79 0.367 -101.77
3.150 0.496 -177.72 4.499 54.66 0.092 10.40 0.365 -102.76
3.200 0.495 -179.47 4.438 53.53 0.093 9.95 0.363 -103.54


Octave script:

######################### START example3.m #####################################
# Import s-parameter data from .s2p file
# Find s-parameters at a single frequency
function example3()

# Inputs
# s2p filename, frequency in GHz
filename = "example3data.s2p"
freq = 3.0

# Import s-parameter data from .s2p file
sparams = importS2P(filename)

# Find s-parameters at the desired frequency
# Create 2x2 s-parameter matrix (rectangular form)
s = singleFreqSparams(sparams,freq)

endfunction
######################### END example3.m #######################################


Results:

octave:33> example3
filename = example3data.s2p
freq = 3
sparams =

2.8000e+00 5.1000e-01 -1.6601e+02 4.9920e+00 6.2520e+01 9.0000e-02 1.3260e+01 3.8200e-01 -9.6780e+01
2.8500e+00 5.0600e-01 -1.6791e+02 4.9200e+00 6.1350e+01 9.1000e-02 1.3020e+01 3.7900e-01 -9.7890e+01
2.9000e+00 5.0400e-01 -1.6970e+02 4.8460e+00 6.0200e+01 9.1000e-02 1.2700e+01 3.7600e-01 -9.8740e+01
2.9500e+00 5.0100e-01 -1.7120e+02 4.7560e+00 5.9210e+01 9.1000e-02 1.2120e+01 3.7600e-01 -9.9360e+01
3.0000e+00 5.0200e-01 -1.7255e+02 4.6930e+00 5.7940e+01 9.2000e-02 1.1460e+01 3.7100e-01 -1.0053e+02
3.0500e+00 5.0000e-01 -1.7440e+02 4.6310e+00 5.6830e+01 9.2000e-02 1.1210e+01 3.6900e-01 -1.0130e+02
3.1000e+00 4.9600e-01 -1.7646e+02 4.5610e+00 5.5720e+01 9.2000e-02 1.0790e+01 3.6700e-01 -1.0177e+02
3.1500e+00 4.9600e-01 -1.7772e+02 4.4990e+00 5.4660e+01 9.2000e-02 1.0400e+01 3.6500e-01 -1.0276e+02
3.2000e+00 4.9500e-01 -1.7947e+02 4.4380e+00 5.3530e+01 9.3000e-02 9.9500e+00 3.6300e-01 -1.0354e+02

s =

-0.497762 - 0.065090i 0.090166 + 0.018279i
2.491077 + 3.977283i -0.067800 - 0.364752i



Example 4: Plotting stability circles
Tools used: ptor.m, plotStabilityCircles.m

This example plots the input and output stability circles of a given s-parameter matrix. S-parameters are commonly in polar form. By converting to rectangular form, we can store all 4 s-parameters in a 2x2 matrix, which is intuitive to use. Once we have the 2x2 matrix called "s", each s-parameter is easy to reference. For example, s11 = s(1,1) and s12 = s(1,2). Makes sense right? A 2x4 matrix would be needed to store them in polar form, which makes the reference to each parameter not make any sense.

Octave script:

######################### START example4.m #####################################
# Plot the input and output stability circles for a given s-parameter matrix
# Could also plot stability circles for a range of frequencies from an s2p file
# by using: plotStabilityCircles(folder,filename,f_min,f_max)
function example4()

# Inputs
# Store s-parameters in 2x2 matrix called "s"
# Converting to rectanguar form allows parameters
# to be stored in 2x2 matrix instead of 2x4 matrix
s(1,1) = ptor(0.502,-172.55);
s(2,1) = ptor(4.693,57.94);
s(1,2) = ptor(0.092,11.46);
s(2,2) = ptor(0.371,-100.53);

# Plot input and output stability circles
plotStabilityCircles(s)

endfunction
######################### END example4.m #######################################


Results:



This example plots stability circles at one frequency. Usually, we want to look at stability circles for a range of frequencies. The plotStabilityCircles.m tool makes plotting a range of frequencies easy by pulling s-parameter data from an s2p file. Check out the help file for plotStabilityCircles.m and you'll see how quick and easy it is to do.


Questions/comments:
CREATINGRF [at] GMAIL.COM