OCDMA: a MAC Protocol for Industrial Intra-machine TeraHertz Network

This paper considers an industrial machine, where wireless sensor nodes (denoted as tags or nodes) support control applications. This scenario poses very challenging communication requirements: hundreds of tags per cubic meter can provide an overall offered throughput of tens of Gbit/s; at the same time, control applications require a latency of less than 0.1 ms. To fulfill them, this work proposes an Orthogonal Chirp Division Multiple Access (OCDMA) scheme to be used in the TeraHertz (THz) frequency band. With THz communications, even at short distances, propagation delays can be of the same order of magnitude as the packet transmission time. This requires proper consideration of such delays in the protocol design and performance evaluation. This paper mathematically derives network throughput and latency of the proposed protocol, comparing it to benchmarks; two scenarios are considered, where tags are in fixed positions or move. Results show that OCDMA outperforms the two benchmark protocols, Aloha and Polling, for static and crowded networks, and the performance is compatible with the communication requirements of industrial control applications.


Introduction
Wireless technologies are used more and more often to improve the efficiency of industrial machines; predictive maintenance and control applications rely on data extracted in real time from sensors deployed in locations often hard to reach with cables [1,2]. Wireless solutions offer a greater degree of flexibility.

3
Journal of Infrared, Millimeter, and Terahertz Waves (2022) 43:400-425 We propose a novel Medium Access Control (MAC) protocol for intramachine wireless sensor networks: OCDMA (Orthogonal Chirp Division Multiple Access), specifically conceived for use at THz frequencies.
We consider a scenario where wireless devices with sensors (denoted as tags or nodes hereafter) are deployed over an industrial machine, like a robot in a manufacturing plant or a large conveyor belt; tags are connected to a central unit (the Programmable Logic Controller, PLC) through Gateways (GW), responsible for data collection.
In many cases, machines are split into sections that are physically separated by metal shields; from the radio propagation viewpoint, they can be considered isolated. We focus here on one single section, whose typical volume is in the order of few cubic meters. One GW is responsible for collecting data from a huge number of tags distributed within its section; all GWs are connected to the PLC via a wired bus. While tags need to be small, cable-free and cheap, GWs can be more complex and are connected to the electrical grid.
We consider both the cases where tags are on fixed and moving components: in the former, they are in known position; in the latter, they move within a limited range, as it happens when tags are deployed on sheaves, pistons or similar mechanical parts.
From the communication network viewpoint, this scenario is very challenging [3,4]. Each tag, especially for applications of predictive maintenance, can generate data rates larger than 1 Mbit/s; for instance, anomalous vibrations can be detected through samples of acceleration taken at minimum frequencies of 10 kHz. Moreover, tag density is expected to skyrocket in the next years [5], thus leading to values of network throughput that can be as large as tens of Gbit/s. Additionally, control loops set very stringent requirements on communication latency (in the order of 0.1 ms [6]); finally, reliability and tag miniaturization are fundamental. These requirements cannot be fulfilled by current wireless technologies [7][8][9][10]; they would be more easily met by using higher frequencies, where larger bandwidths are available. It is envisioned that 6G networks will possibly use the frequency band from 0.1 to 10 THz. It offers bandwidths of several GHz [11,12], which permit ultrahigh data rates, very low latency, while tag miniaturization will benefit from the small wavelengths.
In this paper, our proposed protocol is compared to two benchmarks, accounting for advantages and drawbacks of the THz band. We mathematically derive the success probability, network throughput and latency as a function of several system parameters.
The paper is organized as follows. The next section underlines a number of aspects differentiating this paper from previous works in the literature. Section 3 introduces the system model. Then, in Section 4 we present our proposed OCDMA scheme, and the benchmarks. Section 5 describes the performance metrics, while results are discussed in Section 6 and conclusions are drawn in Section 7.

3 2 Contribution Beyond the State of the Art
Let us compare the contribution of this paper to the available scientific literature, from the viewpoint of the scenario, the physical (PHY) and MAC layers.

Scenario
Most applications envisaged for THz communications belong to two classes: (i) at the nano-scale, due to the use of non-directional antennas at both link ends, transmission ranges are in the order of few centimeters; (ii) at the macro-scale, where highly directive antennas are used both at the transmitter and receiver side, making it possible to reach much larger distances [12].
We assume tags have only one radiating element for the sake of device simplicity, while the GWs can have many of them, generating highly directive beams. This asymmetry, while introducing issues to be solved at protocol level, determines transmission ranges that may reach few meters, which are compatible with the scenario investigated. Therefore, with respect to the two usual categories of applications for THz communications mentioned above, our case is intermediate.

PHY
Many works propose physical layer solutions to cope with the frequency selective nature of the THz channel. Traditional multi-carrier schemes, like Orthogonal Frequency Division Multiplexing, do not seem to be suitable for THz frequencies, due to the disruptive effect of phase noise [13][14][15][16]. In 2016, Xing Ouyang and Jian Zhao have set the basis for Orthogonal Chirp Division Multiplexing (OCDM), where chirps of common duration sweep over a shared band thanks to their mutual orthogonality [17]. The benefits of OCDM have been exploited for different application domains: underwater [18,19], radar [20,21], video-broadcasting [22], power lines [23,24]. Other contributions have addressed the complexity of the receiver [25,26] or applied Multiple-Input Multiple-Output to OCDM [27][28][29]. In 2017, an extension of [17] demonstrated that OCDM is suitable for power-limited applications [30], like the one we are considering in this paper. OCDM also outperforms LoRa [31], a successful system using orthogonal chirps.
In this paper, we assume OCDM waveforms are used, as described in [17], in combination with Frequency Division Multiplexing (FDM); a hybrid OCDM-FDM system is then envisaged at the PHY layer.

MAC
With THz frequencies, even at short distances propagation delays can be larger or in the same order of magnitude as packet lengths. For instance, a 100byte packet can be transmitted in 0.8 ns with a bit rate of 1 Tbit/s, while the propagation delay at a distance of 1 m is 3.3 ns. This has a deep impact on protocol efficiency. Nevertheless, few papers have addressed protocol aspects of THz communications so far in the literature. Our proposed solution is based on the transmission of chirps belonging to an alphabet of orthogonal waveforms. Orthogonality allows the introduction of a spread spectrum transmission technique where multiple tags transmit simultaneously using the same band. This reduces the impact of the propagation delays on protocol efficiency, since packets have longer duration.
Current works in literature propose either centralized or distributed MAC solutions for THz communications [12,32].
The former approach is largely investigated for nano-scale networks (see, e.g., [33]), where the use of Time Division Multiple Access (TDMA) is widely explored [34,35]. An angular-division MAC solution for ad hoc networks is presented in [36]; two separate antenna systems are used for different protocol phases. This generates the well-known asymmetry-in-gain problem, which results in deafness and collisions. The work in [37] proposes to use directional antennas to divide the space in angular sectors, where a 3-ways handshake MAC protocol in each sector allows to achieve synchronization between the central entity and devices before data transmission. Similar approaches are followed in other works dealing with millimeter wave (MMW) communications (see, e.g., [38,39]). A centralized protocol is also proposed in [40], where polling is used; however, the impact of propagation delays on the MAC performance is not considered in this paper.
Other works dealing with CSMA-based protocols assume nodes are equipped with multiple radios: a THz transceiver for data transmission and one working at lower frequencies for neighbor discovery. This approach results in very large delays for the second phase. As an example, both [41,42] use a 2.4 GHz radio to estimate neighbors position, while the THz radio is used with directional antennas to transfer data in the dominant multi-path direction. Additionally, the work in [43] enriches the dual-band exploitation for distributed MAC protocols at THz frequencies with Multiple-Input Multiple-Output (MIMO) and powercontrol techniques. Additional improvements to CSMA-based protocols, considering directional antennas but keeping the deafness problem under control, is proposed in [38,[44][45][46] for MMW communications. However, the authors of above papers do not account for propagation delays, even though it is well known that they dramatically affect CSMA [47].
In this work, we overcome the drawbacks of the above mentioned papers, by assuming a unique transceiver, with a single antenna system. Moreover, to avoid the inefficiencies of CSMA we choose a centralized approach; we propose OCDMA, a MAC solution that exploit OCDM-FDM waveforms at PHY layer. It is compared to simple centralized and distributed MAC protocols, previously analyzed in [48]. Our mathematical description accounts, differently from many of the papers above mentioned, for the impact of propagation delays. More importantly, our proposed protocol is specifically designed to reduce such impact.

Reference Scenario
As mentioned already, we focus on one single machine section, whose typical volume is in the order of few cubic meters. One GW is responsible for collecting data from the N tags distributed within the section, whose geometry can be very different depending on the type of machine. For the sake of simplicity, our reference scenario is modeled via a 3D sphere of radius R and volume V = 4 3 R 3 , having the GW in its center; tags are randomly and uniformly deployed inside the sphere.

System Model
We assume the GW is equipped with a number N a of radiating elements, while tags have one omni-directional antenna. Therefore, the GW can generate an antenna beam with solid angle = 2 arcsin(2∕N a ) radiants. The resulting maximum antenna gain, G, can be assessed as [49]: For the sake of simplicity we assume the radiation pattern is ideal, with gain G inside the angle , and zero outside.
The total number of antenna beams in the sphere is N b = 2 1−cos 2 ; in the j-th beam of volume V = 2 3 R 3 (1 − cos( ∕2)) , a number of n j tags are deployed. Owing to the statistical distribution of tags in the sphere, n j is binomially distributed with parameters N and p = V V = 1 2 (1 − cos( ∕2)) . Therefore, the probability mass function (p.m.f.) of the number of tags in the j-th beam is given by: N−n j , and its average value in the following will be denoted as n j = The GW will sweep the beams in order to communicate with all tags, according to a time division approach. Not necessarily all N b beams will be swept. Let us denote as n b the number of beams to be swept.
We consider the following two scenarios: (i) Static: tags are in fixed positions, and the GW knows a priori their locations; so, it will only sweep the subset of n b = n b s ≤ N b beams illuminating at least one tag; (ii) Quasi-Static: tags are on moving components and can perform small movements; and the GW does not know exactly where they are. Therefore it has to sweep all N b beams: We assume a tag may move within a set of K adjacent beams.

Channel Model
Precise characterization of the radio channel for such an environment, with many metallic components, is a complex task; it is out of the scope of this paper, as we focus on the MAC layer. For the sake of simplicity, we consider the THz channel model proposed in [50,51]. The path-loss, L tot , is given by: is the spreading loss, d is the total path length, f the frequency of the wave, and c is the speed of light. The term e k(f )d represents the molecular absorption attenuation, and k(f) is the medium absorption coefficient, given by , where k i,g stands for the individual absorption coefficient for the isotopologue i of gas g [50]. Indeed, each gas has different resonating isotopologue within the THz band. The values of k i,g have been computed using the HITRAN (HIgh resolution TRANsmission molecular absorption) database [52], considering a humidity level of 10%. where we are assuming the surface is smooth, 1 i is the angle of the incidence wave, and n r is the refractive index.
As usual, the propagation delay, p , can be computed as a function of the link distance d: p = d∕c . We denote as p the propagation delay normalized to the data packet duration. The larger is p , the more the protocol efficiency is impacted by propagation delays.

Signal-to-Noise Ratio
The transmission system we envisage includes a FDM component, both with OCDMA and the two benchmark protocols described later. In particular, the overall bandwidth B used by the system, is split into M sub-bands of width f , where the channel is assumed to be flat (i.e., the molecular absorption parameter k(f) is constant) [50]. Each sub-band is centered around the carrier frequency ., M} , being f c the central frequency of the overall band. A (data or control) packet is fragmented over the M sub-bands after serial-to-parallel conversion. The system bit rate, R b , will be given by The Signal-to-Noise Ratio (SNR) for the i-th tag at distance d i from the GW on any of the sub-bands, (d i ) , is given by: The expression of the received signal power P 0 (d i ) can be written as: In particular, S 0 is the single-sided power spectral density of the transmitted signal and it is assumed to be flat in the bandwidth f (a reasonable assumption for chirps [31]), i.e., S 0 = P t ∕ f , where P t is the transmit power; G t and G r are the transmit and receive antenna gains and t and r are the transmit and receive antenna efficiencies, respectively. In our scenario, tags have unitary antenna gain, while for the GW Eq.
The noise power P n (d i ) is frequency dependent. Indeed, molecular absorption does not only affect the properties of the channel in terms of attenuation; it also introduces noise [50]. In particular, the total noise temperature of the system, T noise , is given by T noise = T sys + T mol where T sys is the system electronic noise temperature, which for graphene-based electronic devices can be considered negligible (i.e., the noise figure is unitary), due to the very low noise factors in nanomaterials [53]; T mol is the equivalent noise temperature due to molecular absorption, given by T 0 1 − e −k(f )d , where T 0 = 290 K is the reference temperature. Therefore, the noise power on any of the sub-bands is: where k B = 1.38 ⋅ 10 −23 J/K is the Boltzmann's constant. This results in: Since we assume that, over each sub-band, k(f) is constant, the SNR can be finally reformulated as: Journal of Infrared, Millimeter, and Terahertz Waves (2022) 43:400-425

Waveforms
As already mentioned, at the PHY layer we refer to OCDM as it was introduced in [17]: chirps assigned to different concurrent transmitters are designed to be orthogonal; thus (on each sub-band), they can be transmitted at the same time over the same bandwidth, as in spread spectrum communications. We denote as T the chirp duration.
If C is the number of orthogonal chirps, for a given and generic bandwidth B c , the i-th chirp, with i = 0, 1, .., C − 1 , has the following expression: shows that the orthogonality between the chirps is achieved when any pair of consecutive chirps is time shifted by T C and when all of them have a chirp rate of − C T 2 ; the minus sign indicates that the frequency sweep within T happens in a decreasing fashion. Figure 1 shows the time-frequency representation of the frequency deviation (with respect to the carrier) performed by an analogue OCDM signal. It is worth mentioning that C chirps are not transmitted in 2 ⋅ B c , as one could argue by looking at Fig. 1, because the discrete OCDM signal may be wrapped in the frequency band of width B c with a proper exploitation of the aliasing coming from the sampling theorem. We assume the latter case hereafter.
The fundamental property of OCDM signals is that the number of orthogonal chirps is Assuming chirps are modulated through a binary phase shift (zero or ), the bit rate on each sub-band will be equal to: In this paper the bandwidth B c will be set equal to f , therefore B = B c M = f M and With OCDMA, we will properly set C in order to eliminate interference when multiple nodes compete for channel access; they will transmit simultaneously using orthogonal chirps. The larger is the value of C, the longer are the chirps and the packet duration; therefore, p is smaller and the protocol efficiency is higher. In our scenario, downlink packets are transmitted in interference-free conditions by one individual node (the GW); so, C is set to one. As a result, the downlink bit rate is equal to B, and the packet duration will be inversely proportional to B. In the uplink, tags have to share access to the medium; at least C orthogonal chirps have to be used if an equal number of tags are permitted to transmit simultaneously. The uplink bit rate is B C and the packet duration will be proportional to C B . In the case of benchmark protocols, the spread spectrum approach implemented in OCDMA is not used and therefore C = 1 in all transmissions.

Time Division
Time is organized into subsequent frames of duration T f rame . During each of them, all N tags try to transmit their data once. Frames are divided into sub-frames, each dedicated to the exploration of the volume illuminated by one beam. Indeed, during each frame the GW sweeps the n b beams, remaining in the j-th direction (with j = {1, .., n b } ) for a time T beam j (sub-frame duration). Accounting for the time needed to switch from one beam to the next one, denoted as s , we have During the j-th sub-frame, first a beacon packet is sent by the GW in downlink, including information about protocol parameters, then an uplink data transmission phase takes place, of duration T tx j . We can write: Journal of Infrared, Millimeter, and Terahertz Waves (2022) 43:400-425 is the transmission time of the beacon packet, including L bea bits.
We fix a guard time between the end of the beacon transmission and the beginning of T tx j , equal to the maximum propagation delay p (R) = R∕c.

OCDMA Protocol
Let us distinguish between the Static and Quasi-Static scenario. In the former case, the GW assignes a different orthogonal chirp to each tag (whose number n j is known); so, C = n j . In the latter, since the GW does not know how many tags are really present in each beam, the worst case is considered, that is C is set equal to the maximum number of tags in the beam, given by is the number of tags in beam j u if tags were still. N j is binomially distributed with parameters N and K p , that is B N j (N, K p) , while its average value in the following will be denoted as In this way, all tags can communicate using the same time-frequency resource toward the GW, which will receive the orthogonal chirps and will separate them using parallel correlators.
As can be seen in Fig. 2, the data transmission phase in OCDMA starts with a Clear To Send (CTS) packet sent in broadcast by the GW and received by all tags in the beam; they will reply sending their own DATA packet (overlapped in time), after which a cumulative acknowledgment (ACK) is sent by the GW, to notify the successful transmission or not.
Note that it is essential that the GW receives synchronized data from tags, to exploit orthogonality for the sake of interference cancellation. We will not take the consequence of lack of synchronization into account; however, we include a synchronization phase in the protocol, to assess its impact on network throughput.

Static Scenario
To ensure synchronization of all data packets at the GW, tags have to start transmitting at proper instants, depending on their distance from the GW (a mechanism known in radio networks as timing advance). To achieve this, after the reception of the CTS each tag i will wait for an interval of time, i , before starting transmitting its data. i is set by each node in order to have the same amount of time between the end of the transmission of the CTS from the GW and the beginning of the reception of the data packets at the GW again. This time duration will be denoted as D (see Fig. 2), and will be set equal to: D = 2 ⋅ p (R) , to account for the worst case scenario (a tag at maximum distance R from the GW). Therefore, each tag i will set its waiting time according to: i = D − 2 ⋅ p (d i ) . Indeed, in the case of Static scenario, where the GW knows the exact position of tags, we can assume the value of i , for tag i, is determined by the GW and included in the payload of the CTS. As a result, the uplink data transmission phase for beam j in the Static scenario, is given by: (14) T tx j =T tx (n j ) = T cts + D + T data (n j ) + T ack + p (R) =T cts + T data (n j ) + T ack + 3 p (R) where T cts , T ack and T data represent the duration of CTS, ACK and DATA packets, respectively. They can be computed accounting for the number of bits they include, L cts , L ack and L data respectively, and the bit rate that differs for downlink (CTS and ACK) and uplink (DATA) packets, as explained before. Therefore, T data will depend on the number of tags in beam j, according to: T data (n j ) = L data ⋅ n j ∕B , having set C = n j .

Quasi-Static Scenario
In this case, the GW does not know exact tag positions, needed to compute i for each tag; therefore, a synchronization phase is required, before the data transmission phase described above can start. This additional time interval, whose duration will be denoted as T sync j , will unfortunately affect OCDMA performance. The synchronization phase will be based on two-way handshake with all tags: the GW will transmit a very short packet in broadcast (Request For Synchronization, RFS), made of L rfs bits, and tags will reply with an ACK message one after the other avoiding collisions, through a proper schedule. Each tag is assigned a slot of duration 2 ⋅ p (R) + T ack . The slot size is such that, regardless of the distance from the GW, the ACK will be received in the assigned slot without collisions. Each tag replies after reception of the RFS, with a suitable and personalized delay; the i-th tag ( i = 1 , 2, … ) will wait (2 ⋅ p (R) + T ack ) ⋅ (i − 1) seconds before transmitting. The only information needed for them is when it is their turn to reply, and this is included in the RFS packet. The synchronization phase is exemplified in Fig. 3; its duration is equal to At the end of such phase, the GW will be able to compute the propagation delay for each tag from the measured round-trip time, and determine i . Therefore, in the case of Quasi-Static scenario, we have: where T rfs is the time spent to transmit the RFS packet, given by L rfs ∕R b . In this case, T data now depends on the total number of potential tags per beam. Therefore, we have: , having set C = N j .

First Benchmark: Polling
As a first benchmark, we consider a centralized protocol, based on polling. In this case, after the beacon transmission the time axis is split into slots. The GW interrogates one by one all tags in V and the data exchange takes place in the dedicated slot.
Within each slot we have (i) CTS packet from the GW to the tag, to notify it is ready to receive data; (ii) DATA transmission from the tag to the GW; and (iii) ACK from the GW to the tag. As soon as a tag has been polled, it will go back to sleep until the subsequent frame will start. Therefore, the data transmission phase of the j-th sub-frame is composed of different slots, of duration: where T cts , T data and T ack are the transmission times of CTS, DATA and ACK packets, respectively, computed as for OCDMA. p (d i ) is the propagation delay for the polled tag i; thus, every slot has a different duration, depending on its distance from the GW.
In the Static scenario, we have: In the Quasi-Static case,

Second Benchmark: Randomized Aloha
We consider as a second benchmark a simple contention-based protocol, inspired to Aloha. The data transmission phase is composed of an interval of time, of duration T CW j , during which tags in the volume V can transmit their data to the GW. Each tag at the beginning of the data transmission phase generates a random waiting time, uniformly distributed between zero and T CW j , after which it transmits. Being the packet success probability strongly affected by the duration T CW j and the number of tags competing for the channel, we study the performance of this protocol by varying T CW j ; we set it equal to T CW for all j. At the end of transmission each tag will wait for an ACK from the GW. In this case, for both the Static and Quasi-Static scenarios we have: Note that in this case the frame duration does not depend on the position of tags.

Performance Metrics
We will now derive mathematically the performance of OCDMA and the benchmarks in terms of network throughput and latency. This requires the computation of the packet success probability.

Bit Error Rate
We first need an expression for the Bit Error Rate, BER; for both OCDMA and the two benchmark protocols, since we modulate the chirps as binary antipodal waveforms, over the kth sub-band we have: where erfc is the complementary error function.

Packet Success Probability
The packet success probability, p s , for tag i at distance d i from the GW and belonging to beam j, is given by: The probability p phy (d i ) accounts for PHY layer aspects; to compute it, we average over LOS and NLOS conditions, having probability p LOS and 1 − p LOS , respectively. In the two cases we set L ref as mentioned in Section 3.3.
Assuming independent events, p phy (d i ) is computed as the product of the success probabilities at PHY layer of each independent packet transmitted to realize communication between tag i and the GW. Let us define p p (d, L) as the probability that a generic packet of L bits at distance d is correctly decoded at the receiver side (whether tag or GW). In the case of OCDMA, packet success implies successful transmissions of the beacon, the CTS and the data packets: The same holds for the first benchmark protocol, since the sequence of packets to be transmitted is the same. Finally, in the case of the second benchmark, packet success implies successful transmissions of the beacon and the data packet: Without loss of generality, we assume absence of Forward Error Correction (FEC); the packet is correctly received if all bits are correct. Indeed, we assume that each transmission is characterized by a time-flat channel [54]; thereby, the use of FEC techniques is not favorable because adjacent bits experience correlated errors. Therefore: The probability p mac (n j ) depends on the MAC protocol, and it is equal to one for contention-free protocols like OCDMA and Polling, while it depends on the number of tags in beam j, n j , for Aloha. In particular, in the latter case p mac (n j ) represents the probability that there are no collisions in the beam j, when n j tags are competing for the channel. It can be computed as the probability that a packet of duration T data generated in a random instant within T CW does not collide (partially or completely) with a packet or an acknowledgement generated by any other tag within the same beam; therefore: where for the propagation delay we consider the worst case.
As long as the SNR at distance d i for each frequency f k is computed, the set of equations above determine the packet success probability. It depends on many parameters, including the number of antenna beams swept by the GW, through n j .

Network Throughput Definition
Let us denote as = {d 1 , .., d N } the vector of tag distances, and as = {n 1 , .., n n b } the vector of the number of tags deployed in each beam; then, network throughput, S, can be defined as: where L pay is the number of bits of data payload, assuming that all tags are transmitting the same number of bits in each frame. Note that in case no tags are present in a beam, no throughput is gathered (i.e., p s (d i , n j ) is set equal to zero when n j = 0 ). In the definition above, T f rame is computed as shown in expression (13), where T tx j depends on the scenario and protocol considered; in general terms, T f rame depends on the number of beams swept, the number of tags in each beam, and their positions.
Therefore, we are interested in the average network throughput, S , averaged among all tags, given by: is the average value of the function g(x), w.r.t. the statistics of the random variable x. In particular, we will have: where f (d i ) is the probability density function (pdf) of tag distances, given by Finally, F(d 1 , .., d N ) will be the joint pdf of tag distances, given by (thanks to the independence of tag positions): As will be shown in the rest of this section, the above defined average network throughput is very complex to be numerically evaluated; in order to reduce the computational time, we will mainly focus on an approximated formula, Ŝ , obtained as the ratio between the average values (averaged over the statistics of n b , , ) of the numerator and denominator of Eq. (27). An example of comparison between approximated and exact formulas is reported in Section 6. We provide below the formulation of S and Ŝ for OCDMA and for the two benchmark protocols.

OCDMA Protocol
In the Static scenario we can account for the fact that we sweep only beams with at least one tag, that is n b = n b s , where n b s is binomially distributed, B n b S (N b , ) , with being the probability that a beam has at least one tag given by = ∑ N n j =1 B n j (N, p) , and having average value, n b s = . It is worth noting that in this case, T f rame does not depend on tag distances, and the success probability p s does not depend on the number of tags per beam. Therefore, Eq. (30) holds, where p phy is computed as in Eq. (28) by replacing p phy (d i ) given by Eq. (22) to g(d i ).
We then approximate Eq. (30) as (31): where T tx is given by: and T tx (n j ) is computed as in Eq. (14). Note that in the approximated expression of throughput we have introduced N as it is equal to n b s ⋅ n j . In the case of Quasi-Static scenario we have to sweep all beams, that is n b = N b and it is deterministic; in addition T f rame depends on } . Following the same approach of the Static case, it is possible to write the exact expression of the throughput as follows: The approximated formula becomes: where we set N b N j = N b K n j = N K and T tx is given by: where T tx (N j ) is given by Eq. (15).

First Benchmark: Polling
Following the same approach, in the Static scenario the exact throughput expression is shown in Eq. (36), while the corresponding approximated formula is given by Eq.
Journal of Infrared, Millimeter, and Terahertz Waves (2022) 43:400-425 The second addendum at the denominator of Eq. (37) is obtained as follows: where wet set N = n b s n j ∕ and T slot is given by Eq. (28) by replacing g(d i ) to T slot (d i ) given by Eq. (16).
In the case of Quasi-Static scenario, being n b = N b , the following exact expression of the throughput comes: and the approximated formula is given by: where it again holds N b N j = N K.

Second Benchmark: Randomized Aloha
In this case we have to consider the MAC level packet success probability, where the number of contending tags varies in the two scenarios. For the sake of conciseness, we just report here the approximated formula, obtained by following the same approach presented for the Polling case.
In the Static scenario we have: where p mac is given by: In the Quasi-Static scenario we have: where p mac has the following expression: In Eq. (44) we average p mac over the K beams of a cluster and we denote as n c u the number of tags competing for the channel in beam u of the cluster; this variable is binomially distributed with parameter K p and assumes a maximum value that depends on the number of tags present in the other beams of the same cluster (the number of tags in the beams of a cluster is not uncorrelated). Finally, the normalization factor is given by ...

Latency
Latency is defined in this context as the time needed by the GW to gather data from all the tags in the network; therefore, it coincides with the frame duration, T f rame , derived in Section 4.

Results
In this section, we present and discuss the numerical evaluations for the closed-form expressions of network throughput and latency. System parameters, if not otherwise specified, are set as in Table 1. It is worth mentioning that all parameters, such as the transmit power or the bandwidth, have been set in order to obtain (d i = R) ≥ min , where min is the minimum SNR level to be guaranteed at the receiver-end. We start the analysis by discussing the success probability, p s , as a function of N a (see Table 2). As expected, Aloha is the worst protocol, due to collisions. This is particularly true when N a is small, because the volumes illuminated by beams are larger and more tags compete for access. However, especially for low values of N a , the performance is mainly affected by noise, owing to a small antenna gain at the GW. The table allows to derive the minimum number of antennas, N a min , to be installed at the GW, given the reliability requirement. For example, if the industrial application requires p s ≥ 0.98 , N a min ≃ 10 for OCDMA and Polling is sufficient, while many more antennas should be deployed in the case of the Aloha protocol.
We now analyze the behavior of throughput by changing different system parameters. Approximated formulas are used, to reduce computational time (precise formulas require weeks to run, in case N > 50 ). To demonstrate the negligible impact of the approximation, Table 3 reports some comparisons: a very good match has been observed, as the error is confined in all cases to less than 5 percent.  Figures 4 and 5 report Ŝ and latency as a function of N, when setting N a = 10 , respectively. As can be noted, the network throughput of OCDMA outperforms the benchmark solutions in all cases for the Static scenario; the advantage increases with the tag density. For N larger than 200, OCDMA provides throughput higher by at least 25 percent with respect to Polling; such increment is significantly larger than the approximation margin introduced by our formulas.
In general, for the Static scenario, it could be shown that OCDMA outperforms Polling when the average number of tags per beam, n j , is larger than one. This is because, if only one tag is present in a beam, the transmission phase duration for the two protocols will be almost the same. In contrast, for larger number of tags per beam, T f rame for Polling will be larger, due to the need to poll multiple tags, while in OCDMA it will remain limited since all tags will transmit at the same time. Since , it is larger than one as long as N > N 2 a 2 for the Static scenario; since Figs. 4 and 5 refer to N a = 10 , this applies as long as N is larger than 50, as confirmed by the curves.
However, in the Quasi-Static case Polling is the best solution, due to the need of implementing the synchronization phase in OCDMA not present in Polling. As expected, Aloha is the worst protocol, due to its contention-based nature.
For what concerns the latency, as expected, it slightly increases with N. We can also observe that Aloha is the best protocol, thanks to the absence of control packets to be sent, together with the fact that T CW in this case can be properly optimized (at the cost of collisions). As for the comparison between OCDMA and Polling, we can observe the same trend commented for the network throughput: for Static and dense networks OCDMA works better than Polling. Finally, it is worth noting that in all cases latency is maintained below 10 s , that is suitable for many industrial control applications.  We conclude by reporting Ŝ as a function of N a in Fig. 6, for N = 100 and considering the Static scenario. In the case of Aloha Ŝ increases with N a , thanks to the improvement of both, PHY and MAC losses. Indeed, by increasing N a , the antenna gain gets larger and the beam volume decreases, making the average number of tags per beam lower (i.e., less collisions in Aloha). In contrast, in the case of OCDMA and Polling, Ŝ slightly decreases by getting N a larger, due to the growing of n b S (at the denominator of Ŝ ). An horizontal floor is reached for large values of N a . The figure also shows the impact of the propagation delay p : the throughput is also reported for an ideal case where it is negligible (i.e., p = 0 ). A notable worsening can be observed when considering the true values of p . This proves our claim that MAC protocols at THz communications need to be investigated accounting for propagation delays.

Conclusions
This paper offers three degrees of novelty: (i) the analysis of the intra-machine scenario using THz frequencies, which is an intermediate case between existing nanoscale and macro-scale applications of THz communications (see Section 2); (ii) the proposal of OCDMA, a MAC protocol specifically designed for this relevant Our proposed OCDMA solution is compared to Polling and Aloha based schemes, taken as benchmarks. We mathematically derived expressions for the packet success probability, the network throughput, and the latency.
As discussed in the last section, OCDMA provides advantages as long as the number of nodes in the machine is large and when the GW knows tags position, so that synchronization among them can be achieved without additional protocol phases. As a rule of thumb, the advantage of OCDMA in the Static case is evident when the number of nodes under the control of the GW is larger than N 2 a ∕2.
Funding Open access funding provided by Alma Mater Studiorum -Università di Bologna within the CRUI-CARE Agreement.

Conflict of Interest
The authors declare no competing interests.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http:// creat iveco mmons. org/ licen ses/ by/4. 0/.