Keywords: #filter #lowpass #averaging
This repository contains a VHDL implementation of an Exponential Moving Average (EMA). The EMA is a simple recursive filter commonly used for smoothing input data and identifying trends. It weights recent data points more heavily than older ones, controlled by a smoothing factor.
- Computes the EMA using the formula: [ \text{EMA}(n) = \alpha \cdot x(n) + (1 - \alpha) \cdot \text{EMA}(n-1) ]
- Fixed-point arithmetic with customizable data width and smoothing factor precision.
- Synchronous operation with clock and reset signals.
Name | Direction | Width | Description |
---|---|---|---|
clk |
Input | 1 bit | Clock signal. |
init |
Input | 1 bit | Synchronous reset signal. |
data |
Input | DATA_WIDTH bits |
Input data to the EMA filter (signed). |
average |
Output | DATA_WIDTH bits |
Filtered EMA output (signed). |
Name | Type | Default | Description |
---|---|---|---|
DATA_WIDTH |
Integer | 16 |
Width of input and output data in bits. |
ALPHA_BITS |
Integer | 8 |
Bit width for the smoothing factor (alpha ). |
The design computes the EMA in the following steps:
- Parameterization: The smoothing factor (
alpha
) is defined in fixed-point representation.- Example: For 8-bit
ALPHA_BITS
,alpha = 128
corresponds to ( \alpha = 0.5 ).
- Example: For 8-bit
- Recursive Calculation: Uses the EMA formula with fixed-point arithmetic.
- Output Update: The result is updated synchronously on each clock cycle.
- Customization: Adjust the generics
DATA_WIDTH
andALPHA_BITS
in theExponentialAverage
entity to fit your design requirements. - Integration: Instantiate the entity in your top-level design, connect the ports, and configure the input data and clock/reset signals.
ExponentialAverage_inst : entity work.ExponentialAverage
generic map (
DATA_WIDTH => 16,
ALPHA_BITS => 8
)
port map (
clk => clk,
init => init,
data => data,
average => average
);
- Simulation: Use a VHDL simulation tool (e.g., ModelSim, GHDL) to verify the functionality. Provide a time-varying input signal to observe the smoothed EMA output.
Applications
• Data smoothing (e.g., temperature sensors, financial data).
• Noise reduction in signals.
• Real-time control systems.
This README.md created with the assistance of Claude.ai