Concept of energy threshold
Does the &quot;Energy Threshold&quot; carry information about the end of the noise and the beginning of the packet due to the calculated arithmetic mean?

There's no such thing as &quot;end of noise&quot;: Nothing says that noise can't take values that are as large (or larger) than your signal's power; in &quot;benign&quot; noise, these values are just rare. (And that especially applies for large $L$: Exactly when your noise estimator becomes bearable, i.e. when $L$ is large and thus $N/L-1$ is small, you get potential for larger sums.)

Or am I not fully understanding something here?

Yep, you need to actually consider noise a random variable, and consider its power a random variable, too.
You need to define a noise model. For example, the often-used assumption of Gaussian noise leads to a distribution with fat tails – which means that, yes, noise will eventually be larger than any signal power, if you just look often enough.
The threshold was chosen for some reason that's impossible for us to know – maybe putting an upper bound to the probability of detecting noise as packet, or an upper bound to the probability of dismissing signal as noise (notice that in general, you don't know your signal's power, either, and it's a random variable, too).
Maybe someone was just lazy and put any value there. My crystal ball is cloudy – you need to ask whoever designed this. (Or your advisor. Asking your advisor/lab supervisor/professor at this point might be wise. You're missing the whole &quot;Probability in Communications&quot; chapter from the book I linked to in my answer to your question of yesterday. Maybe re-read that chapter? It's not actually sufficient in mathematical depth to derive the result I foreshadow below, but it's a good start.)


Noise_power is just that. well, the noise power (although I don't know why multiplied by 100, it is possible that a higher order of magnitude allows a more fair detection - I don't know, sadly)

It's very much not the noise power!
So, &quot;noise power&quot; is a property of the stochastic process (that means: random variable with a time index); you're only estimating that. This is is hence a noise power estimate, not the noise power.
To make matters worse: this is a biased estimate (in any reasonable noise model I can think of). It's probably not very close to the actual noise power.
Let's quickly derive that. Let $Z_t$ be your noise at (discrete) time $t$, a random variable. I don't know your noise model, and I don't think you've given us that info, so we'll have to just say that $Z_t$ has cumulative density function (cdf)
$$F_{Z_t}(z) := P(Z_t \le z),$$
which is nice enough to also imply a probability density $f_{Z_t}(z):=\frac{\mathrm d\,}{\mathrm d\,z}F_{Z_t}(z)$. We'll also have to assume that your noise has a zero mean, and finite variance $\sigma_{Z_t}^2$ (finite power!) (which applies especially to e.g. Gaussian noise). Because anything else would blow up this answer (and not because that is a good representation of every real-world noise), we'll also have to assume our noise is $L$-blockwise stationary and independent (which applies especially to white noise).
We will now look at the case where you get only noise in all segments.
Let us call the powers in your $N/L$ segments $S_i, i=0, \ldots, N/L-1$ (note: you've got a typo in your figure, if you start at 0, the number of the last segment is $N/L-1$, not $N/L$):
$$S_i =  \sum_{k=i\cdot L}^{i\cdot (L+1)-1}\frac1L \lvert Z_k \rvert^2$$
Out of curiosity, let's consider the cdf of $\lvert Z_k \rvert^2$:
\begin{align}
F_{\lvert Z_k \rvert^2}(v) &amp;= P\left(\lvert Z_k \rvert^2 \le v\right)\\
&amp;=\begin{cases}
0 &amp; v &lt; 0\\
P\left(\lvert Z_k \rvert \le \sqrt v \right) &amp; v\ge 0
\end{cases}\\
&amp;=\begin{cases}
0 &amp; v &lt; 0\\
P\left(-\sqrt z \le Z_k  \le \sqrt v  \right) &amp; v\ge 0
\end{cases}\\
&amp;=\begin{cases}
0 &amp; v &lt; 0\\
P\left( Z_k  \le \sqrt v  \right) -P\left( Z_k  \le -\sqrt v  \right) &amp; v\ge 0
\end{cases}\\
&amp;=\begin{cases}
0 &amp; v &lt; 0\\
F_{Z_k}\left( \sqrt v  \right) - F_{Z_k}\left( -\sqrt v  \right)  &amp; v\ge 0
\end{cases}
\end{align}
with a mean $E\left(\lvert Z_k \rvert^2\right) &gt; 0$ (a absolute square is always larger than zero, unless the original variable is 0, and I'd guess this is not a case you care about, because it means &quot;noiseless&quot;). With a little more derivation it's possible to show that the expectation of the random variable $\lvert Z_k\rvert^2$ is the variance of the random variable $Z_k$, i.e. the actual noise power $\sigma_Z^2$; the variance of $\lvert Z_k\rvert^2$ is twice that, at least for Gaussian $Z_k$.
Now, the cdf of that $S_i$ is simply:
\begin{align}
F_{S_i}(p) &amp;:= P(S_i \le p)\\
&amp;=P\left(\sum_{k=i\cdot L}^{i\cdot (L+1)-1}\frac 1L \lvert Z_k \rvert^2 \le p \right)\\
S_i &amp;\overset{\text{CLT}}\sim \mathcal N\left(E\left( \lvert Z_{iL} \rvert^2 \right);
\frac 1L E\left(\left[\lvert Z_{iL} \rvert^2 - E\left(\lvert Z_{iL} \rvert^2\right)\right]^2\right) \right)\\
&amp;= \mathcal N\left(\sigma_Z^2; \frac{2\sigma_Z^2}L\right)
\end{align}
assuming that we can apply the central limit theorem (CLT), which says that for sufficiently large $L$, the sum over a random variable (such as $\lvert Z_k \rvert^2$) has a distribution that approaches the Normal distribution $\mathcal N(\mu_S;\sigma_S^2)$. The factor of $1/L$ in $\sigma_S^2$ stem from the linearity of the expectation (and the resultant quadratic influence of constant factors on variance).
Now, this just shows that your $S_i$ are just a bunch of approximately normal variables.
So, let us consider the minimum of these $S_i$,
$$M := \min_{i=1,\ldots, N/L-1} S_i,$$
which itself is a random variable.
Now, the cdf of that is pretty simple:
\begin{align}
F_M(m) &amp;:= P(M\le m)\\
&amp;= P\left(\min_{i=1,\ldots, N/L-1} S_i \le m\right)\\
&amp;= P\left(S_1 \le m \wedge S_2 \le m \wedge \ldots \wedge S_{L/N-1} \le m\right)
\end{align}
Because we defined the noise to be independent, and thus especially between blocks, $P_1$, $P_2$ and so on are independent variables. Thus,
\begin{align}
F_M(m) &amp;= P\left(S_0 \le m \wedge S_1 \le m \wedge S_2 \le m \wedge \ldots \wedge S_{L/N-1} \le m\right)\\
&amp;= P\left(S_0 \le m \right)P\left(S_1 \le m \right) P\left( S_2 \le m \right)  \ldots P\left( S_{L/N-1} \le m\right)\\
&amp;= P\left(S_0 \le m \right)^{N/L}\\
&amp;= \left(F_{S_0}(m)\right)^{N/L}.
\end{align}
We want to know what the expecation of $M$ is, because that's what we expect our noise power estimator estimates as noise power.
For that, we first find the pdf of $M$, and then just insert that into the definition of expectation.
\begin{align}
f_M(m) &amp;= \frac{\mathrm d\,}{\mathrm d\,m} F_M(m)\\
&amp;= \frac NL \left( F_{S_0}(m)\right)^{N/L-1} \frac{\mathrm d\,}{\mathrm d\,m} F_{S_0}(m)\\
&amp;= \frac NL \left( F_{S_0}(m)\right)^{N/L-1} f_{S_0}(m)\\
\end{align}
Normalizing $m$ allows us to use the cdf of the standardnormal distribution:
\begin{align}
f_M(m) 
&amp;= \frac NL \left( F_{S_0}(m)\right)^{N/L-1} f_{S_0}(m)\\
&amp;= \frac NL \left( \Phi\left(\sqrt{\frac{L}{2}}\frac{m-\sigma_Z^2}{\sigma_Z}\right)\right)^{N/L-1} f_{S_0}(m)\\[2em]
E(M) &amp;= \int_{-\infty}^\infty m\cdot f_M(m) \,\mathrm dm \\
&amp;= \int_{-\infty}^\infty m \left(
\frac NL \left( F_{S_0}(m)\right)^{N/L-1} f_{S_0}(m)
\right)\,\mathrm dm
&amp;|\text{ partial integr.}
\end{align}
In the partial integration step we see that we indeed get a component that is the actual $\sigma_Z^2$, i.e. the actual noise power, but we subtract a strictly positive term. This bias means we're *systematically underestimating the noise power with what you call noise_power. This isn't a good estimator for noise power.
(There's a solution to the above integral; if you really want to know more, the $N/L$th power of a $\chi^2$-distributed variable involves a ratio of $\Gamma$ functions. Don't really think that result helps you much, but it proves (aside from the general consideration yielding the same) that you're underestimating noise power.)


But the thing that bothers me the most is the value of (signal_power+noise_power)/2 - as far as I can see, it's a simple arithmetic average of signal power and noise power. Is this how energy threshold is calculated?

No. Not in general, and I doubt it's  a good choice here.
That threshold $\gamma$ needs to be chosen based on how much missed packets you can live with vs how much noise misidentified as packet you can accept. A common choice for a threshold would be one that leads to maximum likelihood estimation of whether there's a packet $D$ or only noise considering received segment power $S_i$.