Your First Flowgraph
Time to run something. This chapter
builds the smallest flowgraph that
still teaches the craft: a tone made
by arithmetic, one second of it, tapped
into two files — one untouched, one
through a filter — and then measured,
with plain Python, until the numbers
confess whether the chain did what the
diagram promised. The lab ran exactly
this, on the machine that wrote the
guide; the scripts are
gnu-radio-lab/fg1_tone_filter.py (and
its Companion twin, chapter 5) and the
transcript is
gnu-radio-lab/transcripts/t01-first-flowgraph.txt.
The chain, block by block
- Signal source (
analog.sig_source_c) makes a complex tone: sample rate 48,000, frequency 1,000 Hz, amplitude 1.0. Its output is chapter 2's arrow, turning steadily — 48 samples per turn, since 48,000 ÷ 1,000 = 48. - Head (
blocks.head) passes the first 48,000 samples and then stops the graph: exactly one second. An unpaced source would run forever; the head is this graph's full stop. - Low-pass filter (
fir_filter_ccfwith taps designed byfirdes.low_pass) keeps what is below 1,500 Hz and removes what is above, with a 500 Hz transition band to do it in (chapter 8 gives filters their own chapter; here it is enough that the 1,000 Hz tone is meant to pass). - Two file sinks (
blocks.file_sink) write the raw and filtered streams to disk, byte for byte (chapter 7 priced the format: complex pairs, eight bytes each).
The run, from the transcript:
wrote tone_raw.cfile and tone_filtered.cfile
(48000 samples each, expected)
-rw-rw---- 1 384000 tone_filtered.cfile
-rw-rw---- 1 384000 tone_raw.cfile
48,000 samples × 8 bytes = 384,000 bytes, twice. The first check passes: the chain produced exactly the second of signal it was asked for, in both branches. Counting is not pedantry — in a tool where a wrong rate silently rescales your whole world, "the file is the size the arithmetic promised" is the cheapest truth on offer.
Measuring instead of admiring
The lab then read both files with
gnu-radio-lab/measure.py — plain
NumPy, no GNU Radio — which counts the
samples and runs the FFT, the
standard arithmetic that reports how
much of each frequency is present. The
raw file answered:
samples: 48000
magnitude: mean 1.0000, max 1.0000
strongest frequencies (Hz):
1000.0 magnitude 47999.9
Read that like a lab notebook. The arrow's length (chapter 2) is 1.0000 at every sample, as a unit-amplitude tone promised. All of its energy sits at 1,000.0 Hz — the next-strongest bin is a whisper (magnitude 1.4 against 47,999.9). The peak's size is itself a checkable sum: an FFT of 48,000 samples of a pure tone stacks them all into one bin, 48,000 × 1.0 ≈ 47,999.9, the shortfall being rounding in the last decimal.
The filtered file answered:
samples: 48000
magnitude: mean 0.9965, max 1.0310
strongest frequencies (Hz):
1000.0 magnitude 47828.0
Still 1,000 Hz, still essentially all the energy — the filter passed the tone it was told to pass. The small print is honest too: mean length 0.9965 rather than 1.0000, a peak of 1.0310, and a breath of energy in the bins next door. That is the filter's startup transient: a filter computes from a window of recent samples, and for its first few dozen outputs the window is partly empty, so the chain stumbles for a few microseconds before it walks straight. Real filters do this. The measurement caught it because the measurement was actually made — which is the chapter's whole sermon in one anecdote.
What to carry on
- A flowgraph is finished when its output has been measured, not when it has run without error. Running is the hypothesis; the file is the evidence.
- State the expectation before the run — 48,000 samples, a peak at 1,000, length 1.0000 — and let the numbers argue. Every lab in this guide writes its expectations into the script that runs it, so the transcript shows the promise and the keeping of it side by side.
Check: repeat the run and change one number — the tone to 2,000 Hz, above the filter's 1,500 Hz cutoff. Predict first: the raw file unchanged in character, the filtered file's peak gone or gutted. Then measure. When your predictions start surviving contact with the files, you are doing the craft; chapter 8 explains what the filter was doing while you watched.