Skip to content

Title: Gate EMA accumulator on data_ena for multiplexed-stream use cases#1

Open
Abraxas3d wants to merge 1 commit into
mainfrom
fix/data-ena-gate
Open

Title: Gate EMA accumulator on data_ena for multiplexed-stream use cases#1
Abraxas3d wants to merge 1 commit into
mainfrom
fix/data-ena-gate

Conversation

@Abraxas3d
Copy link
Copy Markdown
Member

Summary

Adds a data_ena = '1' gate around the EMA accumulator update inside lowpass_ema. data_ena now selects which clocks the EMA integrates, rather than only riding through as a passsthrough strobe to average_ena.

Motivation

lowpass_ema previously updated all internal state every clock and forwarded data_ena unchanged to average_ena. This is correct for streaming inputs (data valid every clock, data_ena tied high), but incorrect for any use case where data_ena selects which clocks have valid samples (like Haifuraiya).

We discovered this while building a 64-channel polyphase-channelizer power monitor for Haifuraiya. The wrapper instantiates 64 power_detector blocks sharing a single multiplexed I/Q data bus; each instance's data_ena selects which clocks correspond to its assigned channel. Without the data_ena gate, all 64 power_detector instances accumulated the same shared data stream and reported identical averages, regardless of which channel each one was supposed to monitor. Took a while to figure this out!

Change

Wraps the existing accumulator assignments in if data_ena = '1' then ... end if; inside the else (non-reset) branch of the clocked process. average_ena <= data_ena; remains outside the gate so output validity is reported faithfully regardless of accumulator update.

Backward compatibility

For streaming inputs with data_ena tied high, behavior is unchanged: the gate is always satisfied and every clock updates as before.

For users who tied data_ena permanently low, the EMA now holds state instead of overwriting with the input alpha/data. We believe this is the correct behavior (no data, no update) and are not aware of any user relying on the previous behavior. pluto_msk does not.

Testing

Verified in the Haifuraiya AXI wrapper testbench:

  • DC input (20000 + 0j) -> peak channel 0, with symmetric skirt
    decaying through channels 63, 1, 2, 62, 3, 61, ... and deep
    stopband in channels 17-46. Pre-fix: all 64 channels read
    identical EMA values.
  • Tone at FFT bin 16 -> peak channel 16, with symmetric skirt
    around bin 16. Pre-fix: all 64 channels read identical EMA
    values.

Addendum!

Independently caught during the same session: the README port table states power_squared width is 2*DATA_W - 2 but the actual range declaration (2*DATA_W - 2 downto 0) is 2*DATA_W - 1 bits wide.

Previously, all internal state (alpha_signed, alpha_m, data_signed,
mult_data, mult_sum, average) updated unconditionally each clock,
treating data_ena only as a passthrough strobe to average_ena.
This is correct for streaming inputs where every clock has valid
data, but incorrect for multiplexed inputs where data_ena selects
which clocks to integrate.

This change wraps the EMA math in 'if data_ena = 1' so that the
accumulator only advances on valid samples. average_ena remains
outside the gate to faithfully mark output validity.

Backward compatibility: for streaming inputs with data_ena tied
high, behavior is unchanged.
@Abraxas3d Abraxas3d requested a review from mwishek May 16, 2026 04:23
@Abraxas3d Abraxas3d added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant