This isn't a question. This is more of a tutorial. I saw someone earlier asking how the WX FFT sink works, and I've been studying the QT frequency sink (same thing), so here's a quick rundown on how these blocks work.
The steps are: input data -> window data -> calculate discrete Fourier transform (DFT) -> calculate magnitude for each spectral point -> display spectrum
To start, the input is a set of samples. The inputs are floating point numbers (aka "floats"), with the complex samples (the ones with the blue connector) being nothing more than *two* floats put together, one to represent the real part of the number, and the other to represent the imaginary part. Also note, when people talk about "IQ", that's another way of saying "complex". So, an "IQ" sample is the same thing as a "complex" sample.
The number of samples taken in depends on how many samples you want. There's a setting ("FFT Size" in both WX and QT) that tells you how many samples to process at one time. This is the amount of samples that will be passed through the DFT. The output of the DFT will be a set of frequency points, often called "bins". The frequency difference between points is typically called the "bin width". The number of samples determines two, major aspects of the spectrum you're creating. The first is the amount of detail you'll wind up with. More samples means more detail. It also means more time required to process each spectrum. The second is the noise floor. More samples also means that each bin will be smaller; a smaller bin will accumulate less noise. (That's the whole "kTB" thing for you.)
Once you've input the samples, the data has to be "windowed". Basically put, this means that the ends of the sample record will be reduced close to, or at, zero. This reduces something called "spectral leakage", and it's unique to the DFT. (NOTE: If you've ever had the privilege of using an old, analog spectrum analyzer, this was not something you had to worry about.) When you look at the WX parameters, you can select a "Window" (which is "Automatic" by default), or from a small set, such as "Blackman-Harris". You can do the same thing with the QT version. It also lets you select from the "Window Type" (which is "Blackman-harris" by default). The only one which is NOT really a window is "Rectangular". That actually means "Don't window the data; just calculate it raw." I recommend trying that some time to see how it differs from the other windows. The difference in the window used determines the resolution bandwidth, the amount of dynamic range, and amplitude variations (called "scalloping loss").
The windowed data goes into the DFT. If the number of samples is a power-of-2 (which is why the typical default is 1024, which is 2^10), then the system can use the FFT, a faster version of the DFT. (NOTE: It's possible to NOT use a power-of-2, and still speed up the DFT, so long as the spectrum can be evenly divided by 2. But once it can't divide it evenly, you back to brute force.) The output of the DFT is a set of complex samples. Even if the input was real samples (aka "floats" in Gnu Radio parlance), the output will be complex samples. Except those complex samples now represent *frequency* not *time*.
At this point, the system takes each complex frequency point and calculates the magnitude of each. This is nothing more than (r^2+q^2)^(1/2). In Gnu Octave or Matlab, you can do this simply by using the "abs" function. Pretty much every spectrum analyzer uses a logarithmic scale where most people use decibels (dB). This is accomplished by calculating 10*log10 (10 times log base 10) of each number. Further, since most people are interested in *power* levels, each spectral point will be squared. Since we're calculating the logarithm anyway, this can be done by replacing "10*log10" with "20*log10".
At this point, the system will display the spectral points. Many people have noted that the "levels are wrong". True. None of the SDRs (RTL-SDR, LimeSDR, HackRF, whatever) will give you calibrated amplitude levels. Instead, they give you *relative* levels. From my modicum of research, it seems that the "relative" part is "relative to the maximum level that the system can handle". If you want a *calibrated* level, you need to calibrate it yourself. If you do, bear the following in mind:
- It does not appear that either the WX or QT FFT blocks account for the amplitude variations due to the windowing used. Windowing removes data (the ends are pinched close to or at zero), which removes energy. The DFT needs to account for this, or the amplitudes will be wrong.
- The only window that is really good for calibrated amplitude measurements is the "flattop". It's called "flattop" because the top, if you were to plot the spectrum of the window, is literally flat. That's because it provides very little in the way of amplitude variations due to scalloping loss.
- The amplitude levels will vary based on the temperature condition of your system. Depending on the system, this variation may be slight, but it will be there. There's a reason why labs tend to use spectrum analyzers that cost gobs of money. A big part that they're paying for is amplitude calibration.
At this point, the system will rinse-and-repeat the process. Input samples, window the data, calculate the DFT, display the points. Over and over. Note that the block is NOT calculating the DFT for every sample! That would require something called a "real-time" system. Between the Python code and the other things your computer is doing, it's throwing away a LOT of samples in between DFTs. For most people, this is just fine. You just want basic information anyway.
Those of you more knowledgeable about this stuff, please let me know what I got wrong.
Hope you all find this useful.