Here it is in C and Perl:
--------------- C -----------------
/*
Take Z, SWR from RF-1 as two command line args, output R and X
Only accurate if:
a) SWR is > 1.2 and < 6 (better if less than 4)
b) ratio of R/X between .2 and 5
To determine sign of X:
a) add 5pf cap to load, if Z increases X is positive if decreases, neg.
b) if Z increases with increased frequency, X is positive
if Z decreases with increased frequency, X is negative
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main( int argc, char **argv )
{
float z,s,r,x;
if( argc != 3 ) {
fprintf( stderr, "usage: imp Z SWR\n");
exit(1);
}
sscanf( argv[1], "%f", &z );
sscanf( argv[2], "%f", &s );
r = ( ( 2500.0 + ( z * z ) ) * s ) / ( 50.0 * ( ( s * s ) + 1.0 ) );
x = sqrtf( fabsf( ( z * z ) - ( r * r ) ) );
fprintf( stdout, "%6.1f (+/-)%6.1f\n", r, x );
}
--------------- Perl -----------------
#!/usr/local/bin/perl
#
# Take Z, SWR from RF-1 as two command line args, output R and X
#
# Only accurate if:
# a) SWR is > 1.2 and < 6 (better if less than 4)
# b) ratio of R/X between .2 and 5
#
# To determine sign of X:
#
# a) add 5pf cap to load, if Z increases X is positive if decreases, neg.
# b) if Z increases with increased frequency, X is positive
# if Z decreases with increased frequency, X is negative
#
if( @ARGV != 2 ) {
printf("usage: imp.pl Z SWR\n");
exit(1);
}
$z = $ARGV[0];
$s = $ARGV[1];
$r = ( ( 2500.0 + ( $z * $z ) ) * $s ) / ( 50.0 * ( ( $s * $s ) + 1.0 ) );
if( $z > $r ) {
$x = sqrt( ( $z * $z ) - ( $r * $r ) );
} else {
$x = sqrt( ( $r * $r ) - ( $z * $z ) );
}
printf( "%6.1f (+/-)%6.1f\n", $r, $x );
-----------------------------------------------
Regards,
Pete
KS4XG
--
FAQ on WWW: http://www.contesting.com/towertalkfaq.html
Submissions: towertalk@contesting.com
Administrative requests: towertalk-REQUEST@contesting.com
Problems: owner-towertalk@contesting.com
|