On Sun, Mar 17, 2019 at 1:52 PM John Ackermann N8UR <jra@febo.com> wrote:
On 3/17/19 3:45 PM, Kevin Reid wrote:
If you want to detect clipping, you want to know if the magnitude of any sample is greater than 1.0 — that's all there is to it. No FFT. My code happens to divide the stream into vectors but that is the only similarity.
That all makes sense. But if you are looking at the raw IQ stream, with two values per sample, do you just look to see if either the I or the Q hits 1, or do you need to manipulate both components of the complex number to get a real number?
Strictly speaking, the valid sample range is (usually) -1 to 1 for I and -1 to 1 for Q (a square on the complex plane). So, you could check both of them in the same way, and in fact that would be the most CPU-efficient way to check what you need.
The technique I showed above does not do that. Rather, it takes the magnitude of the samples, sqrt(I^2 + Q^2), and lets you check whether they fall within the unit circle on the complex plane. The argument for this measurement is that it gives you the same answer if the signal is phase- or frequency-shifted — which is completely irrelevant to you if you are just replaying a signal (or more generally, if you are performing the check just before you send the signal to the transmitter), but might matter if you are processing it further (such as by a filter), which could introduce phase shifts that will rotate the samples in the complex plane and hence allow the "corners to be cut off".
(In my application, I'm actually depending on the existence of those corners — I'm receiving a signal, which therefore predictably has a random frequency shift, and if any samples fall in the "corners" (the region covered by the square but not the unit circle) then that's a good indication that there will be clipping some of the time and so the overall gain should be reduced to keep things within the unit circle.)
No comments:
Post a Comment