prog

Untitled

Jul 28th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. public class FirFilter : IFilter
  2. {
  3. private readonly double[] _coefficients;
  4. private readonly double[] _queue;
  5. private int _index;
  6.  
  7. public FirFilter()
  8. {
  9. _coefficients = new[]
  10. {
  11. -0.0000133,-0.0000429,-0.0000689,-0.000089,-0.0001015,-0.000105,-0.0000991,-0.0000842,-0.0000614,-0.0000325,0,0.0000334,0.0000646,0.0000909,0.0001097,0.0001192,0.0001182,0.0001063,0.0000843,0.0000537,0.0000171,-0.0000226,-0.0000618,-0.000097,-0.0001248,-0.0001423,-0.0001475,-0.0001394,-0.000118,-0.0000848,-0.0000421,0.0000065,0.0000569,0.0001045,0.0001448,0.0001736,0.0001879,0.0001854,0.0001656,0.0001295,0.0000795,0.0000195,-0.0000454,-0.0001094,-0.0001666,-0.0002113,-0.0002386,-0.0002452,-0.0002294,-0.0001914,-0.0001337,-0.0000605,0.0000221,0.0001068,0.000186,0.000252,0.000298,0.0003186,0.0003106,0.0002734,0.0002089,0.0001217,0.0000189,-0.0000909,-0.0001977,-0.0002914,-0.0003627,-0.0004038,-0.0004095,-0.0003774,-0.0003088,-0.0002082,-0.0000834,0.0000551,0.000195,0.0003236,0.0004282,0.000498,0.0005249,0.0005045,0.0004363,0.0003246,0.0001777,0.0000077,-0.0001708,-0.0003415,-0.0004883,-0.0005964,-0.0006542,-0.000654,-0.0005933,-0.0004751,-0.0003078,-0.0001048,0.0001167,0.0003369,0.0005354,0.0006929,0.0007931,0.0008242,0.0007805,0.000663,0.0004793,0.0002438,-0.000024,-0.0003005,-0.0005606,-0.0007796,-0.0009356,-0.0010116,-0.0009973,-0.0008905,-0.0006973,-0.0004322,-0.0001167,0.000222,0.0005536,0.0008472,0.0010741,0.001211,0.0012416,0.0011591,0.0009666,0.0006776,0.0003153,-0.00009,-0.0005024,-0.0008843,-0.0011992,-0.0014157,-0.00151,-0.001469,-0.0012912,-0.0009879,-0.0005825,-0.0001083,0.0003936,0.0008779,0.0012994,0.001617,0.0017977,0.0018198,0.0016753,0.0013714,0.0009303,0.0003873,-0.0002113,-0.0008125,-0.0013611,-0.0018047,-0.0020988,-0.0022107,-0.0021235,-0.0018379,-0.0013729,-0.0007645,-0.0000634,0.0006694,0.0013677,0.0019662,0.0024061,0.0026411,0.0026421,0.0024003,0.0019288,0.0012623,0.0004548,-0.0004249,-0.0012988,-0.0020863,-0.0027119,-0.003112,-0.0032412,-0.0030774,-0.0026242,-0.0019121,-0.0009964,0.0000468,0.0011268,0.0021458,0.0030079,0.0036278,0.0039388,0.0038999,0.0035004,0.0027622,0.001739,0.000513,-0.000812,-0.0021185,-0.0032858,-0.0042009,-0.0047688,-0.0049221,-0.0046284,-0.0038945,-0.0027679,-0.0013339,0.0002902,0.0019644,0.0035374,0.0048601,0.0057988,0.0062485,0.0061431,0.0054639,0.0042435,0.002565,0.0005578,-0.0016122,-0.003755,-0.0056727,-0.0071763,-0.0081036,-0.0083346,-0.0078048,-0.0065146,-0.0045324,-0.0019936,0.0009078,0.0039319,0.0068112,0.0092717,0.0110565,0.0119487,0.0117932,0.0105142,0.008128,0.0047486,0.000586,-0.0040624,-0.008829,-0.0132983,-0.0170351,-0.0196152,-0.0206572,-0.0198526,-0.0169924,-0.0119877,-0.0048823,0.0041425,0.0147735,0.0265799,0.0390363,0.051553,0.0635106,0.0742987,0.0833534,0.0901938,0.0944521,0.0958977,0.0944521,0.0901938,0.0833534,0.0742987,0.0635106,0.051553,0.0390363,0.0265799,0.0147735,0.0041425,-0.0048823,-0.0119877,-0.0169924,-0.0198526,-0.0206572,-0.0196152,-0.0170351,-0.0132983,-0.008829,-0.0040624,0.000586,0.0047486,0.008128,0.0105142,0.0117932,0.0119487,0.0110565,0.0092717,0.0068112,0.0039319,0.0009078,-0.0019936,-0.0045324,-0.0065146,-0.0078048,-0.0083346,-0.0081036,-0.0071763,-0.0056727,-0.003755,-0.0016122,0.0005578,0.002565,0.0042435,0.0054639,0.0061431,0.0062485,0.0057988,0.0048601,0.0035374,0.0019644,0.0002902,-0.0013339,-0.0027679,-0.0038945,-0.0046284,-0.0049221,-0.0047688,-0.0042009,-0.0032858,-0.0021185,-0.000812,0.000513,0.001739,0.0027622,0.0035004,0.0038999,0.0039388,0.0036278,0.0030079,0.0021458,0.0011268,0.0000468,-0.0009964,-0.0019121,-0.0026242,-0.0030774,-0.0032412,-0.003112,-0.0027119,-0.0020863,-0.0012988,-0.0004249,0.0004548,0.0012623,0.0019288,0.0024003,0.0026421,0.0026411,0.0024061,0.0019662,0.0013677,0.0006694,-0.0000634,-0.0007645,-0.0013729,-0.0018379,-0.0021235,-0.0022107,-0.0020988,-0.0018047,-0.0013611,-0.0008125,-0.0002113,0.0003873,0.0009303,0.0013714,0.0016753,0.0018198,0.0017977,0.001617,0.0012994,0.0008779,0.0003936,-0.0001083,-0.0005825,-0.0009879,-0.0012912,-0.001469,-0.00151,-0.0014157,-0.0011992,-0.0008843,-0.0005024,-0.00009,0.0003153,0.0006776,0.0009666,0.0011591,0.0012416,0.001211,0.0010741,0.0008472,0.0005536,0.000222,-0.0001167,-0.0004322,-0.0006973,-0.0008905,-0.0009973,-0.0010116,-0.0009356,-0.0007796,-0.0005606,-0.0003005,-0.000024,0.0002438,0.0004793,0.000663,0.0007805,0.0008242,0.0007931,0.0006929,0.0005354,0.0003369,0.0001167,-0.0001048,-0.0003078,-0.0004751,-0.0005933,-0.000654,-0.0006542,-0.0005964,-0.0004883,-0.0003415,-0.0001708,0.0000077,0.0001777,0.0003246,0.0004363,0.0005045,0.0005249,0.000498,0.0004282,0.0003236,0.000195,0.0000551,-0.0000834,-0.0002082,-0.0003088,-0.0003774,-0.0004095,-0.0004038,-0.0003627,-0.0002914,-0.0001977,-0.0000909,0.0000189,0.0001217,0.0002089,0.0002734,0.0003106,0.0003186,0.000298,0.000252,0.000186,0.0001068,0.0000221,-0.0000605,-0.0001337,-0.0001914,-0.0002294,-0.0002452,-0.0002386,-0.0002113,-0.0001666,-0.0001094,-0.0000454,0.0000195,0.0000795,0.0001295,0.0001656,0.0001854,0.0001879,0.0001736,0.0001448,0.0001045,0.0000569,0.0000065,-0.0000421,-0.0000848,-0.000118,-0.0001394,-0.0001475,-0.0001423,-0.0001248,-0.000097,-0.0000618,-0.0000226,0.0000171,0.0000537,0.0000843,0.0001063,0.0001182,0.0001192,0.0001097,0.0000909,0.0000646,0.0000334,0,-0.0000325,-0.0000614,-0.0000842,-0.0000991,-0.000105,-0.0001015,-0.000089,-0.0000689,-0.0000429,-0.0000133
  12. };
  13. _queue = new double[_coefficients.Length];
  14. }
  15.  
  16. public unsafe double Process(double sample)
  17. {
  18. int n = _coefficients.Length;
  19. double result = 0.0;
  20. fixed (double* coefficients = _coefficients, queue = _queue)
  21. {
  22. if (--_index < 0)
  23. _index = n - 1;
  24. queue[_index] = sample;
  25. for (int i = 0; i < n; i++)
  26. {
  27. result += queue[_index] * coefficients[i];
  28. if (++_index >= n)
  29. _index = 0;
  30. }
  31. }
  32. return result;
  33. }
  34. }
Add Comment
Please, Sign In to add comment