Energy calculation in frequency domain I was just wondering... The formula I learned to calculate the energy of the signal is expressed in the time domain:

$$E_x^{\text{time}} = \sum_{n=-\infty}^{\infty} |x[n]|^2$$

Then, what does the amount of energy gotten from the magnitude spectrum mean?

$$E_x^{\text{frequency}} = \sum_{f=0}^{fs/2} |X[f]|^2$$

Supposing that both amplitudes are expressed in decibels, $fs/2$ is the maximum representable frequency (by Nyquist theorem), and $E_x^{\text{frequency}}$ is taken over the same time frame as $E_x^{\text{time}}$. Should the quantities be the same?
You need Parseval's theorem. For the discrete-time Fourier transform (DTFT) you have the following relation:

$$\sum_{n=-\infty}^{\infty}|x[n]|^2=\int_{-1/2}^{1/2}|X(f)|^2df\tag{1}$$

where $f$ is normalized by the sampling frequency. For the DFT you have

$$\sum_{n=0}^{N-1}|x[n]|^2=\frac{1}{N}\sum_{k=0}^{N-1}|X[k]|^2$$

So due to Parseval's theorem it is always possible to compute a signal's energy in the time domain as well as in the frequency domain.