blib/lib/RF/LTE/EARFCN.pm

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