Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed methode of mean power calculation. #10

Closed
wants to merge 1 commit into from

Conversation

Mictronics
Copy link

I changed the method to calculate mean power in the converter. We already have the average mean level so we can calculate average power from it. This corrects also the mean power value because what is calculated by the old method is slightly off, probably due to loose in precision when casting.

Example from live IQ data:
sum_level = 91873866
out_mean_level = 0.010695526
Level to dB is: 20log(out_mean_level) = 20log(0.010695526) = -39.416 dB

Old method (summing up mag^2):
sum_power = 85686914156
out_mean_power = 0.00015221812
Power to dB is: 10log(out_mean_power) = 10log(0.00015221812) = -38.175 dB
Converting this power back to level results in 0.0123377 so it's not equal to square level (or magnitude).

New method:
output_mean_power = out_mean_level^2 = 0.000114394
Power to dB is: 10log(out_mean_power) = 10log(0.000114394) = -39.416 dB

Second benefit of this change is a performance gain. I saw +0.15-0.3 Msamples/s in the benchmarks, except for the UC8 NODC that showed up to +2.8Msamples/s, on my Pi2 setup.

Corrects loose in precision, slight performance gain.
@mutability
Copy link

mutability commented Feb 23, 2017

The two calculations are not equivalent, which is why you get different numbers. With a time-varying input it is not true that sum(|Xi|)^2 = sum(|Xi|^2)

@Mictronics
Copy link
Author

Mictronics commented Feb 23, 2017

Well, it depends what result is required. In case of mean power per sample block (mean envelope power) I think my method is just fine. For my understanding your method is calculating the mean of peak power of each IQ pair (mean instantaneous power).
Since mean power is going into the demodulator for noise calculation the question is if it's better to take the mean power of a whole sample block or the mean of peak per IQ. What is your experience on that?

@mutability
Copy link

mutability commented Feb 23, 2017

The current implementation calculates power (in the only meaningful way for an unpredictably varying signal) and the demodulator expects to be able to deal with that as an energy value i.e. you can add and subtract in a simple way. Doing some type of averaging of the level (not power) over a sample block is not useful because the sample block boundaries are arbitrary and don't correspond with the received signal at all.

@mutability
Copy link

mutability commented Feb 23, 2017

Or to put it another way: the power value reported for a sample block is the average power of that block, such that (power * duration of sample block) = total energy in the sample block. The demodulator measures the energy in the signals it finds and subtracts that from the total energy to find the remaining "noise" energy. Then turn that back into a power by dividing by the block duration.

AFAIK it is correct as it currently is and applying this PR would break it, so I'm going to go ahead and close it. If you do spot errors in the calculation, or a way to compute the same thing faster, let me know.

@mutability mutability closed this Feb 23, 2017
Mictronics added a commit to Mictronics/readsb that referenced this pull request Feb 23, 2017
Mictronics added a commit to Mictronics/readsb that referenced this pull request Feb 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants