10. Pulse Shaping and the Eye Diagram¶
PySDR’s Pulse Shaping chapter explains why symbols are sent as smooth pulses instead of rectangles, why the raised-cosine pulse avoids inter-symbol interference (ISI), why it is usually split into two root-raised-cosine (RRC) halves, one at the transmitter and one at the receiver, and how an eye diagram shows the result at a glance. Its Python exercise builds the transmitted signal in two steps: a “pulse train” with each symbol followed by seven zeros, then np.convolve with a 101-tap raised-cosine filter.
That is the clearest way to explain pulse shaping, and the most wasteful way to compute it: seven of every eight input samples are zeros, so seven of every eight multiplications produce nothing. This chapter computes the same signal without them, designs the RRC at compile time and checks its ISI there, and builds the eye diagram as a two-dimensional view of the signal using a custom std::mdspan layout, without copying it. This is the transmit-side counterpart of the receiver’s resampler in A Complete Receiver.
The code is in code/include/cppsdr/pulse.hpp and code/tests/test_pulse.cpp; figure-generating-scripts/pulse_reference.py runs PySDR’s exercise (200 symbols instead of 10, fixed seed) for comparison.
Skipping the Zeros: Polyphase Interpolation¶
Write the convolution out. Output sample \(m\) is \(y[m] = \sum_k h[k]\, x[m-k]\), and the pulse train \(x\) is non-zero only at multiples of the 8 samples per symbol, where it holds symbol \(s[n]\). So only the taps \(k\) with \(m - k\) a multiple of 8 contribute. Write \(m = 8n + p\), with \(p\) the position within the symbol (the phase), and the sum becomes
which reads: output phase \(p\) of symbol \(n\) uses every eighth tap, starting at tap \(p\), applied to the current and previous symbols. For 101 taps that is 13 multiply-adds per output instead of 101. The 101 taps split into 8 sub-filters, the polyphase components, and since the taps are compile-time constants the split happens in the constructor, once:
template <std::size_t N, std::size_t SPS, class T = float>
class polyphase_interpolator {
public:
static constexpr std::size_t J = (N + SPS - 1) / SPS; // taps per phase: 13
void process(std::span<const T> symbols, std::vector<T>& out)
{
for (const T s : symbols) {
hist_[pos_] = hist_[pos_ + J] = s; // mirrored ring, written backwards
const T* w = hist_.data() + pos_; // w[j] = the symbol j steps ago
pos_ = pos_ == 0 ? J - 1 : pos_ - 1;
for (std::size_t p = 0; p < SPS; ++p) { // SPS outputs per symbol
T acc{};
for (std::size_t j = 0; j < J; ++j) acc += bank_[p][j] * w[j];
out.push_back(acc);
}
}
}
...
};
The symbol history is the mirrored ring from FIR Filters in C++, filled backwards so that the last \(J\) symbols always lie newest-first in contiguous memory. The input is symbols, not a pulse train, so the zeros are never even created. Fed PySDR’s 200 symbols in random blocks of 1 to 17 symbols (plus 13 zero symbols at the end to flush the filter, the tail that np.convolve adds), the interpolator reproduces PySDR’s x_shaped to \(3 \cdot 10^{-7}\), the difference between float and double.
GNU Radio’s interp_fir_filter and pfb_arb_resampler blocks are built the same way, as banks of sub-filters, and so is every FPGA interpolator, where the saving is in multipliers rather than CPU time.
The Root Raised Cosine at Compile Time¶
The raised cosine has its own 0/0 at \(t = \pm T_s/(2\beta)\), handled in Compile-Time DSP: Filters, Tables and Constellations. The root raised cosine has two: at \(t = 0\) and at \(t = \pm T_s/(4\beta)\). Both are removable, with known finite limits, so the design function returns those limits instead of dividing by zero:
constexpr double rrc_at(double t, double Ts, double beta)
{
const double x = t / Ts;
if (cx::abs(x) < 1e-12) return (1 + beta * (4 / cx::pi - 1)) / Ts;
if (cx::abs(cx::abs(4 * beta * x) - 1) < 1e-12) {
const double a = cx::pi / (4 * beta);
return beta / (Ts * cx::sqrt(2.0)) * ((1 + 2 / cx::pi) * cx::sin(a) + (1 - 2 / cx::pi) * cx::cos(a));
}
return (cx::sin(cx::pi * x * (1 - beta)) + 4 * beta * x * cx::cos(cx::pi * x * (1 + beta))) /
(Ts * cx::pi * x * (1 - (4 * beta * x) * (4 * beta * x)));
}
GNU Radio’s firdes::root_raised_cosine handles the second singularity with a different, algebraically rearranged expression. After normalizing both to the same DC gain, the two agree to \(7 \cdot 10^{-9}\) for PySDR’s parameters (101 taps, \(\beta = 0.35\), 8 samples per symbol), checked in the cross-check program. Our version normalizes the taps to unit energy instead (\(\sum h^2 = 1\)). Then the cascade of transmit RRC and matched RRC has exactly 1 at its centre, and a \(\pm 1\) symbol comes out of the matched filter as \(\pm 1\).
ISI as a Compile-Time Number¶
PySDR states the key property: sampled at the symbol instants, a raised-cosine pulse is zero at every other symbol, so neighbouring symbols do not interfere. The RRC alone does not have this property; only the cascade RRC * RRC does, and only approximately, because a 101-tap filter is a truncated version of an infinitely long pulse. How large is the residual?
That is a question about constants, so the compiler can answer it. convolve computes the cascade at compile time, and worst_case_isi adds up the pulse’s magnitude at all other symbol instants relative to its centre. This is the worst case, all neighbours conspiring against one symbol:
constexpr auto rrc = pulse::root_raised_cosine<101>(0.35, 8);
constexpr auto rrc2 = pulse::convolve(rrc, rrc); // transmit * matched filter
static_assert(pulse::worst_case_isi(rc_d, 8) < 1e-6, "raised cosine: zero crossings at every other symbol");
static_assert(pulse::worst_case_isi(rrc2, 8) < 0.01, "RRC * RRC: small residual ISI from truncation");
static_assert(pulse::worst_case_isi(rrc, 8) > 0.3, "RRC alone is not a Nyquist pulse");
The numbers behind those bounds: the raised cosine’s ISI is exactly 0 (its samples at the other symbol instants are zero to rounding). RRC * RRC leaves 0.009 with 101 taps, 0.041 with 41 taps and 0.0036 with 201 taps. The RRC alone has 0.333. This is the filter-length trade-off of pulse shaping as a table, and it is computed before the program runs. If someone shortens the filter to save CPU time, the build can say how much eye opening that costs.
An Eye Diagram Is a View¶
PySDR describes the eye diagram as chopping the signal into chunks two symbol periods long, one starting at every symbol, and overlaying them. The chunks overlap: each sample belongs to two of them. So an eye diagram is a matrix with one row per symbol and \(2 \times 8\) columns, where row \(r+1\) starts 8 samples after row \(r\). In memory that is simply the signal itself, read with a different index formula: element \((r, c)\) is sample \(8r + c\).
C++23’s std::mdspan is designed for exactly this: it separates the data from the layout, the function that maps indices to offsets. The standard layouts cannot express overlapping rows. layout_stride comes closest (offset \(= r \cdot s_0 + c \cdot s_1\)), but its preconditions require every element to have a unique offset. The standard does allow user-defined layouts, though, and one with overlapping rows is about 40 lines (layout_hop in pulse.hpp). Its heart is the index formula, plus an honest answer to the question mdspan asks every layout:
constexpr index_type operator()(index_type r, index_type c) const noexcept { return r * hop_ + c; }
static constexpr bool is_always_unique() noexcept { return false; } // rows may overlap
constexpr bool is_unique() const noexcept { return hop_ >= e_.extent(1); }
constexpr index_type stride(rank_type r) const noexcept { return r == 0 ? hop_ : 1; }
With it, the eye diagram is a function that does no work:
using eye_view = std::mdspan<const float, std::dextents<std::size_t, 2>, layout_hop>;
eye_view eye_diagram(std::span<const float> x, std::size_t sps, std::size_t first_instant);
auto eye = pulse::eye_diagram(y, 8, first); // rows x 16, column 8 = symbol instant
float v = eye[r, 8]; // the r-th symbol, as sampled by the receiver
The test checks that the view really does not copy: &eye[1, 0] == &eye[0, 8], the start of one row is the symbol instant of the previous one. The same layout with a hop smaller than the frame length describes the overlapping frames of the Welch estimate in The FFT and the Spectrogram.
Here are three eye diagrams of the same 300 random BPSK symbols, computed by the polyphase interpolator and drawn from such views:
The raised cosine (left) passes exactly through \(\pm 1\) at the symbol instant. The RRC alone (centre) has a smaller amplitude, because unit energy spreads the pulse’s height, and above all it has a blurred eye: the 0.333 of ISI computed above. After the matched filter (right), the eye is as clean as the raised cosine’s. eye_opening turns that into a number, the smallest distance of any trace from zero at the symbol instant relative to the mean distance: 1.000 for the raised cosine, 0.664 for the RRC alone, and 0.991 with the matched filter (the 0.009 of residual ISI again). Sampling one sample late (1/8 of a symbol) reduces the opening to about 0.67 in both good cases, which is why PySDR’s next chapter needs timing recovery (Timing Recovery with a Compile-Time Filter Bank).
Key Takeaways¶
Never multiply by the zeros of a pulse train: a polyphase interpolator computes PySDR’s
np.convolveresult with 13 instead of 101 multiply-adds per output, and takes symbols, not zero-padded samples.The RRC formula has two removable singularities; return their limits. Our RRC matches GNU Radio’s
firdesto \(7 \cdot 10^{-9}\).Normalize the RRC to unit energy, and the matched-filter cascade returns the symbols with their original amplitude.
Residual ISI is a compile-time number: 0.009 for two 101-tap RRCs at \(\beta = 0.35\), 0.041 for 41 taps.
static_assertcan guard it.An eye diagram is the signal seen through a layout with overlapping rows. A small custom
std::mdspanlayout makes it a zero-copy view.