# Applying a FIR filter to floating point array c# [closed]

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
//y[n]=b0x[n]+b1x[n-1]+....bmx[n-M]
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?

• 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. – Jason R May 27 '15 at 19:52
• 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 – axcelenator May 27 '15 at 20:03
• Why don't you use Matlab to filter your signal, so you have a reference as to what you should get? – Matt L. May 27 '15 at 20:10
• I use it, but the the plots I get are deferent so I assume something wrong in my code – axcelenator May 28 '15 at 7:01