line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RF::Functions; |
2
|
1
|
|
|
1
|
|
60652
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
440
|
use POSIX qw{log10}; |
|
1
|
|
|
|
|
5595
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
1187
|
use base qw{Exporter}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
112
|
|
6
|
1
|
|
|
1
|
|
418
|
use Math::Round qw{}; |
|
1
|
|
|
|
|
965
|
|
|
1
|
|
|
|
|
267
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(db_ratio ratio2db ratio_db db2ratio fsl_hz_m fsl_mhz_km fsl_ghz_km); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
RF::Functions - Perl Exporter for Radio Frequency (RF) Functions |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use RF::Functions qw{db_ratio ratio_db}; |
18
|
|
|
|
|
|
|
my $db = db_ratio(2); #~3dB |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
RF::Functions is a lib for common RF function. I plan to add additional functions as I need them. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 FUNCTIONS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 db_ratio, ratio2db |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Returns dB given a numerical power ratio. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $db = db_ratio(2); #+3dB |
31
|
|
|
|
|
|
|
my $db = db_ratio(1/2); #-3dB |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
1
|
82
|
sub db_ratio {10 * log10(shift())}; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
1
|
15
|
sub ratio2db {10 * log10(shift())}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 ratio_db, db2ratio |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Returns power ratio given dB. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $power_ratio = ratio_db(3); #2 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
1
|
11
|
sub ratio_db {10 ** (shift()/10)}; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
2
|
1
|
11
|
sub db2ratio {10 ** (shift()/10)}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 fsl_hz_m, fsl_mhz_km, fsl_ghz_km |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Return power loss in dB given frequency and distance in the specified units of measure |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $free_space_loss = fsl_mhz_km($mhz, $km); #returns dB |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub fsl_hz_m { |
60
|
1
|
|
|
1
|
1
|
258
|
my ($f, $d) = @_; |
61
|
1
|
|
|
|
|
3
|
return _fsl_constant($f, $d, -147.55); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub fsl_mhz_km { |
65
|
1
|
|
|
1
|
1
|
3
|
my ($f, $d) = @_; |
66
|
1
|
|
|
|
|
3
|
return _fsl_constant($f, $d, 32.45); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub fsl_ghz_km { |
70
|
1
|
|
|
1
|
1
|
267
|
my ($f, $d) = @_; |
71
|
1
|
|
|
|
|
3
|
return _fsl_constant($f, $d, 92.45); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _fsl_constant { |
75
|
3
|
|
|
3
|
|
4
|
my $freq = shift; |
76
|
3
|
|
|
|
|
4
|
my $dist = shift; |
77
|
3
|
|
|
|
|
4
|
my $const = shift; |
78
|
|
|
|
|
|
|
#Equvalent to 20log($freq) + 20log($dist) + $const for performance |
79
|
3
|
|
|
|
|
18
|
return Math::Round::nearest(0.001, 20 * log10($freq * $dist) + $const); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SEE ALSO |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L, L |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Michael R. Davis, MRDVT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
MIT LICENSE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Copyright (C) 2022 by Michael R. Davis |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |