I have designed using MATLAB a FIR filter with some coefficients.

I have an array that is normalized to -+1. The array is float.

I used this method to apply the FIR to the array but I'm not sure if this is fine:

public static float[] FirFilter(float[] b, float[] x)
        int M = b.Length;// b == coffecients of FIR
        int n = x.Length;// x == mySignalSamples
        var y = new float[n];
        for (int yi = 0; yi < n; yi++)
            float t = 0.0f;
            for (int bi = M - 1; bi >= 0; bi--)
                if (yi - bi < 0) continue;

                t += b[bi] * x[yi - bi];
            y[yi] = t;
        //return Convert.ToDouble(y);
        return y;

Am I doing that right?

  • 1
    $\begingroup$ Questions about getting a specific piece of code to work are off-topic for this site. At a glance it looks reasonable. You should put in a known signal and see if you get what you expect at the output. $\endgroup$ – Jason R May 27 '15 at 19:52
  • $\begingroup$ My problem is that after applying this and specograming it back in matlab I get a big reduction in magnitude. For example: from 0 db to -40db in my specific frequency which I want to pass $\endgroup$ – axcelenator May 27 '15 at 20:03
  • 3
    $\begingroup$ Why don't you use Matlab to filter your signal, so you have a reference as to what you should get? $\endgroup$ – Matt L. May 27 '15 at 20:10
  • $\begingroup$ I use it, but the the plots I get are deferent so I assume something wrong in my code $\endgroup$ – axcelenator May 28 '15 at 7:01