Need algorithm or source code to draw a smith chart image (the chart itself) - Page 1
Forum section: electronics / rf-microwave

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 09, 2020, 02:32:46 pm
content: I need to implement a smith chart in software - that is, have a software program actually create the smith chart image from scratch (so that it can be generated on-the-fly for an application I'm working on.)I've not been able to find any examples or methods to draw a smith chart in software. Before I try to re-invent the wheel, I'd like to ask here if anyone knows of a resource like this. Any language/method will work, as I'll be porting whatever I start with to C language.Thanks,Dave

author: Twoflower
author_rank: Frequent Contributor
timestamp: August 09, 2020, 02:38:54 pm
content: Maybe check gnuplot:http://gnuplot.sourceforge.net/demo/poldat.html

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: August 09, 2020, 02:57:14 pm
content: Quote from: Twoflower on August 09, 2020, 02:38:54 pmWhilst I as well recommend gnuplot to anyone wanting to make charts, the extensive manual is something magnificent for any geek to behold. And you can't beat the price.However, the linked thread below suggests scilab as well as a gnuplot example and a few other methods.https://electronics.stackexchange.com/questions/50120/what-application-do-you-use-for-plotshttps://www.scilab.org/

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: August 09, 2020, 03:11:59 pm
content: Quote from: wb0gaz on August 09, 2020, 02:32:46 pmI didn't know this but I found out gnuplot has a API for C++.http://stahlke.org/dan/gnuplot-iostream/HTH

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 09, 2020, 03:42:32 pm
content: Twoflower, Ed - the poldat demo on gnuplot looks promising. I have zero knowledge of gnuplot, and won't be using gnuplot, but the intent of the demo script seems clear enough to follow to get started.There seem to be four curve functions (tu, tv, cu, tv) and for these, there seem to be a total of about 28 individual calls to the four functions (and none of the functions are nested, which should help). The plot itself shows 14 curves, so I suspect some of the individual calls do only a portion of a visible curve.Anyway, this should be enough for an initial experiment today, and I'll post back once I get some sense of whether this can be used as a starting point.Thank you very much for the quick and helpful replies!Dave

author: RenThraysk
author_rank: Regular Contributor
timestamp: August 09, 2020, 04:12:48 pm
content: Here's an interactive one in d3 & javascript for browsers.https://observablehq.com/@mbostock/smith-chart

author: jmw
author_rank: Frequent Contributor
timestamp: August 09, 2020, 04:31:52 pm
content: I've done my own Smith charts, for the aim of making printable sheets of them, and tried a few packages and found them all lacking. I did them using TeX, which won't carry over well to C, but I'll suggest this approach:- Do everything in Cartesian coordinates. The Smith chart might be thought of as a polar plot, but it's easier to draw it in the Cartesian system.- Everything can be drawn with circles, and you can find derivations for the constant resistance and constant reactance circles from several places likehttps://www.allaboutcircuits.com/technical-articles/mathematical-construction-and-properties-of-the-smith-chart- Most graphic systems support "clipping" regions, where anything drawn outside that region is hidden. If you set the clipping region to the unit circle, you can draw the reactance circles without care of where they intersect the unit circle. You'll never have to calculate the intersection of any arc with another.

author: bson
author_rank: Unknown
timestamp: August 09, 2020, 05:18:16 pm
content: Or if you can draw arbitrary circle segments (arcs) it's not exactly difficult to determine the endpoints, where two circles intersect.

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 09, 2020, 05:42:33 pm
content: OK - looks like deriving from poldem1 shows promise, with some attention to gnuplot details.I'm getting something that somewhat resembles a smith chart from my initial C experiment, so it's a start. I now mostly need to work out how gnuplot auto-scales and clips the curves so I can duplicate the result.Thanks again for the pointer - I'm much farther along now than I was this morning!

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 09, 2020, 07:26:23 pm
content: Success - at this point my C language version ofhttp://gnuplot.sourceforge.net/demo/poldat.htmlas originally suggested by Twoflower produces nearly identical image to the result from gnuplot (I haven't verified exact intersects where the curves hit the square clip limits, but they're very close in any event.)Very much appreciate the pointers and suggestions - next step is to work out how to stop the curves from exiting the outer perimeter (pure reactance?) circle (as bson suggests, finding intersections will help here.)Thanks again for the quick and detailed replies!Dave

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 09, 2020, 07:46:38 pm
content: Re-read jmw post in part"Most graphic systems support "clipping" regions, where anything drawn outside that region is hidden. If you set the clipping region to the unit circle, you can draw the reactance circles without care of where they intersect the unit circle. You'll never have to calculate the intersection of any arc with another."My graphic system is totally homebrew (basically c language code writing to a canvas), however, as I was puzzling over how to clip beyond the outer perimeter circle, I realized your suggestion re the unit circle (vs. trying to handle curve intersections) will easily solve this - I'll start into that shortly.Thanks again!

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 09, 2020, 08:17:17 pm
content: Clipping at edge of outer circle was successful - just compare next pixel location distance from origin vs radius of outer circle. Anyway, at this point I'll declare success on this task, with much thanks to all the help here!

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 12, 2020, 01:13:11 am
content: I don't know if you want to roll your own or are just looking for a ready made solution, but check these pages for links:https://www.vintage-radio.net/forum/showthread.php?t=162265http://sss-mag.com/smith.html#examples

author: wb0gaz
author_rank: Frequent Contributor
timestamp: August 12, 2020, 02:06:52 am
content: Thanks Quarlo - those are very good resources.I did succeed in my initial requirement of a small self-contained C routine to draw a basic smith chart (=roll your own in my case); it was also interesting to see the construction of the smith chart from fully "zoom out" where all of the circles are entirely visible (the smith chart is a circle subset.)Thank you again,Dave

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 12, 2020, 02:10:58 am
content: I hope some of the links were helpful. G'day.