Author Topic: S-Parameter Plotter  (Read 3956 times)

0 Members and 1 Guest are viewing this topic.

Offline k6stiTopic starter

  • Contributor
  • Posts: 21
  • Country: us
S-Parameter Plotter
« on: May 24, 2025, 06:08:47 pm »
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5742
  • Country: Earth
Re: S-Parameter Plotter
« Reply #1 on: May 26, 2025, 12:23:47 am »
you can do it with octave, for example:

Code: [Select]
data = dlmread('BPF-2450BP15Q0100.s2p', '', 5, 0);  % skip 5 lines in header
freq = data(:, 1);
s11 = data(:, 2) + j*data(:, 3);
s21 = data(:, 4) + j*data(:, 5);

freq /= 1000000;                    % Hz to MHz
s11_dB = 20*log10(abs(s11 + eps));  % linear to dB
s21_dB = 20*log10(abs(s21 + eps));  % linear to dB

figure;
hold on;
plot(freq, s11_dB);
plot(freq, s21_dB);
xlabel('MHz');
ylabel('dB');
xlim([min(freq) max(freq)]);
ylim([min([s11_dB(:); s21_dB(:)])-10, 6.02]);
grid on;
grid minor;

The positions of the S11 and S21 values are hardcoded in the code, but it's simpler to inspect the S2P file manually and enter the required indices directly, rather than implementing a parser to extract parameter indices by name.

If needed, you can add calculations for VSWR and other parameters, as Octave provides convenient tools for a wide range of computations.

« Last Edit: May 26, 2025, 12:31:49 am by radiolistener »
 

Offline rf-fil

  • Regular Contributor
  • *
  • Posts: 134
  • Country: au
    • VK2ZJ at QRZ
Re: S-Parameter Plotter
« Reply #2 on: May 26, 2025, 12:49:50 am »
Nice. There used to be a neat little Windows app called Iowa Hills Smith Chart that could do plotting but also allowed a simple matching circuit to be drawn up and tuned. Any plans to add something like that?
-VK2ZJ
 

Offline ftg

  • Frequent Contributor
  • **
  • Posts: 516
  • Country: fi
    • ftg's RF hax paeg
Re: S-Parameter Plotter
« Reply #3 on: May 26, 2025, 08:09:32 am »
Nice. There used to be a neat little Windows app called Iowa Hills Smith Chart that could do plotting but also allowed a simple matching circuit to be drawn up and tuned. Any plans to add something like that?

Isn't this more or less what SimNEC, former SimSmith does?
https://www.ae6ty.com/smith_charts/

It displays the S-parameter file on the Smith chart and allows building a matching network for it.
 
The following users thanked this post: rf-fil

Offline k6stiTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: S-Parameter Plotter
« Reply #4 on: May 27, 2025, 05:26:46 pm »
Nice. There used to be a neat little Windows app called Iowa Hills Smith Chart that could do plotting but also allowed a simple matching circuit to be drawn up and tuned. Any plans to add something like that?


No. I wrote the program mainly to provide reference impedance renormalization and the Y21 method. I think impedance matching is better done these days with nongraphical programs that can automatically optimize the match.

Brian
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5742
  • Country: Earth
Re: S-Parameter Plotter
« Reply #5 on: May 27, 2025, 08:04:26 pm »
I wrote the program mainly to provide reference impedance renormalization and the Y21 method.

it's more easy to do math calculations in Octave, it already has many tools for that like interpolation, etc.
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 782
  • Country: us
Re: S-Parameter Plotter
« Reply #6 on: June 02, 2025, 06:05:59 pm »
it's more easy to do math calculations in Octave, it already has many tools for that like interpolation, etc.

Unless someone already has the Matlab baggage in their brain (hey, a lot of us do!), I would suggest not learning Octave.  Far better to use python instead.  There's even an actively developed, RF-focused "toolkit" for python called scikit-rf.  I believe it can do most of the things you're suggesting here.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5742
  • Country: Earth
Re: S-Parameter Plotter
« Reply #7 on: June 02, 2025, 11:59:13 pm »
Unless someone already has the Matlab baggage in their brain (hey, a lot of us do!), I would suggest not learning Octave.  Far better to use python instead.  There's even an actively developed, RF-focused "toolkit" for python called scikit-rf.  I believe it can do most of the things you're suggesting here.

I don't agree, I tried python, but its very slow and has many issues. I'm using C, C++ and C# instead. But programming language is not a replacement for Matlab/Octave. You need both. Matlab/Octave for calculations, filters/model design, plots, etc. Programming language for applied implementation of algorithms. Python is often seen as a middle ground, but it's actually a poor choice for both.

For example, you can find a python script that calculates THD for a wav file. But it produces very strange and incomprehensible results, different from the Matlab/Octave implementation, and the correct result is given by Matlab/Octave, just like with other calculations - at first glance, all these python packages seem to calculate what is needed, but you can't trust them. The same for scikit-rf and other. And it is very slow. If you want a more accurate result with proper calculation and with many math tools, then your choice is Matlab/Octave.

As for scripting languages, in my opinion js is better than python and js more universal and faster, because unlike python, js uses jit. js has worse support for precise math (it has extended packages, but its complicated to use them), but it is supported on any platform with browser. While for precise math you can use Matlab/Octave.


In practice I just use either C or Octave, running the file directly from the Geany text editor with the Run button. I set the Run button to compile the file and run it, and it's very convenient - you just create a calc.c or calc.m ​​file, enter a couple of lines of code, press Run, and see the result. And there is no need for python at all.

« Last Edit: June 03, 2025, 12:12:35 am by radiolistener »
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 782
  • Country: us
Re: S-Parameter Plotter
« Reply #8 on: June 03, 2025, 12:15:29 am »
Unless someone already has the Matlab baggage in their brain (hey, a lot of us do!), I would suggest not learning Octave.  Far better to use python instead.  There's even an actively developed, RF-focused "toolkit" for python called scikit-rf.  I believe it can do most of the things you're suggesting here.

I don't agree, I tried python, but its very slow and has many issues. I'm using C, C++ and C# instead. But programming language is not a replacement for Matlab/Octave. You need both. Matlab/Octave for calculations, filters/model design, plots, etc. Programming language for applied implementation of algorithms. Python is often seen as a middle ground, but it's actually a poor choice for both.

For example, you can find a python script that calculates THD for a wav file. But it produces very strange and incomprehensible results, different from the Matlab/Octave implementation, and the correct result is given by Matlab/Octave, just like with other calculations - at first glance, all these python packages seem to calculate what is needed, but you can't trust them. The same for scikit-rf and other. And it is very slow. If you want a more accurate result with proper calculation and with many math tools, then your choice is Matlab/Octave.

As for scripting languages, in my opinion js is better than python and js more universal and faster, because unlike python, js uses jit

Well, without getting into a programming language holy war, I will simply say that if you are comfortable doing your simulations in FORTRAN (which is essentially what Matlab/Octave is---very little difference in programming constructs, program structure, etc.), then by all means, stick with that.  But there are reasons why most people have moved on to languages like python for clarity and maintainability.  At some point you won't even need to deploy an argument like that:  the sheer mindshare advantage of python (or its eventual replacement) will be all the reason needed to switch to it.

Certainly C/C++ is best if you care about speed.  But I suspect that is irrelevant for the vast majority of engineering calculation/simulation work.

Python with numpy/scipy now predominates in most academic settings.  Certainly the $$$ licensing costs of Matlab are part of the reason, but at some point the reasons don't matter anymore---you'll need to switch just to benefit from the larger body of tools/expertise/code.

Finally, if you are worried about unvetted algorithms in packages like numpy and scipy, I hope you are using Matlab, the real thing.  Because I'd trust any of the standard python packages over Octave for accuracy and correctness, any day.

And that is all I'll say  :box:
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5742
  • Country: Earth
Re: S-Parameter Plotter
« Reply #9 on: June 03, 2025, 12:20:25 am »
For frequently used scenarios such as quick RF calculations and conversion of values ​​I used to use my calculators in C#, but now I have rewritten them in html with js and they work great on any machine. Html allows you to implement a GUI for input/output of values, graphs and even sound. For example, I wrote a small page that allows you to translate text into Morse code and back for different languages, as well as play Morse code at any selected speed. :)
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5742
  • Country: Earth
Re: S-Parameter Plotter
« Reply #10 on: June 03, 2025, 12:44:17 am »
I will simply say that if you are comfortable doing your simulations in FORTRAN (which is essentially what Matlab/Octave is---very little difference in programming constructs, program structure, etc.), then by all means, stick with that. 

Matlab and Octave are high-level interpreted languages focused on numerical computing, matrix operations, data visualization, and scientific tasks. Their syntax is similar to each other but has nothing in common with Fortran at the language level.

But there are reasons why most people have moved on to languages like python for clarity and maintainability.  At some point you won't even need to deploy an argument like that:  the sheer mindshare advantage of python (or its eventual replacement) will be all the reason needed to switch to it.

Certainly C/C++ is best if you care about speed.  But I suspect that is irrelevant for the vast majority of engineering calculation/simulation work.

I personally don't see a strong need for Python in the context of engineering calculations or simulations. Matlab/Octave handles such tasks exceptionally well, especially for matrix operations and numerical algorithms.

If performance is critical or a more application-level implementation is needed, it's straightforward to write performance-critical components in C and call them from Octave using MEX interfaces. This provides a powerful and efficient workflow.

In this point of view, there are few, if any, areas where Python would offer a significant advantage. Python may be helpful for those less familiar with lower-level languages, but if you're comfortable with C, the combination of Octave and C covers most scientific and engineering needs effectively.

When complex object-oriented structures are required, I prefer to write in C#. While it's slightly slower than C, it offers a clean and readable OOP syntax along with strong safety features - such as bounds checking and memory management, which help avoid issues like buffer overflows or accessing freed memory. This makes development more robust without sacrificing much performance in most engineering applications.

Another alternative for OOP development is Java. Its JIT compiler is amazingly fast - in many cases, performance comes very close to that of C compiler.

But Python still relies on an interpreter and lacks JIT compilation, making it very slow. I also don't see compelling use cases for it, as there are more suitable alternatives for other languages available.

Certainly the $$$ licensing costs of Matlab are part of the reason, but at some point the reasons don't matter anymore---you'll need to switch just to benefit from the larger body of tools/expertise/code.

GNU Octave is free and can run almost any code written for Matlab.


I hope you are using Matlab, the real thing.  Because I'd trust any of the standard python packages over Octave for accuracy and correctness, any day.

I used to work with Matlab and R in the past, but nowadays I primarily use Octave. Based on my experience, Octave provides more accurate results than standard Python packages, mainly because Python libraries tend to use simplified algorithms in many cases, whereas Octave implementations are often more complete and closer to the original mathematical formulations.

That said, there are indeed some differences between Octave and Matlab - for example, certain windowing functions may produce slightly different results. These differences aren't necessarily incorrect, but they can diverge from Matlab's output due to implementation details. If you want exactly the same result on Matlab and Octave using such functions, you can replace it with your own implementation and it will works exactly the same. Nonetheless, for many engineering and scientific tasks, Octave remains a reliable and precise tool.

I have greater trust to Octave than to Python.


In the past, I frequently used C# for filter design and graphical visualization via Direct2D for GPU-accelerated vector graphics on Windows. However, Octave now offers a very convenient Qt-based plotting backend, which I’ve complemented with a few custom wrappers to streamline usage. For example, loading a WAV file, computing its FFT, and plotting the spectrum takes just a few lines of code in Octave. Surprisingly, even a 32 million-point FFT runs very efficiently even on a Raspberry Pi, faster than FFTW.


PS: and another issue with Python, is that their packages often contains malware and spyware which steal your credentials, personal data and tracking information...
« Last Edit: June 03, 2025, 01:37:21 am by radiolistener »
 

Offline MisterHeadache

  • Regular Contributor
  • *
  • Posts: 152
  • Country: us
    • Level UP EE Lab
Re: S-Parameter Plotter
« Reply #11 on: June 04, 2025, 02:20:01 pm »
FWIW, I figured out how to plot .s11 data (in real/imaginary format) in Excel and get a Smith chart.  Turns out it's stupidly easy, just choose scatter plot and set both the X and Y axis ranges to -1.1 / + 1.1 (the extra tenth adds a bit of space for the outer circle).  Drawing the gradient circles was much harder to figure out!  In my spreadsheet I also calculate the return loss, reflection coefficient, VSWR, and impedance (scalar, real, and imaginary).

I used this to visually compare multple nanoVNA .s11 files at the same scale, plus do the calcuations.  Maybe this doesn't fill the need of the OP, but I thought I'd just share my experience.
Daryn from Level Up EE Lab
AKA 'MisterHeadache'
 

Offline k6stiTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: S-Parameter Plotter
« Reply #12 on: June 12, 2025, 11:42:35 pm »


Make one VNA measurement of a crystal filter with no matching network. Then find the best filter termination by rotating the mouse wheel to vary the renormalization impedance. This method is faster and easier than doing the same thing experimentally with solder.

An animated PNG illustrating this does not animate here. The image shows the response envelope for impedance changes from 500 to 2100 ohms. The animated PNG is in this writeup:

https://k6sti.neocities.org/splot.htm

Brian
« Last Edit: June 13, 2025, 08:56:46 am by k6sti »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->