リグエキスパートのAA-30.ZEROグラフ描画(3)

もっと良い方法があるとは思いますが、これでも動きます。

/* Data Converter for Rig Expert AA-30.ZERO */
/* % g++ bb30.cpp -o bb30 */
#include <complex>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(int argc, char *argv[]) {
  string fval, rval, xval;
  double f, r, x;
  double absz, retloss, vswr;
  complex<double> z, rho;
  const complex<double> z0 = 50.0;

  while (!cin.eof()) {
    getline(cin, fval, ',');
    getline(cin, rval, ',');
    getline(cin, xval, '\n');

    stringstream(fval) >> f;
    stringstream(rval) >> r; if(r<0) r=0.01;
    stringstream(xval) >> x;

    z       = complex<double>(r,x);
    absz    = abs(z);
    rho     = (z-z0)/(z+z0);
    retloss = -20.0 * log( abs(rho) ) / log( 10.0 );
    vswr    = ( 1+abs(rho) ) / ( 1-abs(rho) );

    cout << f << ", " << r << ", " << x << ", " << absz << ", "
         << retloss << ", " << vswr << ", "
         << arg(rho) << ", " << abs(rho) << endl;
  }
}
# Gnuplot script for AA-30.ZERO

reset
set terminal aqua enhanced title 'AA-30.ZERO' size 1200 900
set multiplot layout 2,2 title 'My Antenna'
set grid
unset key

fname = 'mydata.txt'
set datafile separator ','

set title 'Impedance (R, X, and Z)'
plot   fname using 1:2 with line linewidth 3, \
       ''    using 1:3 with line linewidth 3, \
       ''    using 1:4 with line linewidth 3, \
       0.0             with line linewidth 3 lc "#80000000"

stats '' using 1:5 nooutput
set title sprintf("Retrun Loss (max = %6.2fdB at %6.3fMHz)", STATS_max_y, STATS_pos_max_y)
plot '' using 1:5 with line linewidth 3 linetype 4


stats '' using 1:6 nooutput
set title sprintf("VSWR (min = %6.2f at %6.3fMHz)", STATS_min_y, STATS_pos_min_y)
set yrange [1:10]
plot '' using 1: 6 with line linewidth 3 linetype 7, \
     1.0           with line linewidth 3 lc "#80000000"

set title 'Smith Chart'
set polar
set grid polar
set size square
set xrange [-1:+1]
set yrange [-1:+1]
plot '' using 7:8 with line linewidth 3 linetype 6

unset multiplot
reset
% ./aa30zero /dev/cu.usbmodem1461 fq3500000 sw3000000 frx300 | ./bb30 > mydata.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.