blib/lib/RF/LTE/EARFCN.pm

filter: Statementstmt 91.8% 68 / 74 Branchbran 82.6% 38 / 46 Conditioncond 80.0% 12 / 15 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 80.9% 17 / 21 Podpod 100% 15 / 15 totaltotal 86.0% 154 / 179 CC 30 SCAR 17.6
CC
30
Cov
87%
_row
13.2
channel_type
6.5
ful
4.0
CRAP 5.8
↑ Summary
1 package RF::LTE::EARFCN;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use base qw{Package::New};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Scalar::Util qw{dualvar};
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp qw{croak};
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.02';
9  
10 =head1 NAME
11  
12 RF::LTE::EARFCN - LTE EARFCN Channel to Frequency Converter
13  
14 =head1 SYNOPSIS
15  
16 use RF::LTE::EARFCN;
17 my $rf = RF::LTE::EARFCN->new(channel=>5110);
18 printf "Channel: %s\n Frequency (dl): %s\n Frequency (ul): %s\n Frequency Separation: %s\n",
19 $rf->channel, $rf->fdl, $rf->ful, $rf->fs;
20  
21 =head1 DESCRIPTION
22  
23 This LTE EARFCN Channel to Frequency Converter uses the functions and tables in sections 5.7.3 and 5.7.4 of ETSI TS 136 101 V17.6.0 (2022-08) to convert EARFCN Channel to Frequency Downlink (fdl), Frequency Uplink (ful), and Frequency Separation (fs).
24  
25 The carrier frequency in the uplink and downlink is designated by the E-UTRA Absolute Radio Frequency Channel
26 Number (EARFCN) in the range 0 - 262143. The relation between EARFCN and the carrier frequency in MHz for the
27 downlink is given by the following equation, where FDL_low and NOffs_DL are given in Table 5.7.3-1 and NDL is the
28 downlink EARFCN.
29  
30 FDL = FDL_low + 0.1(NDL - NOffs_DL)
31  
32 The relation between EARFCN and the carrier frequency in MHz for the uplink is given by the following equation
33 where FUL_low and NOffs_UL are given in Table 5.7.3-1 and NUL is the uplink EARFCN.
34  
35 FUL = FUL_low + 0.1(NUL - NOffs_UL)
36  
37 The relationship between frequency uplink and frequency downlink can also be calculated using table 5.7.4.
38  
39 FDL = FUL + FS
40 FUL = FDL - FS
41  
42 =head1 METHODS
43  
44 =head2 new
45  
46 =head1 PROPERTIES
47  
48 =head2 channel
49  
50 Sets and returns the EARFCN channel number. The logic is written so that the channel number can be either the downlink or uplink channel number and the correct frequency calculation is used.
51  
52 my $rf = RF::LTE::EARFCN->new(channel=>5110);
53 $rf->channel(5110);
54 my $channel = $rf->channel;
55  
56 =cut
57  
58 1633 ▶sub channel {
Subroutine channel: called CC=4 SCAR=13.9
Pod documented
59 1633 my $self = shift;
60 1633 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 307 1326 1633
61 307 $self->{'channel'} = shift;
62 307 undef($self->{'_row'}); #clears _row
63 307 undef($self->{'channel_type'}); #clears channel_type
64 }
65 1633 ▶ croak('Error: channel required') unless defined $self->{'channel'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"channel"} 1 1632 1633
66 1632 ▶ croak('Error: channel must be zero or greater') unless $self->{'channel'} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"channel"} >= 0 1 1631 1632
67 1631 return $self->{'channel'};
68 }
69  
70 =head2 channel_type
71  
72 Returns either 'ul' or 'dl' based on whether the channel is an uplink or downlink channel number.
73  
74 my $channel_type = $rf->channel_type; #ISA String 'dl'||'ul'
75  
76 =cut
77  
78 708 ▶sub channel_type {
Subroutine channel_type: called CC=6 SCAR=18.7
Pod documented
79 708 my $self = shift;
80 708 ▶ $self->{'channel_type'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 708 708
81 708 ▶ $self->_row unless $self->{'channel_type'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"channel_type"} 303 405 708
82 707 ▶ croak('Error: channel_type not defined') unless defined $self->{'channel_type'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"channel_type"} 0 707 707
83 707 ▶ croak('Error: channel_type invalid') unless ($self->{'channel_type'} eq 'dl' or $self->{'channel_type'} eq 'ul');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"channel_type"} eq "dl" or $self->{"channel_type"} eq "ul" 0 707 707
Condition66%2/3
$self->{"channel_type"} eq "dl" or $self->{"channel_type"} eq "ul"
l!l&&r!l&&!r
4073000
MC/DC0%0/2
$self->{"channel_type"} eq "dl" or $self->{"channel_type"} eq "ul"
$self->{"channel_type"} eq "dl" $self->{"channel_type"} eq "ul"
Truth table66%2/3
A or B
A= $self->{"channel_type"} eq "dl"B= $self->{"channel_type"} eq "ul"
ABresult
1X1
011
000
84 707 return $self->{'channel_type'};
85 }
86  
87 # From: https://www.etsi.org/deliver/etsi_ts/136100_136199/136101/17.06.00_60/ts_136101v170600p.pdf
88 # LTE; Evolved Universal Terrestrial Radio Access (E-UTRA);
89 # User Equipment (UE) radio transmission and reception (3GPP TS 36.101 version 17.6.0 Release 17)
90 # Section: 5.7.3 Carrier frequency and EARFCN
91 # Table 5.7.3-1: E-UTRA channel numbers
92 # Columns
93 # E-UTRA Operating Band
94 # Downlink FDL_low (MHz)
95 # Downlink NOffs_DL
96 # Downlink Range of NDL Lower
97 # Downlink Range of NDL Upper
98 # Uplink FUL_low (MHz)
99 # Uplink NOffs_UL
100 # Uplink Range of NUL Lower
101 # Uplink Range of NUL Upper
102  
103 4 our @BAND_TABLE = map {[split]} (
104 '1 2110 0 0 599 1920 18000 18000 18599',
105 '2 1930 600 600 1199 1850 18600 18600 19199',
106 '3 1805 1200 1200 1949 1710 19200 19200 19949',
107 '4 2110 1950 1950 2399 1710 19950 19950 20399',
108 '5 869 2400 2400 2649 824 20400 20400 20649',
109 '6 875 2650 2650 2749 830 20650 20650 20749',
110 '7 2620 2750 2750 3449 2500 20750 20750 21449',
111 '8 925 3450 3450 3799 880 21450 21450 21799',
112 '9 1844.9 3800 3800 4149 1749.9 21800 21800 22149',
113 '10 2110 4150 4150 4749 1710 22150 22150 22749',
114 '11 1475.9 4750 4750 4949 1427.9 22750 22750 22949',
115 '12 729 5010 5010 5179 699 23010 23010 23179',
116 '13 746 5180 5180 5279 777 23180 23180 23279',
117 '14 758 5280 5280 5379 788 23280 23280 23379',
118 '17 734 5730 5730 5849 704 23730 23730 23849',
119 '18 860 5850 5850 5999 815 23850 23850 23999',
120 '19 875 6000 6000 6149 830 24000 24000 24149',
121 '20 791 6150 6150 6449 832 24150 24150 24449',
122 '21 1495.9 6450 6450 6599 1447.9 24450 24450 24599',
123 '22 3510 6600 6600 7399 3410 24600 24600 25399',
124 '23 2180 7500 7500 7699 2000 25500 25500 25699',
125 '24 1525 7700 7700 8039 1626.5 25700 25700 26039',
126 '25 1930 8040 8040 8689 1850 26040 26040 26689',
127 '26 859 8690 8690 9039 814 26690 26690 27039',
128 '27 852 9040 9040 9209 807 27040 27040 27209',
129 '28 758 9210 9210 9659 703 27210 27210 27659',
130 '29 717 9660 9660 9769',
131 '30 2350 9770 9770 9869 2305 27660 27660 27759',
132 '31 462.5 9870 9870 9919 452.5 27760 27760 27809',
133 '32 1452 9920 9920 10359',
134 '33 1900 36000 36000 36199 1900 36000 36000 36199',
135 '34 2010 36200 36200 36349 2010 36200 36200 36349',
136 '35 1850 36350 36350 36949 1850 36350 36350 36949',
137 '36 1930 36950 36950 37549 1930 36950 36950 37549',
138 '37 1910 37550 37550 37749 1910 37550 37550 37749',
139 '38 2570 37750 37750 38249 2570 37750 37750 38249',
140 '39 1880 38250 38250 38649 1880 38250 38250 38649',
141 '40 2300 38650 38650 39649 2300 38650 38650 39649',
142 '41 2496 39650 39650 41589 2496 39650 39650 41589',
143 '42 3400 41590 41590 43589 3400 41590 41590 43589',
144 '43 3600 43590 43590 45589 3600 43590 43590 45589',
145 '44 703 45590 45590 46589 703 45590 45590 46589',
146 '45 1447 46590 46590 46789 1447 46590 46590 46789',
147 '46 5150 46790 46790 54539 5150 46790 46790 54539',
148 '47 5855 54540 54540 55239 5855 54540 54540 55239',
149 '48 3550 55240 55240 56739 3550 55240 55240 56739',
150 '49 3550 56740 56740 58239 3550 56740 56740 58239',
151 '50 1432 58240 58240 59089 1432 58240 58240 59089',
152 '51 1427 59090 59090 59139 1427 59090 59090 59139',
153 '52 3300 59140 59140 60139 3300 59140 59140 60139',
154 '53 2483.5 60140 60140 60254 2483.5 60140 60140 60254',
155 '65 2110 65536 65536 66435 1920 131072 131072 131971',
156 '66 2110 66436 66436 67335 1710 131972 131972 132671',
157 '67 738 67336 67336 67535',
158 '68 753 67536 67536 67835 698 132672 132672 132971',
159 '69 2570 67836 67836 68335',
160 '70 1995 68336 68336 68585 1695 132972 132972 133121',
161 '71 617 68586 68586 68935 663 133122 133122 133471',
162 '72 461 68936 68936 68985 451 133472 133472 133521',
163 '73 460 68986 68986 69035 450 133522 133522 133571',
164 '74 1475 69036 69036 69465 1427 133572 133572 134001',
165 '75 1432 69466 69466 70315',
166 '76 1427 70316 70316 70365',
167 '85 728 70366 70366 70545 698 134002 134002 134181',
168 '87 420 70546 70546 70595 410 134182 134182 134231',
169 '88 422 70596 70596 70645 412 134232 134232 134281',
170 '103 757 70646 70646 70655 787 134282 134282 134291',
171 );
172  
173 1023 ▶sub _row {
Subroutine _row: called CC=13 SCAR=25.8
174 1023 my $self = shift;
175 1023 my $channel = $self->channel;
176 1023 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1023 1023
177 0 $self->{'_row'} = undef;
178 0 $self->{'channel_type'} = undef;
179 }
180 1023 ▶ unless ($self->{'_row'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_row"}) 305 718 1023
181 305 my $found;
182 my $channel_type;
183 305 foreach my $row (@BAND_TABLE) {
184 3108 ▶ if ($row->[3] <= $channel and $channel <= $row->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->[3] <= $channel and $channel <= $row->[4]) 204 2904 3108
Condition66%2/3
$row->[3] <= $channel and $channel <= $row->[4]
!ll&&!rl&&r
02904204
MC/DC50%1/2
$row->[3] <= $channel and $channel <= $row->[4]
$row->[3] <= $channel $channel <= $row->[4]
Truth table66%2/3
A and B
A= $row->[3] <= $channelB= $channel <= $row->[4]
ABresult
0X0
100
111
185 204 $found = $row;
186 204 $channel_type = 'dl';
187 }
188 3108 ▶ last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 204 2904 3108
189 2904 ▶ if (defined($row->[7]) and defined($row->[8]) and $row->[7] <= $channel and $channel <= $row->[8]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $row->[7] and defined $row->[8] and $row->[7] <= $channel and $channel <= $row->[8]) 100 2804 2904
Condition88%8/9
defined $row->[7] and defined $row->[8] and $row->[7] <= $channel and $channel <= $row->[8]
!ll&&!rl&&r
2643161100
defined $row->[7] and defined $row->[8] and $row->[7] <= $channel
!ll&&!rl&&r
62637261
defined $row->[7] and defined $row->[8]
!ll&&!rl&&r
602898
MC/DC75%3/4
defined $row->[7] and defined $row->[8] and $row->[7] <= $channel and $channel <= $row->[8]
defined $row->[7] defined $row->[8] $row->[7] <= $channel $channel <= $row->[8]
Truth table80%4/5
A and B and C and D
A= defined $row->[7]B= defined $row->[8]C= $row->[7] <= $channelD= $channel <= $row->[8]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
190 #Not sure how to support ul at this time...
191 100 $found = $row;
192 100 $channel_type = 'ul';
193 }
194 2904 ▶ last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 100 2804 2904
195 }
196 305 ▶ die(qq{Error: table entry not found for channel "$channel"}) unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 1 304 305
197 304 $self->{'_row'} = $found;
198 304 $self->{'channel_type'} = $channel_type;
199 }
200 1022 return $self->{'_row'};
201 }
202  
203 =head2 band, fdl_low, noffs_dl, range_ndl_lower, range_ndl_upper, ful_low, noffs_ul, range_nul_lower, range_nul_upper, band_note2
204  
205 Returns the table values directly from the table based on the channel.
206  
207 my $band = $rf->band;
208  
209 =cut
210  
211 7 ▶sub band {shift->_row->[0]};
Subroutine band: called CC=1 SCAR=0.0
Pod documented
212 203 ▶sub fdl_low {shift->_row->[1]};
Subroutine fdl_low: called CC=1 SCAR=0.0
Pod documented
213 203 ▶sub noffs_dl {shift->_row->[2]};
Subroutine noffs_dl: called CC=1 SCAR=0.0
Pod documented
214 0 ▶sub range_ndl_lower {shift->_row->[3]};
Subroutine range_ndl_lower: not called CC=1 SCAR=6.9
Pod documented
215 0 ▶sub range_ndl_upper {shift->_row->[4]};
Subroutine range_ndl_upper: not called CC=1 SCAR=6.9
Pod documented
216 100 ▶sub ful_low {shift->_row->[5]};
Subroutine ful_low: called CC=1 SCAR=0.0
Pod documented
217 100 ▶sub noffs_ul {shift->_row->[6]};
Subroutine noffs_ul: called CC=1 SCAR=0.0
Pod documented
218 0 ▶sub range_nul_lower {shift->_row->[7]};
Subroutine range_nul_lower: not called CC=1 SCAR=6.9
Pod documented
219 0 ▶sub range_nul_upper {shift->_row->[8]};
Subroutine range_nul_upper: not called CC=1 SCAR=6.9
Pod documented
220 107 ▶sub band_note2 {defined(shift->_row->[5]) ? 0 : 1};
Subroutine band_note2: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined +(shift())->_row->[5] ? : 105 2 107
221  
222 =head2 fdl
223  
224 Calculates and returns the downlink carrier frequency in MHz.
225  
226 my $frequency_downlink_mhz = $rf->fdl;
227  
228 The relation between EARFCN and the carrier frequency in MHz for the downlink is given by the following equation, where FDL_low and NOffs_DL are given in Table 5.7.3-1 and NDL is the
229 downlink EARFCN.
230  
231 FDL = FDL_low + 0.1(NDL - NOffs_DL)
232  
233 =cut
234  
235 203 ▶sub fdl {
Subroutine fdl: called CC=3 SCAR=11.7
Pod documented
236 203 my $self = shift;
237 203 my $channel_type = $self->channel_type;
238 203 ▶ return $channel_type eq 'ul' ? $self->ful + $self->fs
Branch: 2 branches
BranchTrueFalseTotal
$channel_type eq 'ul' ? : 0 203 203
$channel_type eq 'dl' ? : 203 0 203
239 : $channel_type eq 'dl' ? $self->fdl_low + 0.1 * ($self->channel - $self->noffs_dl)
240 : die('Error: unexpected channel type');
241 }
242  
243 =head2 ful
244  
245 Calculates and returns the uplink carrier frequency in MHz.
246  
247 my $frequency_uplink_mhz = $rf->ful;
248  
249 The relation between EARFCN and the carrier frequency in MHz for the uplink is given by the following equation where FUL_low and NOffs_UL are given in Table 5.7.3-1 and NUL is the uplink EARFCN.
250  
251 FUL = FUL_low + 0.1(NUL - NOffs_UL)
252  
253 Issue: Does not support Narrow Band IoT options NB1 or NB2.
254  
255 =cut
256  
257 102 ▶sub ful {
Subroutine ful: called CC=4 SCAR=13.9
Pod documented
258 102 my $self = shift;
259 102 my $channel_type = $self->channel_type;
260 102 ▶ return $self->band_note2 ? dualvar(0, 'n/a')
Branch: 3 branches
BranchTrueFalseTotal
$self->band_note2 ? : 1 101 102
$channel_type eq 'dl' ? : 1 100 101
$channel_type eq 'ul' ? : 100 0 100
261 : $channel_type eq 'dl' ? $self->fdl - $self->fs
262 : $channel_type eq 'ul' ? $self->ful_low + 0.1 * ($self->channel - $self->noffs_ul)
263 : die('Error: unexpected channel type');
264 }
265  
266 #Options for band 24 and 70
267 # $RF::LTE::EARFCN::FS_TABLE{24} = -120.5;
268 # $RF::LTE::EARFCN::FS_TABLE{70} = 295;
269  
270 4 our %FS_TABLE = qw{
271 1 190
272 2 80
273 3 95
274 4 400
275 5 45
276 6 45
277 7 120
278 8 45
279 9 95
280 10 400
281 11 48
282 12 30
283 13 -31
284 14 -30
285 17 30
286 18 45
287 19 45
288 20 -41
289 21 48
290 22 100
291 23 180
292 24 -101.5
293 25 80
294 26 45
295 27 45
296 28 55
297 30 45
298 31 10
299 65 190
300 66 400
301 68 55
302 70 300
303 71 -46
304 72 10
305 73 10
306 74 48
307 85 30
308 87 10
309 88 10
310 103 -30
311 };
312  
313 =head2 fs
314  
315 Returns the TX-RX frequency separation in MHz from Table 5.7.4-1 based on the band of the channel.
316  
317 my $frequency_separation_mhz = $rf->fs;
318  
319 The default E-UTRA TX channel (carrier center frequency) to RX channel (carrier center frequency) separation is
320 specified in Table 5.7.4-1 for the TX and RX channel bandwidths defined in Table 5.6.1-1
321  
322 =cut
323  
324 5 ▶sub fs {
Subroutine fs: called CC=4 SCAR=13.9
Pod documented
325 5 my $self = shift;
326 5 ▶ my $band = $self->band or die('Error: band required');
Branch: 1 branch
BranchTrueFalseTotal
my $band = $self->band or die "Error: band required" 5 0 5
327 my $fs = $self->band_note2 ? dualvar(0, 'n/a')
328 5 ▶ : $FS_TABLE{$band}
Branch: 2 branches
BranchTrueFalseTotal
my $fs = $self->band_note2 ? &dualvar(0, "n/a") : $RF::LTE::EARFCN::FS_TABLE{$band} or die qq[Error: frequency separation not found in %FS_TABLE for band "$band"] 4 1 5
$self->band_note2 ? : 1 4 5
329 or die(qq{Error: frequency separation not found in %FS_TABLE for band "$band"});
330 4 return $fs
331 }
332  
333 =head1 SEE ALSO
334  
335 L<https://www.etsi.org/deliver/etsi_ts/136100_136199/136101/17.06.00_60/ts_136101v170600p.pdf>
336 L<https://github.com/qvil/lte-earfcn-calculator>
337  
338 =head1 AUTHOR
339  
340 Michael R. Davis
341  
342 =head1 COPYRIGHT AND LICENSE
343  
344 Copyright (C) 2026 by Michael R. Davis
345  
346 License: MIT
347  
348 =cut
349  
350 4 1;
351  
↑ Summary