GNU Radio

GNU Radio does have blocks that can subtract streamed data in real time

GNU Radio does have blocks that can subtract streamed data in real time, though there isn’t a single block literally called “Subtraction”.

You can achieve subtraction cleanly in a few ways, depending on your situation:


🧮 1. Add block with negative gain (most common method)

  • Block: Add (or Add Const if subtracting a constant)
  • If you want:
    [
    \text{Output} = A – B
    ]
    Connect stream A to input 0, and stream B to input 1, then set the gain of input 1 to –1.
  • Or, more simply: feed B through a Multiply Const block with value –1, then into the Add block.

🧭 Typical use: removing a reference signal or background level from a measurement stream.


🧮 2. Sub block in the “Math Operators” category (if installed)

  • Some GNU Radio distributions (especially 3.10+ with standard blocks) include:
    • Sub (Subtraction)
    • Multiply, Divide, etc.
  • This block directly outputs:
    [
    \text{Output}[n] = \text{Input0}[n] – \text{Input1}[n]
    ]
  • Great for sample-by-sample subtraction of two streams.

📍 If you don’t see this in your installation:

  • It may be under “Operators” or “Math”.
  • Or you can add the equivalent with Method 1.

🧮 3. Custom subtraction with “Python Block” or “Expression Filter”

  • Use the Single Input/Multiple Input Expression block or embedded Python:
·         out[0] = in0[0] - in1[0]
  • Useful for more complex operations (e.g., subtracting a running average or calibration reference).

⚡ Important Notes

  • Both input streams must have identical sample rates and be synchronized (aligned in time).
  • If one stream lags behind, you may need a Delay block to line them up.
  • Subtraction happens sample-by-sample, not block-wise (unless you use a Vector-based block).

Example in radio astronomy:
If you’re using two antennas with SDRplay RSPduo and want to remove common-mode RFI, you can subtract the reference channel from the signal channel using:

[SDR 0] --->(A)---+
                  |---> Add block ---> Output = A - B
[SDR 1] --->(B)-MulConst(-1)-+

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.