How to Process the 2D Antenna Pattern Text Files using PHP Script?


Antennas are not easy to manufacture, and their patterns are usually represented using 2x2D array. For example, the below represents a horizontal antenna pattern that contains 360 gain values which are stored by 36 (rows) times 10 (columns).

#HUBER+SUHNER AG XXXX / XXXX 0627/360/7/0/MIMO / File name:XXXX
#XXXX / Version 1
Name = 1399.17.0229
Number of Points = 360
Start Ang. = 0
Range = 40.000000
Increment = 1.0
Orientation = Horizontal
-3.89 -4.08 -4.27 -4.47 -4.66 -4.85 -5.05 -5.25 -5.44 -5.64 
-5.84 -6.04 -6.24 -6.44 -6.64 -6.83 -7.03 -7.22 -7.42 -7.61 
-7.81 -7.98 -8.16 -8.34 -8.51 -8.69 -8.82 -8.94 -9.07 -9.20 
-9.32 -9.36 -9.40 -9.43 -9.47 -9.50 -9.43 -9.36 -9.29 -9.22 
-9.15 -9.01 -8.87 -8.72 -8.58 -8.44 -8.28 -8.13 -7.97 -7.81 
-7.66 -7.53 -7.39 -7.26 -7.13 -7.00 -6.92 -6.83 -6.75 -6.66 
-6.58 -6.55 -6.52 -6.49 -6.46 -6.43 -6.45 -6.47 -6.50 -6.52 
-6.54 -6.62 -6.70 -6.77 -6.85 -6.93 -7.06 -7.19 -7.32 -7.45 
-7.58 -7.76 -7.94 -8.12 -8.30 -8.49 -8.72 -8.95 -9.18 -9.41 
-9.64 -9.89 -10.14 -10.39 -10.64 -10.89 -11.08 -11.26 -11.45 -11.63 
-11.82 -11.81 -11.79 -11.78 -11.77 -11.76 -11.53 -11.31 -11.09 -10.86 
-10.64 -10.34 -10.04 -9.74 -9.44 -9.14 -8.88 -8.61 -8.35 -8.08 
-7.82 -7.63 -7.44 -7.25 -7.06 -6.87 -6.77 -6.67 -6.56 -6.46 
-6.36 -6.34 -6.32 -6.30 -6.28 -6.26 -6.31 -6.37 -6.42 -6.47 
-6.53 -6.63 -6.73 -6.83 -6.94 -7.04 -7.14 -7.24 -7.34 -7.44 
-7.54 -7.57 -7.59 -7.62 -7.64 -7.66 -7.56 -7.46 -7.36 -7.25 
-7.15 -6.95 -6.75 -6.54 -6.34 -6.14 -5.91 -5.67 -5.44 -5.20 
-4.97 -4.75 -4.53 -4.31 -4.09 -3.87 -3.68 -3.50 -3.31 -3.13 
-2.94 -2.79 -2.65 -2.50 -2.35 -2.20 -2.09 -1.97 -1.86 -1.75 
-1.63 -1.55 -1.46 -1.37 -1.29 -1.20 -1.14 -1.08 -1.01 -0.95 
-0.89 -0.85 -0.81 -0.76 -0.72 -0.68 -0.66 -0.63 -0.61 -0.58 
-0.56 -0.54 -0.53 -0.52 -0.51 -0.50 -0.51 -0.51 -0.51 -0.51 
-0.51 -0.53 -0.54 -0.55 -0.56 -0.58 -0.60 -0.62 -0.64 -0.66 
-0.68 -0.70 -0.73 -0.75 -0.78 -0.80 -0.83 -0.86 -0.89 -0.92 
-0.95 -0.98 -1.01 -1.03 -1.06 -1.09 -1.12 -1.15 -1.18 -1.21 
-1.24 -1.26 -1.29 -1.32 -1.35 -1.37 -1.40 -1.42 -1.44 -1.46 
-1.49 -1.50 -1.52 -1.54 -1.55 -1.57 -1.57 -1.58 -1.58 -1.59 
-1.59 -1.58 -1.58 -1.57 -1.56 -1.55 -1.53 -1.51 -1.48 -1.46 
-1.43 -1.40 -1.36 -1.32 -1.28 -1.24 -1.19 -1.14 -1.09 -1.04 
-0.99 -0.94 -0.89 -0.83 -0.78 -0.73 -0.67 -0.62 -0.57 -0.52 
-0.47 -0.43 -0.38 -0.34 -0.30 -0.26 -0.22 -0.19 -0.16 -0.13 
-0.10 -0.08 -0.06 -0.05 -0.03 -0.02 -0.01 -0.01 -0.01 -0.01 
-0.01 -0.02 -0.04 -0.06 -0.07 -0.09 -0.13 -0.16 -0.20 -0.23 
-0.27 -0.33 -0.39 -0.44 -0.50 -0.56 -0.64 -0.72 -0.81 -0.89 
-0.97 -1.08 -1.19 -1.30 -1.41 -1.51 -1.65 -1.79 -1.92 -2.06 
-2.19 -2.35 -2.51 -2.67 -2.83 -2.99 -3.17 -3.35 -3.53 -3.71 

How to construct 3D Full Antenna Pattern from Both Horizontal and Vertical 1-D array?

You might need the interopolation methods, that allow you to construct an estimate of a full 3D pattern given 2x2D gain values. The industry uses 2x2D gain values to represent an antenna for simplicity.

directional-antenna-pattern-3d How to Process the 2D Antenna Pattern Text Files using PHP Script? Antenna

directional-antenna-pattern-3d

Full 360 antenna gain matrix need to be applied to Path Loss, in order to compute the signal strength, for example:

tex_7ee95bd57c1e6c2d6d481e435b70a217 How to Process the 2D Antenna Pattern Text Files using PHP Script? Antenna

where Pr and Pt are signal strength for receiver and transmitter respectively. The G is the antenna gains (for both transmitter and receiver), and the L denotes the path loss.

How to Extract Gain Values from Antenna Text File?

We want to merge two gain text files into one, something like this:

0 h1 v1
1 h2 v2
2 h3 v3
..
..
359 h359 v359

The quickest way is to copy these 360 gain values for horizontal and vertical patterns respectively into spreadsheet e.g. Microsoft Excel. So how to extract 36×10 gain matrix into 360 gain values?

Let’s create a PHP script e.g. process_ant.php with the following content:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// https://propagationtools.com/wireless/how-to-process-the-2d-antenna-pattern-text-files-using-php-script/
if (count($argv) >= 1) {
    echo ("files missing"); 
    die();
}
 
function process_pat($filename) {
    $s = file_get_contents($filename);
    $array = preg_split('/\s*\R\s*/', trim($s), NULL, PREG_SPLIT_NO_EMPTY);
    $r = array();
    foreach ($array as $line) {
        if ($line[0] == '#') continue;
        $tmp = explode(' ', $line);     
        if (count($tmp) >= 2) { // if it looks like pattern values
            $r = array_merge($r, $tmp);
        }
    }
    return $r;
}
 
for ($i = 1; $i < count($argv); ++ $i) {
    $filename = $argv[$i];
    if (!is_file($filename)) {
        echo "cannot open: $filename\n";
        continue;
    }
        
    $r = process_pat($filename);
    if (count($r) == 0) continue;
 
    $s = "";
    foreach ($r as $t) {
        $s .= "$t\r\n";
    }
 
    file_put_contents($filename . ".txt", $s);
    echo "Saved: $filename\n";
}
// https://propagationtools.com/wireless/how-to-process-the-2d-antenna-pattern-text-files-using-php-script/
if (count($argv) >= 1) {
	echo ("files missing");	
	die();
}

function process_pat($filename) {
	$s = file_get_contents($filename);
	$array = preg_split('/\s*\R\s*/', trim($s), NULL, PREG_SPLIT_NO_EMPTY);
	$r = array();
	foreach ($array as $line) {
		if ($line[0] == '#') continue;
		$tmp = explode(' ', $line);		
		if (count($tmp) >= 2) { // if it looks like pattern values
			$r = array_merge($r, $tmp);
		}
	}
	return $r;
}

for ($i = 1; $i < count($argv); ++ $i) {
	$filename = $argv[$i];
	if (!is_file($filename)) {
		echo "cannot open: $filename\n";
		continue;
	}
		
	$r = process_pat($filename);
	if (count($r) == 0) continue;

	$s = "";
	foreach ($r as $t) {
		$s .= "$t\r\n";
	}

	file_put_contents($filename . ".txt", $s);
	echo "Saved: $filename\n";
}

This script converts antenna files to text files that contain 360 lines of values. For example,

1
php process_ant.php sample.pat
php process_ant.php sample.pat

That will read sample.pat and write to sample.pat.txt. You can loop folders recursively for all pattern files, for example (Windows Command Line Prompt):

FOR /F "usebackq delims==" %i IN (`dir /s /b *`) do php process_ant.php "%i"

For Linux shells, use this instead:

1
find . -name \* -exec php process_ant.php {} \;
find . -name \* -exec php process_ant.php {} \;
980 words Last Post: Download Paris Digital Map and Measurements
Next Post: Interview Questions for Wireless Software Engineer


Leave a Reply

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