Skip to content

Question on power calculation (dBm) #1923

@mweyland

Description

@mweyland

Hey guys

I looked at the code used to calculate the power within the filter bandwidth because I am trying to do something similar in a different (completely unrelated) project. I read the wiki article about it and also a number of threads where "dBm" vs. "S-Meter" is debated ... passionately. Thankfully my question is not on that debate at all. All line numbers refer to the current ui_spectrum.c in the default branch:

On line 1383, arm_cfft_f32() is called. I presume this is computing the complex DFT of the voltage samples obtained from the QSD.

On line 1390, arm_cmplx_mag_f32() is called to turn the FFT result into magnitudes. Since the samples z are sampled voltages and this function is computing sqrt( Re(z)² + Im(z)² ), those magnitudes are signal amplitudes of the respective sinusoids. These sinusoids are still a representation of voltage.

In UiSpectrum_CalculateDBm(), the frequency bins that are within the filter bandwidth if the receiver are found, taking care of all edge cases. The boundary-bins are stored in Lbin and Ubin, respectively.

Starting from line 2084, I believe the samples are reshuffled such that the subsequent operation is easy but I am not entirely sure about that. In any case the voltage signal magnitudes are copied from FFT_MagData to FFT_Samples which I believe is used as some kind of working buffer(?)

Then in the loop on line 2101, the magnitudes between Lbin and Ubin are summed. These still represent voltages.

Finally on line 2114 this sum of voltages (magnitudes) is converted into the logarithmic domain.

Now here is my question: A power-equivalent to the voltage would be obtained by squaring the voltage (P ~ U²). In the logarithmic domain, we have log(U²) = 2*log(U), thus this factor of 2 would be accounted for in the calibration procedure when the variable slope is determined. In the present case, however, U is a sum of the voltages (or rather, magnitudes that represent voltages in the digital domain). Naively, I would assume that the conversion to power/dBm would call for the RMS value of the voltage. According to Parseval's theorem, this could be achieved by squaring the magnitudes before summing. Thus we would have log(U²_1 + U²_2 + ... + U²_n), which is NOT equal to 2*log(U_1 + U_2 + ... + U_n).

I'm not claiming to have found a bug in the code but I'm wondering about the mathematics that allow for the simple summing of magnitudes during aforementioned loop...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions