Changing the Rate
Sooner or later every flowgraph must
change speed: the dongle delivers
millions of samples a second, the
speaker wants 48,000, and the computer
would like its evening back. Reducing
the rate is decimation — keeping
one sample in N. Raising it is
interpolation — inserting computed
samples between the real ones. This
chapter runs the experiment the whole
subject hangs on: the lab decimated
the same signal two ways, wrong and
right, and measured both. The transcript
is gnu-radio-lab/transcripts/t02-decimation.txt;
the script is gnu-radio-lab/fg2_decimation.py.
The experiment
Two tones at 96,000 samples per second: 2,000 Hz (the wanted signal) and 20,000 Hz (an unwanted neighbour), each at amplitude 0.5, one second of them. Decimate by 4 and the rate becomes 24,000. Chapter 3 prices that: the new band, for a complex stream, runs from −12,000 to +12,000 Hz. The 2,000 Hz tone fits comfortably. The 20,000 Hz tone does not fit at all — and anything that does not fit folds.
Branch A — wrong. Keep one sample
in four, no filter (the keep_one_in_n
block: decimation and nothing else).
The measurement of Branch A's file:
samples: 24000
strongest frequencies (Hz):
2000.0 magnitude 12000.0
-4000.0 magnitude 12000.0
There is the forgery, caught. The 20,000 Hz tone did not disappear; it reappeared at −4,000 Hz — since 20,000 − 24,000 = −4,000, its samples march the other way around the circle and the stream now swears, with full magnitude (12,000, equal to the wanted tone's), that a signal lives at −4,000 Hz. Nothing downstream can evict it. It is indistinguishable from a real station that was always there. This is chapter 3's aliasing with its gloves off, and it is why the order of operations in this chapter is a rule and not a tip.
Branch B — right. The same stream,
through a low-pass filter first
(cutoff 8,000 Hz — safely below the new
12,000 Hz boundary — transition
2,000 Hz, 115 taps), with the decimation
done inside the filter block itself
(fir_filter_ccf with a decimation of
4, so the discarded samples are never
even computed on). The measurement:
samples: 24000
strongest frequencies (Hz):
2000.0 magnitude 11999.7
2001.0 magnitude 8.0
One peak. The wanted tone at full strength (11,999.7 of an ideal 12,000), the neighbour not folded, not attenuated — absent, its would-be seat at −4,000 Hz showing nothing above the measurement's floor (magnitude single digits, some 1,500 times weaker, roughly 63 dB down). The filter removed the 20,000 Hz tone while the stream was still fast enough for the tone to be honestly itself; then, and only then, the rate fell.
The rules this buys
- Filter first, at the old rate. The filter's job is to remove everything that cannot fit in the new band, while it still exists as itself. Then decimate.
- Decimate inside the filter when you can. GNU Radio's FIR blocks take a decimation factor and skip the outputs nobody will read — the same answer for a fraction of the arithmetic.
- Interpolation is the mirror
errand: insert zeros (or repeat)
to raise the rate, then low-pass at
the old band edge to smooth the
staircase into a wave, or the same
folding gremlins appear above the old
Nyquist line. The lab did not run an
interpolation chain; it is described
here from the documentation and
criteria.mdfiles it as such. - Rates compound quietly. Two decimations of 4 and 5 are a decimation of 20, and every intermediate rate is a band edge something must respect. State the rate at every block boundary, in the variable blocks and in your notes — chapter 16's first diagnostic question is always what rate is it here?
Check: in Branch A, predict where a 30,000 Hz tone at the same input would have landed after decimation by 4 to 24,000: 30,000 − 24,000 = +6,000 Hz. The folding is addition and subtraction of the new rate until the answer fits the band. When that sum is reflex, chapter 11 can spend your attention on the receiver itself, whose middle block is this chapter's lesson wearing a radio's clothes.