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