Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FirFilter : IFilter
- {
- private double[] _coefficients;
- private double[] _queue;
- private int _index;
- public FirFilter()
- {
- _coefficients = new[]
- {
- 0, 0.0000717, 0.0001444, 0.0002168, 0.0002873, 0.0003538, 0.0004134, 0.0004627,
- 0.0004977, 0.0005138, 0.0005067, 0.0004718, 0.0004056, 0.0003052, 0.0001698, 0,
- -0.0002009, -0.000427, -0.0006702, -0.0009192, -0.0011609, -0.0013801, -0.0015604,
- -0.001685, -0.001738, -0.0017049, -0.0015742, -0.0013381, -0.000994, -0.0005449, 0,
- 0.0006246, 0.0013064, 0.0020166, 0.0027211, 0.0033818, 0.0039577, 0.0044075, 0.004691,
- 0.0047721, 0.0046204, 0.0042141, 0.0035416, 0.0026033, 0.0014134, 0, -0.0015943,
- -0.003313, -0.0050866, -0.0068351, -0.0084696, -0.0098961, -0.0110186, -0.0117432,
- -0.0119819, -0.0116567, -0.0107036, -0.0090761, -0.0067478, -0.0037156, 0, 0.0043531,
- 0.0092736, 0.0146682, 0.0204226, 0.0264051, 0.0324702, 0.0384635, 0.0442269, 0.0496037,
- 0.0544445, 0.0586122, 0.061987, 0.0644708, 0.065991, 0.0665028, 0.065991, 0.0644708,
- 0.061987, 0.0586122, 0.0544445, 0.0496037, 0.0442269, 0.0384635, 0.0324702, 0.0264051,
- 0.0204226, 0.0146682, 0.0092736, 0.0043531, 0, -0.0037156, -0.0067478, -0.0090761,
- -0.0107036, -0.0116567, -0.0119819, -0.0117432, -0.0110186, -0.0098961, -0.0084696,
- -0.0068351, -0.0050866, -0.003313, -0.0015943, 0, 0.0014134, 0.0026033, 0.0035416,
- 0.0042141, 0.0046204, 0.0047721, 0.004691, 0.0044075, 0.0039577, 0.0033818, 0.0027211,
- 0.0020166, 0.0013064, 0.0006246, 0, -0.0005449, -0.000994, -0.0013381, -0.0015742,
- -0.0017049, -0.001738, -0.001685, -0.0015604, -0.0013801, -0.0011609, -0.0009192,
- -0.0006702, -0.000427, -0.0002009, 0, 0.0001698, 0.0003052, 0.0004056, 0.0004718,
- 0.0005067, 0.0005138, 0.0004977, 0.0004627, 0.0004134, 0.0003538, 0.0002873, 0.0002168,
- 0.0001444, 0.0000717, 0
- };
- _queue = new double[_coefficients.Length];
- }
- public unsafe double Process(double sample)
- {
- int n = _coefficients.Length;
- double result = 0.0;
- fixed (double* coefficients = _coefficients, queue = _queue)
- {
- if (--_index < 0)
- _index = n - 1;
- queue[_index] = sample;
- for (int i = 0; i < n; i++)
- {
- result += queue[_index] * coefficients[i];
- if (++_index >= n)
- _index = 0;
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement