07-21-2015 05:24 AM
Hey guys,
I am looking for an example of an exponentially weighted moving average filter for FPGA.
I know the DFD kit, but you can't change the coefficients on the run of the FPGA code. Therefor I want to build it on my own or use an already existing example.
If anyone has one or any advices, please let me know.
Kind regards
Slev1n
07-21-2015 08:12 AM
According to wikipedia:
https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
You can calculate the exponential moving average as follows.
S[t] = a*Y[t] + (1-a)S[t-1]
This can be done with simple maths and a feedback node on an FPGA (I haven't bothered to sort out the FXP word lengths in the snippet below).
07-22-2015 07:07 AM
I think your formula is not completly correct.
I build my own but as my input is a 64Bit integer coming from a CIC filter I had to use SGL in the end.
How would you change the Integer into FXP?
kind regards
Slev1n
07-22-2015 08:38 AM
Ok, here is my FIX point version of an EWMA. Input 32bit output 32bit. If the stage is 2 the data is running thorugh the filter 2 times and therefor you double your attenuation.
Can someone of you approximate the error I am creating?
(The input is a 64bit integer which can be presented with 32Bits, you can check the explanaition to it)
kind regards
Slev1n
07-31-2015 04:20 AM
Ok,
I want to simulate the frequency response of this filter.
from y[n] = alpha *x[n] + (1-alpha)*y[n-1] I come to H(w)=alpha+(1-alpha)*e^(-jw) but now I dont know how to get rid of the complex part to get a non complex function of the amplitude of the frequency response like this one: |H(w)| = [sin(w*M/2)/M*sin(w/2)] (moving average).
Can you guys give me a hint?
Slev1n
08-05-2015 06:50 AM - edited 08-05-2015 06:52 AM
I just derived the frequency response of the EWMA:
|H(w)|= alpha / sqrt(1²-2*1*(1-alpha)*cos(w/fs)+(1-alpha)²)
I plotted it with MATLAB for alpha=0.5:
You can find my fix point version attached to this file. I have problems with the stability. The result sometimes jumps between two values...
Can someone find the mistake? I think it has something to do with the conversions...
kind regards
Slev1n
08-05-2015 09:19 AM
Hi Slev1n,
It would be easier to debug this with a testbench that provides a data set to reproduce the jumps you're seeing. Here's a few suggestions:
Hope this helps,
Jim
08-06-2015 06:10 AM
Hey Jim,
Q1 and Q2: I have this shift register, because later on I want to be able to multiple pass the input signal through the filter. That is how it will look like:
Therefor i want to scale the output to I36.1 again to have the same fxp type.
Q3: Ok i will change it the output of the subtraction to U25.1
Q4: You are right, I will try to make the code easier. I will built a testbench, were I fed the filter with a noisy DC signal.
I will post my updates.
@JLewis: I think you can still help me with my cic 🙂
Kind regards
Slev1n
08-11-2015 05:14 AM
So the actual error was beyond the filter at a bit shift...
I have now a working version, which can be implemented as a multipass as well. Can someone have a look at the pipeline logic?
kind regards
Slev1n
08-11-2015 09:59 AM
Hi Slev1n,
Have you tested theses results against the original version? It looks like there may be some timing issues that would change the behavior. Here's a few suggestions:
Hope that helps,
Jim