Skip to content

Spiking Neural Networks and Dynamics

In Chapter 12 we met biological neurons through continuous differential equations, while Chapter 07 introduced recurrent neural networks and state-space models that carry hidden memory across time. This section bridges those two worlds, showing how discrete-time Leaky Integrate-and-Fire neurons operate as minimal recurrent cells, how richer adaptive and resonant dynamics unlock long-horizon memory, and how encoding continuous signals into spike timing enables sub-millisecond decisions.

Discrete-Time LIF as a Minimal Recurrent Cell

  • Recall the leaky wooden bucket analogy from Chapter 12. Rain pours into the bucket (incoming synaptic current), a small hole near the bottom constantly drains water away (membrane leak), and the instant the water reaches the rim (threshold), the bucket tips over in a sharp splash (an action potential). That picture gave us the continuous-time differential equation \(\tau_m \frac{dU(t)}{dt} = -U(t) + R\,I(t)\) (setting resting voltage to \(0\) for convenience).

  • Now imagine filming that leaky bucket with a fast camera that takes one crisp snapshot every \(\Delta t\) milliseconds. Between frame \(t - 1\) and frame \(t\), any leftover water decays by a fixed multiplicative fraction \(\beta = \exp(-\Delta t / \tau_m) \in (0, 1)\), fresh synaptic rain \(W X[t]\) pours in from upstream spikes \(X[t]\), and if the neuron just fired at the previous step (\(S[t - 1] = 1\)), its membrane voltage drops back down by the threshold \(\theta\).

  • Writing that flip-book update in matrix-vector form turns the biophysical neuron into a remarkably clean discrete-time Leaky Integrate-and-Fire (LIF) recurrence.

\[U[t] = \beta \, U[t-1] + W X[t] - S[t-1]\,\theta\]
\[S[t] = \Theta\!\bigl(U[t] - \theta\bigr) = \begin{cases} 1 & \text{if } U[t] \ge \theta \\ 0 & \text{if } U[t] < \theta \end{cases}\]
  • Look closely at those two lines through the lens of Chapter 07. The membrane potential \(U[t]\) is literally a hidden recurrent state carried from one time step to the next, just like the hidden vector \(h[t]\) of an RNN or the latent state of a diagonal State-Space Model (SSM). The decay factor \(\beta\) behaves like a fixed or learnable forget gate that sets the neuron's temporal memory horizon (when \(\beta = 0.9\), a past impulse takes roughly ten steps to fade to \(1/e\) of its initial height). The only twist separating a spiking neuron from a classic linear state-space block is its sharp binary output \(S[t] \in \{0, 1\}\) produced by the Heaviside step function \(\Theta(\cdot)\) and the negative reset feedback \(-S[t-1]\,\theta\).

Discrete-time Leaky Integrate-and-Fire neuron unrolled across steps t-1, t, and t+1 showing recurrent membrane decay beta U, synaptic input W X, binary threshold firing S, and subtractive reset feedback

Reset-by-Subtraction Versus Reset-to-Zero

  • When a neuron's membrane potential crosses threshold, say reaching \(U[t] = 1.35\) when \(\theta = 1.0\), what should happen to that extra \(0.35\) of voltage left above the rim? Neuromorphic modellers choose between two reset rules, and the difference matters far more than it first appears.

  • Picture a neighbourhood coffee shop that stamps a loyalty card and gives you a free espresso after ten stamps. Suppose you arrive with twelve colleagues and buy twelve coffees in one transaction. Under reset-to-zero (hard reset), the barista hands you one free espresso and shreds the card completely, discarding your two leftover stamps. Under reset-by-subtraction (soft reset), the barista subtracts ten stamps and immediately puts two fresh stamps onto your new card so nothing from your large order is lost.

  • Mathematically, the two mechanisms modify the state right after a spike \(S[t] = 1\) in distinct ways.

\[U_{\text{hard}}[t] = U[t]\,\bigl(1 - S[t]\bigr), \qquad U_{\text{soft}}[t] = U[t] - S[t]\,\theta\]
  • Reset-to-zero mimics biological hyperpolarisation faithfully and can be wired cleanly with a single discharge transistor in analogue silicon. Yet in discrete-time simulations, throwing away excess potential \(U[t] - \theta\) introduces a systematic quantisation error whenever strong input pushes \(U[t]\) well past threshold in a single step.

  • Reset-by-subtraction preserves that exact excess charge as a head start toward the next spike. Because no integrated input current is ever discarded, the neuron's average firing rate tracks strong inputs linearly without clipping errors, making subtractive reset the default choice in modern deep spiking networks and ANN-to-SNN conversions.

Richer Neuronal Dynamics Beyond Vanilla LIF

  • Trying to build a sophisticated temporal brain solely from identical vanilla LIF neurons is a bit like asking an orchestra to perform a symphony using only snare drums. A snare drum marks crisp beats, yet it cannot sustain a slow cello melody across ten seconds or ring selectively at one musical pitch. Real cortex contains dozens of specialised neuronal classes, and neuromorphic architectures borrow four powerful dynamical upgrades that stay remarkably lightweight in hardware.

Adaptive Threshold (ALIF) Neurons for Working Memory

  • Think about stepping from a dim hallway into bright afternoon sunshine. For the first second your eyes squint, then your pupils adapt so moderate changes stay clearly visible without blinding you. Adaptive Leaky Integrate-and-Fire (ALIF) neurons build this exact self-regulating mechanism directly into their firing threshold.

  • Every time an ALIF neuron fires, a slow adaptation variable \(a[t]\) jumps up by one and decays gradually with a long time constant \(\rho \in (0, 1)\) (often spanning hundreds of milliseconds, much slower than membrane decay \(\beta\)). The effective threshold shifts upward in proportion to \(a[t]\).

\[a[t] = \rho \, a[t-1] + S[t-1], \qquad \theta[t] = \theta_0 + b \, a[t]\]
  • Here \(\theta_0\) is the baseline threshold and \(b > 0\) sets the adaptation strength. This tiny extra scalar per neuron turns out to be a game-changer. Because \(a[t]\) retains a fading trace of past spikes long after membrane voltage \(U[t]\) has leaked back to zero, ALIF populations achieve long-horizon working memory on delayed-cue and speech tasks that closely rivals LSTM gating (Chapter 07), while still communicating purely through sparse binary spikes.

Resonant Neurons and Frequency Selectivity

  • Now imagine pushing a child on a playground swing. If you shove randomly at awkward moments, the swing barely moves, yet tiny gentle pushes timed to the swing's natural rhythm rapidly build huge amplitude. Standard LIF neurons are pure low-pass integrators (faster inputs simply pile up faster). Resonate-and-Fire neurons replace the real scalar voltage \(U[t]\) with a damped two-dimensional oscillator, neatly written as a complex state \(z[t] = x[t] + i\,y[t]\).
\[z[t] = \exp\!\bigl((-\alpha + i\omega)\,\Delta t\bigr)\,z[t-1] + W X[t]\]
  • Whenever the real or imaginary component crosses threshold, the neuron spikes. Because its internal state rotates at angular frequency \(\omega\), a resonant neuron ignores steady background hum or off-beat noise and fires enthusiastically only when incoming spikes arrive in rhythm with its preferred frequency. This connects directly to complex diagonal state-space models (like LRU and S4D in Chapter 07) and gives neuromorphic audio processors natural pitch and speech-formant selectivity.

Izhikevich Bursting Dynamics

  • Real cortical cells exhibit a zoo of firing signatures beyond regular clicking, including chattering, fast spiking, and intrinsically bursting packets of rapid spikes followed by silence. Eugene Izhikevich distilled the messy four-variable Hodgkin-Huxley biophysics (Chapter 12) into a brilliant two-variable quadratic system that reproduces over twenty biological firing patterns with only a handful of additions and multiplications per step.
\[\frac{dv}{dt} = 0.04 v^2 + 5 v + 140 - u + I, \qquad \frac{du}{dt} = a(b v - u)\]
  • Whenever \(v \ge 30\,\text{mV}\), the cell emits a spike and resets via \(v \leftarrow c\) and \(u \leftarrow u + d\). Simply tuning the four small parameters \((a, b, c, d)\) transforms the exact same silicon neuron from a calm regular-spiking pyramidal cell into a bursting pacemaker, giving hardware engineers biological diversity without Hodgkin-Huxley's heavy computational price.

Learnable Time Constants and Synaptic Delays

  • In early spiking networks, every neuron shared the exact same hand-picked leak \(\beta\) and zero transmission delay. Modern neuromorphic models treat both the membrane decay \(\beta_i\) (parameterised via a sigmoid so \(\beta_i \in (0, 1)\)) and learnable axonal or synaptic delays \(d_{ij}\) as trainable parameters.

  • Think of a team of couriers starting from different towns who all need to walk through a locked door at the exact same second to push it open together. By learning distinct delays \(d_{ij}\), spikes triggered at earlier and later moments in a spoken word or gesture arrive at a downstream neuron in tight coincidence, turning a single shallow spiking layer into an exquisitely accurate spatio-temporal pattern detector.

Converting Continuous Signals into Spikes

  • Physical sensors such as microphones, strain gauges, and standard cameras output continuous real numbers rather than spikes. Before a spiking network can process a photograph or audio clip, an input layer must translate continuous intensity \(x \in [0, 1]\) into a binary spike stream. Three core encoding schemes sit at the heart of neuromorphic engineering, each making a distinct bargain between noise tolerance, spike count, and reaction speed.

Diagram comparing Rate Coding, Time-to-First-Spike Latency Coding, and Delta Modulation converting a continuous input waveform into three distinct spike train patterns

Rate Coding

  • Imagine judging how busy a coffee shop is by counting how many customers walk through the door over a full ten-minute window. Rate coding converts a normalised intensity \(x \in [0, 1]\) into a stochastic Bernoulli or Poisson spike train where the probability of firing at each time step equals \(x\).
\[P\!\bigl(S[t] = 1\bigr) = x, \qquad \hat{x} = \frac{1}{T}\sum_{t=1}^{T} S[t]\]
  • Rate coding is wonderfully forgiving of dropped packets or noisy transistors, because losing one spike out of twenty barely shifts the average. Its weakness is speed and energy. Because the standard error of a binomial estimate shrinks slowly as \(1/\sqrt{T}\) (Chapter 04), distinguishing \(x = 0.72\) from \(x = 0.78\) demands dozens or hundreds of time steps and many energy-burning spikes.

Time-to-First-Spike Latency Coding

  • Now imagine a 100-metre dash where every runner wears a number on their chest and starts at the same gunshot. You do not need them to run fifty laps to see who is fastest. The moment the quickest runner crosses the tape, you already have the answer.

  • Time-to-first-spike (TTFS) latency coding encodes larger input intensities into earlier arrival times, allowing each neuron to emit at most one single spike per stimulus. In a simple linear mapping over a window \(T\), firing time is \(t_{\text{spike}}(x) = T(1 - x)\). In a physically grounded LIF encoder driven by constant input \(x > \theta\), solving the leaky charging equation yields a smooth logarithmic latency curve.

\[t_{\text{spike}}(x) = \tau_m \ln\!\left(\frac{x}{x - \theta}\right) \quad \text{for } x > \theta\]
  • Inputs below threshold stay completely silent forever. Because every active neuron fires once at most, latency coding slashes total spike counts by an order of magnitude compared to rate coding.

Delta Modulation

  • Think of a thermostat monitor or a stock ticker that only sends a text message to your phone when the temperature rises or drops by at least one degree. Delta modulation skips redundant static values altogether. Keeping an internal reference level \(\hat{x}\), the encoder tracks the running change \(x[t] - \hat{x}\) and emits a positive ON spike (\(+1\)) whenever the signal climbs by a threshold \(\vartheta\), or a negative OFF spike (\(-1\)) whenever it drops by \(\vartheta\), resetting \(\hat{x}\) to the new level each time.

  • When the input stays flat, delta modulation emits pure silence. This is the exact physical mechanism implemented inside every pixel of a Dynamic Vision Sensor (event camera), which streams microsecond brightness changes with zero motion blur and negligible background bandwidth.

Why Temporal Coding Enables Sub-Millisecond Decisions

  • Put yourself behind the wheel of a car when a football bounces unexpectedly onto the road. Your visual cortex does not sit around waiting 500 milliseconds to count Poisson firing rates across eight cortical stages. Behavioural experiments by Simon Thorpe showed that humans can detect whether a flashed scene contains an animal in under 150 milliseconds, leaving roughly 10 to 15 milliseconds per cortical layer, barely enough time for each neuron to fire one single spike.

  • Temporal coding unlocks that exact ultra-low-latency regime in neuromorphic silicon. When the first wave of earliest spikes leaves layer 1 (carrying the strongest visual edges or acoustic onsets), layer 2 immediately begins integrating them without waiting for weak, late neurons to finish. As soon as the winning output neuron in the final layer crosses threshold and fires its very first spike, the chip can declare its classification decision and halt the rest of the wave.

  • In high-speed robotics, drone obstacle avoidance, and radar gesture recognition, this first-spike racing effect turns latency from tens of milliseconds down into the sub-millisecond range, using a tiny fraction of the spikes and energy required by frame-based or rate-coded networks.

Take-Home

  • A discrete-time LIF neuron is a minimal recurrent state-space cell whose hidden state is membrane voltage \(U[t] = \beta U[t-1] + W X[t] - S[t-1]\theta\), pairing leaky exponential memory with a sharp binary spike output \(S[t] = \Theta(U[t] - \theta)\).
  • Reset-by-subtraction outperforms reset-to-zero in most discrete SNNs because carrying over residual voltage \(U[t] - \theta\) avoids throwing away excess input signal above threshold.
  • Richer single-neuron dynamics expand temporal power, with ALIF adaptation providing long-horizon working memory, resonant neurons filtering specific frequencies, Izhikevich models capturing bursting patterns, and learnable delays aligning spike coincidence.
  • Input encoding sets the energy-latency bargain, trading rate coding's noise robustness against latency coding's single-spike efficiency and delta modulation's change-only compression.
  • Time-to-first-spike waves allow sub-millisecond decisions, letting downstream layers classify stimuli from the earliest arriving spikes without waiting to count long spike trains.

Coding Tasks (use CoLab or notebook)

  1. Simulate discrete-time LIF neurons under both reset-by-subtraction and reset-to-zero across a sweep of constant input currents. Visualise the membrane trajectories and compare how faithfully each reset rule's firing rate tracks the ideal linear input current above threshold.

    import jax
    import jax.numpy as jnp
    import matplotlib.pyplot as plt
    
    def run_lif_reset_mode(I_seq, beta=0.85, theta=1.0, mode="subtract"):
        """Simulate a discrete-time LIF neuron with soft (subtract) or hard (zero) reset."""
        u = 0.0
        u_hist, s_hist = [], []
        for x in I_seq:
            u = beta * u + float(x)
            s = 1.0 if u >= theta else 0.0
            u_hist.append(u)
            s_hist.append(s)
            if s > 0.0:
                if mode == "subtract":
                    u = u - theta
                else:
                    u = 0.0
        return jnp.array(u_hist), jnp.array(s_hist)
    
    # 1. Trace comparison at strong input where overshoot matters
    T = 40
    I_strong = jnp.full((T,), 0.65)
    u_sub, s_sub = run_lif_reset_mode(I_strong, beta=0.9, theta=1.0, mode="subtract")
    u_zero, s_zero = run_lif_reset_mode(I_strong, beta=0.9, theta=1.0, mode="zero")
    print(f"Spikes over {T} steps (I=0.65) -> Subtract: {int(jnp.sum(s_sub))}, Zero-reset: {int(jnp.sum(s_zero))}")
    
    # 2. Firing-rate fidelity sweep across input currents (no leak beta=1.0 shows exact quantisation)
    currents = jnp.linspace(0.0, 1.8, 30)
    rate_sub, rate_zero = [], []
    for amp in currents:
        seq = jnp.full((120,), amp)
        _, spk_s = run_lif_reset_mode(seq, beta=1.0, theta=1.0, mode="subtract")
        _, spk_z = run_lif_reset_mode(seq, beta=1.0, theta=1.0, mode="zero")
        rate_sub.append(float(jnp.mean(spk_s)))
        rate_zero.append(float(jnp.mean(spk_z)))
    
    fig, axes = plt.subplots(1, 2, figsize=(11, 4))
    axes[0].plot(u_sub, color="#27ae60", lw=2, label="Reset-by-Subtraction")
    axes[0].plot(u_zero, color="#e74c3c", lw=1.8, ls="--", label="Reset-to-Zero")
    axes[0].axhline(1.0, color="#333333", ls=":", label="Threshold theta=1.0")
    axes[0].set_xlabel("Time Step t")
    axes[0].set_ylabel("Membrane Potential U[t]")
    axes[0].set_title("Subtractive Reset Preserves Overshoot Charge")
    axes[0].legend()
    axes[0].grid(alpha=0.3)
    
    axes[1].plot(currents, jnp.clip(currents, 0.0, 1.0), color="#333333", ls=":", lw=1.5, label="Ideal Rate = min(I, 1)")
    axes[1].plot(currents, rate_sub, "o-", color="#27ae60", ms=4, lw=2, label="Reset-by-Subtraction")
    axes[1].plot(currents, rate_zero, "s--", color="#e74c3c", ms=4, lw=1.8, label="Reset-to-Zero")
    axes[1].set_xlabel("Constant Input Current I")
    axes[1].set_ylabel("Mean Firing Rate (spikes / step)")
    axes[1].set_title("Reset-to-Zero Introduces Staircase Distortion")
    axes[1].legend()
    axes[1].grid(alpha=0.3)
    plt.tight_layout()
    plt.show()
    

  2. Compare Adaptive LIF (ALIF) firing-rate adaptation with Izhikevich bursting dynamics under a sustained input pulse, plotting both membrane traces and the evolving adaptive threshold \(\theta[t]\).

    import jax
    import jax.numpy as jnp
    import matplotlib.pyplot as plt
    
    # Part A: Adaptive LIF (ALIF) neuron with slow threshold adaptation
    T_alif = 120
    I_pulse = jnp.where((jnp.arange(T_alif) >= 15) & (jnp.arange(T_alif) <= 95), 0.35, 0.0)
    
    u, a = 0.0, 0.0
    beta, rho = 0.85, 0.96
    theta0, b_adapt = 1.0, 0.45
    u_alif, th_alif, spk_alif = [], [], []
    
    for x in I_pulse:
        theta_t = theta0 + b_adapt * a
        u = beta * u + float(x)
        s = 1.0 if u >= theta_t else 0.0
        u_alif.append(u)
        th_alif.append(theta_t)
        spk_alif.append(s)
        u = u - s * theta_t
        a = rho * a + s
    
    # Part B: Izhikevich Intrinsically Bursting (IB) neuron (a=0.02, b=0.2, c=-55, d=4)
    dt = 0.5
    T_izh = 300
    v, u_rec = -65.0, -65.0 * 0.2
    a_iz, b_iz, c_iz, d_iz = 0.02, 0.2, -55.0, 4.0
    v_izh = []
    
    for step in range(T_izh):
        I_in = 10.0 if 40 <= step <= 260 else 0.0
        dv = (0.04 * v * v + 5.0 * v + 140.0 - u_rec + I_in) * dt
        du = a_iz * (b_iz * v - u_rec) * dt
        v = v + dv
        u_rec = u_rec + du
        if v >= 30.0:
            v_izh.append(30.0)
            v = c_iz
            u_rec = u_rec + d_iz
        else:
            v_izh.append(v)
    
    print(f"ALIF total spikes: {int(sum(spk_alif))} | Peak adapted threshold: {max(th_alif):.2f}")
    print(f"Izhikevich IB spikes: {sum(1 for val in v_izh if val >= 29.9)}")
    
    fig, axes = plt.subplots(1, 2, figsize=(11, 4))
    axes[0].plot(u_alif, color="#3498db", lw=1.6, label="Membrane U[t]")
    axes[0].plot(th_alif, color="#e74c3c", lw=2, ls="--", label="Adaptive Threshold theta[t]")
    axes[0].set_xlabel("Time Step t")
    axes[0].set_ylabel("Potential / Threshold")
    axes[0].set_title("ALIF Slow Adaptation Memory (Early Burst then Slowing)")
    axes[0].legend()
    axes[0].grid(alpha=0.3)
    
    t_ms = jnp.arange(T_izh) * dt
    axes[1].plot(t_ms, v_izh, color="#9b59b6", lw=1.6)
    axes[1].set_xlabel("Time (ms)")
    axes[1].set_ylabel("Voltage v (mV)")
    axes[1].set_title("Izhikevich Intrinsically Bursting Pattern")
    axes[1].grid(alpha=0.3)
    plt.tight_layout()
    plt.show()
    

  3. Compare Rate Coding, Time-to-First-Spike (TTFS) Latency Coding, and Delta Modulation on an 8-channel sensory pattern, measuring total spike count and how quickly a downstream winner-take-all decoder identifies the strongest channel.

    import jax
    import jax.numpy as jnp
    import matplotlib.pyplot as plt
    
    # 8-channel input intensities (channel 5 is the strongest stimulus at 0.92)
    intensities = jnp.array([0.15, 0.35, 0.62, 0.28, 0.74, 0.92, 0.48, 0.20])
    T = 40
    key = jax.random.PRNGKey(21)
    
    # 1. Rate Coding (Bernoulli spikes at every time step)
    rand_u = jax.random.uniform(key, (T, len(intensities)))
    rate_spikes = (rand_u < intensities[None, :]).astype(jnp.float32)
    
    # Find earliest step where cumulative rate count stays locked on true winner (ch 5)
    cum_counts = jnp.cumsum(rate_spikes, axis=0)
    rate_preds = jnp.argmax(cum_counts, axis=1)
    rate_stable_t = T
    for t in range(T):
        if bool(jnp.all(rate_preds[t:] == 5)):
            rate_stable_t = t + 1
            break
    
    # 2. Time-to-First-Spike Latency Coding (t_spike = round((1 - x) * (T - 1)))
    lat_times = jnp.round((1.0 - intensities) * (T - 1)).astype(jnp.int32)
    lat_spikes_rows = []
    for t in range(T):
        lat_spikes_rows.append((lat_times == t).astype(jnp.float32))
    lat_spikes = jnp.stack(lat_spikes_rows, axis=0)
    ttfs_decision_t = int(jnp.min(lat_times)) + 1
    ttfs_winner = int(jnp.argmin(lat_times))
    
    # 3. Delta Modulation on a smooth time-varying version of channel 5
    t_axis = jnp.linspace(0.0, 2.0 * jnp.pi, T)
    wave = 0.5 + 0.45 * jnp.sin(t_axis)
    ref, thresh = float(wave[0]), 0.14
    delta_events = []
    for val in wave:
        diff = float(val) - ref
        if diff >= thresh:
            delta_events.append(1.0)
            ref = float(val)
        elif diff <= -thresh:
            delta_events.append(-1.0)
            ref = float(val)
        else:
            delta_events.append(0.0)
    delta_events = jnp.array(delta_events)
    
    print(f"Rate coding   -> Total spikes: {int(jnp.sum(rate_spikes)):3d} | Stable decision step: t = {rate_stable_t}")
    print(f"Latency (TTFS)-> Total spikes: {int(jnp.sum(lat_spikes)):3d} | First-spike winner: ch {ttfs_winner} at t = {ttfs_decision_t}")
    print(f"Delta coding  -> Non-zero ON/OFF events on sine wave: {int(jnp.sum(jnp.abs(delta_events)))} / {T} steps")
    
    fig, axes = plt.subplots(1, 3, figsize=(13, 3.8))
    t_r, ch_r = jnp.where(rate_spikes > 0.5)
    axes[0].scatter(t_r, ch_r, s=22, color="#3498db")
    axes[0].axvline(rate_stable_t, color="#e74c3c", ls="--", label=f"Stable t={rate_stable_t}")
    axes[0].set_xlabel("Time Step t"); axes[0].set_ylabel("Channel")
    axes[0].set_title(f"Rate Coding ({int(jnp.sum(rate_spikes))} spikes)")
    axes[0].legend(fontsize=8)
    
    t_l, ch_l = jnp.where(lat_spikes > 0.5)
    axes[1].scatter(t_l, ch_l, s=45, color="#27ae60")
    axes[1].axvline(ttfs_decision_t - 1, color="#e74c3c", ls="--", label=f"1st Spike t={ttfs_decision_t}")
    axes[1].set_xlim(0, T); axes[1].set_xlabel("Time Step t")
    axes[1].set_title(f"Latency TTFS ({int(jnp.sum(lat_spikes))} spikes)")
    axes[1].legend(fontsize=8)
    
    axes[2].plot(wave, color="#f39c12", lw=2, label="Signal x(t)")
    on_t = jnp.where(delta_events > 0)[0]
    off_t = jnp.where(delta_events < 0)[0]
    axes[2].vlines(on_t, 0.0, 0.25, color="#27ae60", lw=2, label="ON (+1)")
    axes[2].vlines(off_t, -0.25, 0.0, color="#e74c3c", lw=2, label="OFF (-1)")
    axes[2].set_xlabel("Time Step t")
    axes[2].set_title("Delta Modulation (ON/OFF Events)")
    axes[2].legend(fontsize=8)
    plt.tight_layout()
    plt.show()