Super-Light intro to nonlinearities
Amplifier model
Ideally, an amplifier has this output function $f(x)$, where $x$ is the input amplitude:
$$f_\text{ideal}(x) = a_1 x\text,$$
and we call $a_1$ the amplitude gain (which is inherently the square root of the power gain).
Sadly, real amplifiers don't have ideal behaviour, instead they have:
$$f(x) = a_1 x\text + a_2 x^2 + a_3 x^3 + a_4 x^4 + \ldots$$
The $a_i$ can be positive, negative, whatever the physics of the amplifier makes them.
A good amplifier has a $|a_1|\gg |a_2| ,|a_3| , |a_4|,\ldots$.
As a general rule of thumb, a sensibly designed amplifier
Intermodulation products
Now, why is $a_2$, for example, a problem?
Let's look at
$$f_{2}(x) = a_2 x^2\text,$$
where we've simply set all $a_i=0$ except $a_2> 0$.
Let's feed in a single tone, $x=\cos(\omega t)$ at frequency $f = \frac{\omega}{2\pi}$:
\begin{align}
f_2(\cos(\omega t)) &= a_2\left(\cos(\omega t)\right)^2\\
&=a_2\cos(\omega t)\cos(\omega t)&\hspace{-8em}\text{trigonometrics: }\cos(a)\cos(b) &= \frac12\left(\cos(a+b)+\cos(a-b)\right)\\
&=a_2\frac12\left(\cos(\omega t + \omega t) + \cos(\omega t - \omega t)\right)\\
&=\frac{a_2}2 \left(\cos(2\omega t) + \underbrace{\cos(0)}_{=1}\right)\\
&= \frac{a_2}2 \cos(2\omega t) + \frac{a_2}{2}
\end{align}
Oooops! We've built a frequency doubler! That's where the harmonics on even multiples of the fundamental frequency come from: from $a_i\ne 0$ where $i$ even. And the fact that the double frequency is far away from the input frequency allows us to cancel that effect with a simple low-pass filter.
Now, what happens if we have two tones, e.g. $x=\cos(\omega_1 t) + \cos(\omega_2 t)$?
We get harmonics at $2\omega_1$, $2\omega_2$, $\omega_1 + \omega_2$ and $|\omega_1\omega_2|$.
Good news is, if $\omega_1$ and $\omega_2$ are close together (relative to their value, e.g. $\frac{\omega_1}{2\pi} = 14.1\,\text{MHz}$, $\frac{\omega_2}{2\pi} = 14.2\,\text{MHz}$), then these intermodulation products will also be "far away" from the frequencies we care about, and we can filter them away. By the way, that's the difference between an amplifier and an active mixer: The amplifier has large $a_1$ and small $a_2$, and the mixer has large $a_2$ and small $a_1$. All amplifiers are (bad) mixers!
The math becomes longer, but also stays boring (and that's why I'm leaving it as an exercise for the reader) for $a_3\ne0$: You get intermodulation products that are close to the original frequencies, namely at $\omega_1 \pm |\omega_2-\omega_1|$ and $\omega_1 \pm |\omega_2-\omega_1|$, and since that frequency difference was small to begin with, these products land in our band of interest and can't be simply filtered out.
Practical measurements
I have:
- 20MHz dual trace oscilloscope,
- RTL SDR dongle,
- ubitx transciever,
- 30V/20A power supply.
- I am planning to get hold of a nanoVNA as well
That's not half bad; I'd say, get a few attenuators, too, and you've got a basic setup!
None of the following is done over-the-air, but with cabling in between devices.
I don't know the UBITX, but you say it's a transceiver. If you can use TX at the same time as RX on that device, you can replace the RTL-SDR below all with the RX side of your UBITX.
- Use the ubitx (-> somewhere between 16 and 20 MHz low-pass filter) -> attenuator -> RTL-SDR to calibrate:
- Make sure all cables are reliable (this is like embedded debugging – you wouldn't guess how much headache unreliable connections cause), and all connectors are screwed on to a proper connection (don't overtighten them. Coax connectors can be damaged by too much force.)
- Start with a strong attenuator to avoid frying the RTL-SDR.
- Disable any AGC on the RTL-SDR.
- Send a pure tune at say 1/8 of the max digital amplitude, at medium TX gain, at say 14.00 MHz using your UBITX (if you can, use offset tuning – I don't know the ubitx, but you want to have LO leakage, if existent, to be out of band)
- Tune the RTL-SDR to let's say 14.35 MHz, sampling rate 1 MHz.
- Use a spectrum plot (in a pinch, a high-length FFT display will do!) and note down the "digital" power for the one tone you see. (better: Use a parametric spectrum estimator that finds the N strongest tones)
You should see a very dominant peak at 14.00 MHz; verify that you're far away from Full Scale of the RTL-SDR (or that will be what introduces your nonlinearities).
If you see more than one peak (higher than say -45 dB of the main peak), try reducing the gain of the RTL-SDR.
- A good rule of thumb is that the time domain signal (i.e. as if you hooked up an oscilloscope to the baseband signal) should be -10 dB from full scale (i.e. typically "1/10").
- Write down all the settings: TX gain, TX amplitude, frequencies, the attenuator you used, the RX gain, sample rate, FFT length... Everything you can configure must be reproducible. (This is like debugging an embedded system!)
- You now have a relatively calibrated transceiver pair, i.e. when you increase the amplitude or power on the transmitter by x dB , you see the same x dB on the receiving end. Great! Test whether that's true, and for which range of transmit powers. This gives you the range over which this measurement setup works linearly and can be used.
- Note down what you see on 14.00 MHz. Tune to 28.35 MHz; note down what you see at 28.00 MHz. Since the RTL-Dongle isn't calibrated to have the same amplitude response over the whole frequency band, this doesn't say much as it – but we'll compare this number later! (The filter should eliminate the 28 MHz spurs from your transmitter completely – these thus are effects of the RTL-SDR, so we need to ignore them later on). Optimally, you see nothing but noise floor here.
- That means that when you send two tones in a small frequency distance on the UBITX, you'll also only see these two tones on the receiving end. And they should have the same amplitude. Test that! If you see new tones appearing: That's the intermodulation of one tone with the other. Reduce amplitude / gains.
- add the amplifier and enough attenuation to (at least) compensate its gain between the UBITX (-> filter)-> and the attenuator we used so far. Power it.
- If the amplifier is perfectly linear, then gain + attenuation would cancel out, and we'd just see the input at the output (plus maybe a little more attenuation, because you probably don't have exactly the same attenuator as your amplifier has gain, but that doesn't matter at all).
- Send a single, low-power tone. Make sure that your RTL-SDR is far from saturation (e.g. via time domain signal). If not, add more attenuation.
- SLOWLY increase the tone's power. You'll observe that over the range that was our measurement range above, the x dB input power increase -> x dB output power increase doesn't hold. You might need to add more attenuation at some point. That simply gives you two measurement curves; one with, and one without the extra attenuation.
- This is one figure of merit: You now know how much, on your frequency that you'll be using, the amplifier really amplifies for a given output power. At some point, pumping more power into the amplifier has diminishing returns!
- When you plot the output vs input power graph, you'll be able to read the 1 dB compression point from that. Save that graph! You'll need the curve later on
- Do the same – but do it for the 28 MHz frequency! That's the second order intermodulation product
- Make a curve for second order output vs input power. Save that graph.
- Find the second order intercept point: Figure borrowed from RF Wireless world, which I've never heard of before asking google just now. You combine the two graphs above into one and find the intercept point if you "extend" your curves with a straight line.
- rule of thumb: stay 10 dB away from IIP2 for acceptable linearity
- Same, but with two tones, and just looking at the spurs in the 14 MHz band; gives you IIP3.
These are the two main figures you usually use to describe how (non)linear an amplifier is.
Now what?
Armed with knowledge of IIP2 and IIP3, you know how much you can put into your amplifier until it becomes very nonlinear, and can, through extrapolating your curves, also estimate how much power you'll see on the even and odd harmonics. That helps you decide on filters!
Predistortion
However, that's kind of a sad thing: our amplifier uses its power to produce unwanted frequency components, that we then have to put effort into suppressing. Sad!
What if we could take the $f(x)$ equation, measure the $a_i$, and find something like a "good" inverse function $g(x) \approx {f^{-1}(x)}{a_1}$, so that we can apply that function $g$ to the signal we actually want to send:
$$f(g(x)) \approx a_1 x$$
That would be awesome, because now we're just using our amplifier to produce the signal we want, and none of the intermodulation products.
This technique exists, it's called predistortion (which makes sense, since $g$ definitely distorts $x$, but only in a manner that "pre-reverts" the distortion of $f$). And, good news, your UBITX is a software defined radio, so you can calculate $g(x)$ on your PC and send it to your UBITX instead of sending $x$. Yay!
Caveats:
- Needs software to do that
- $f(x)$ isn't actually fully invertible – so perfect predistortion won't happen, but you can significantly reduce out-of-band radiation. Professional radio equipment does predistortion for that very reason.
Here's a talk by a friend of mine, MW0LNA on doing exactly that: predistortion in the digital domain.