Mathematics


Every now and then I write or modify a matlab function that I need for my research, and will post them to this blog here and there, with the hopes that they will be useful to someone doing antenna/microwave design.  I know, there is the Matlab File Exchange (which is very useful!) , but hey, this is my blog, I want to post my content here.

Below is a function I used to plot smith chart results in matlab.  I used basic plotting code to generate the chart itself, and added a simply plot function to add the impedance locus and constant VSWR circles.  Hope this is helpeful!  Please let me know if anyone finds a bug.  I will note that there is no safeguard in the function for s-parameters that are greater than 1, which if you are plotting the active S-parameters of a multiport device, are possible.  This isn’t a big deal when the S-parameter goes slightly above 1, but if it swings well above 1 you end up with a tiny smith chart and these erratic line segments…it’s a mess.  For passive applications I haven’t come across a bug yet.

smithchart.m


This article from NASA talks about the measurement of magentic portals that connect the earth to the sun every 8 minutes, due to their magnetic fields pushing against each other and forming connections.  It is always interesting to see something happening on a such a large scale and with these huge fields that, as the article points out, many people didn’t believe in only 10 years ago.
I find the interaction of the electromagnetic waves on the scale of the solar system, between immensely large objects (here the earth and the sun) to be fascinating.  I spend so much time dealing with such small scale fields - antennas, microwave circuits, where fields are coerced into existence in these carefully designed structures to behave in a certain way.  Then I read articles on fields stretching 100 million miles between the earth and the sun, or the various effects the sun’s fields have on the earth, such as solar flares - fields covering half our solar system, in unbounded space, whose origins are not always clear or understood.  I mean, the earth’s magnetic field seems such a simple field that we take for granted - yet why it exists in the first place is not fully understood - you can’t exactly cut the earth in half and take a peak at it’s cross-section. It has even been shown to have flipped thousands of times over it’s lifetime - also something that we don’t quite understand the reason for.

I only have one course this semester, focusing on my Probability and Random Processes course and doing research.  This is by design, since I knew probability is a course I haven’t taken in 6+ years now…and I am super rusty.  But I have our text for the class, the schaum’s outline, and 3 other probability and random processes texts, and have been reading like crazy this semester, and doing sample problems out of the 4 texts and schaum’s.  Daily.  It’s good because I am having a much better time with this material than I expected, although the homeworks have been taking a long time to complete.

All this being said, here’s a sign it’s really starting to mess with my life: when I woke up this morning I asked myself what the probability of me getting out of bed when my snooze alarm went off for a third time (it’s set for 10 min intervals).  So I told myself, given how freezing it was in my apartment, and that I didn’t feel particularly awake, that I’d rate the likelihood of me getting out of bed on a given snooze alarm as 2/5, assuming I feel the same way independant of which snooze alarm is going off.

SO to get out of bed at the third snooze would be the probability of 2 failures to get out of bed, again assuming independence to make my just woken life easier, and one success:

P(I get out of bed on third snooze) =  (1-P(I get out of bed on first snooze))*(1-P(I get out of bed on second snooze))*P(I get out of bed on third snooze) = (1-2/5)(1-2/5)(2/5) = 18/125 ~ 20/120 = 1/6 ~slightly below 0.2, I’d say around 0.18 = => 18%

Then I went to sleep again and got out of bed on the 4th snooze alarm.

btw: The probability of me ever getting out of bed on my snooze alarm, found by summing over all probabilities from 1 alarm going off to infinitely many snooze alarm events, is 1, as you’d expect.  So it was bound to happen, eventually…

I have been running some Ansoft HFSS simulations of infinite arrays of antennas, recently.  A peculiar thing I noticed is that some of the impedance data, which is calculated from the S-parameter matrices, had sizable spikes (upwards of 300Ohms) inside a frequency band that, from the S-parameters, looked smooth and well matched.  Clearly something was wrong.  A low VSWR and S11 imply impedance levels close to the source impedance, yet these spikes in the impedance were there.

So I decided that, being able to compute all the data I need from S-parameters alone (as HFSS does), I exported the entire S-matrix to MATLAB and took a look at the impedance values I calculated.

HFSS gives the equation for finding the Z matrix as :

Z = sqrt(Zo*I)*inv(I-S)*(I+S)*sqrt(Zo*I)

where I=identity matrix, and S is the full S-parameter matrix

from this I plotted the exact same thing HFSS was giving for the impedances.  So I started plotting different chunks of the equation (e.g. inv(I-s) alone, (I+S) alone…) and found that the inv(I-S) term was spiking at the exact places my impedance was spiking, while the other terms were well-behaved.  Well, looks like that inversion is messing things up…indicating a singular, or more correctly a nearly-singular matrix (singular matrices have NO inverse defined).  Sure enough, using the function:

cond()

in MATLAB revealed huge condition numbers for the matrix (I-S) where the impedance spikes occurred, 2 orders of magnitude larger than the condition numbers calculated over the rest of the frequency sweep.  So I need to invert a matrix that is nearly-singular….now what??  I need single-value-decomposition (SVD) to take out those values that make the matrix singular and do a quasi-inversion, basically approximate the inversion.  MATLAB includes just such a function:

pinv() — where it’s use is  pinv(matrix, tolerance)

The tolerance can be set to an arbitrary value.  For my purposes, I can stand to lose some accuracy, so I chose a relatively large tolerance (around 0.02 or so) to take out those spikes but preserve the overal shape of the impedance waveforms.  Usually you will want to keep this very small to keep the inversion close to the true value.  But this solves my problem.

But it leads to another conclusion — HFSS, apparently, doesn’t test if its S-parameter matrices are nearly-singular (or at least I haven’t seen a way to have it do so).  Certainly it is using all sorts of inversion approximations in the solver the software uses (you can even do iterative matrix solutions in v11 of HFSS…), I don’t think it is likely that they have skimped on such checking on the data output front end.   Please post comments if you konw of any solutions in HFSS for this.

De Moivre, famous mathematician, is known to have predicted his own death. After finding that he slept 15 extra minutes with each night, he solved a series called an arithmetic progression, which is basically a series where the difference of each successive term is constant. example:

1 + 3 + 5 + 7… is an arithmetic progression because the difference between all terms is two.

Anyway, by summing this series up he figured out the day he would sleep for 24 hours, and declared that as the day he would die. He died on that very day - November 27th, 1754.