FIRF64.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "FIRF64.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 310
  5. /*
  6. Reference patterns are generated with
  7. a double precision computation.
  8. */
  9. #define REL_ERROR (2.0e-14)
  10. static void checkInnerTail(float64_t *b)
  11. {
  12. ASSERT_TRUE(b[0] == 0.0);
  13. ASSERT_TRUE(b[1] == 0.0);
  14. }
  15. // Coef must be padded to a multiple of 4
  16. #define FIRCOEFPADDING 2
  17. void FIRF64::test_fir_f64()
  18. {
  19. const int16_t *configp = configs.ptr();
  20. float64_t *statep = state.ptr();
  21. const float64_t *orgcoefsp = coefs.ptr();
  22. const float64_t *coefsp;
  23. const float64_t *inputp = inputs.ptr();
  24. float64_t *outp = output.ptr();
  25. unsigned long i;
  26. int blockSize;
  27. int numTaps;
  28. /*
  29. Python script is generating different tests with
  30. different blockSize and numTaps.
  31. We loop on those configs.
  32. */
  33. for(i=0; i < configs.nbSamples() ; i += 2)
  34. {
  35. blockSize = configp[0];
  36. numTaps = configp[1];
  37. coefsp = orgcoefsp;
  38. /*
  39. The filter is initialized with the coefs, blockSize and numTaps.
  40. */
  41. arm_fir_init_f64(&this->S,numTaps,coefsp,statep,blockSize);
  42. /*
  43. Input pointer is reset since the same input pattern is used
  44. */
  45. inputp = inputs.ptr();
  46. /*
  47. Python script is filtering a 2*blockSize number of samples.
  48. We do the same filtering in two pass to check (indirectly that
  49. the state management of the fir is working.)
  50. */
  51. arm_fir_f64(&this->S,inputp,outp,blockSize);
  52. outp += blockSize;
  53. checkInnerTail(outp);
  54. inputp += blockSize;
  55. arm_fir_f64(&this->S,inputp,outp,blockSize);
  56. outp += blockSize;
  57. checkInnerTail(outp);
  58. configp += 2;
  59. orgcoefsp += numTaps;
  60. }
  61. ASSERT_EMPTY_TAIL(output);
  62. ASSERT_SNR(output,ref,(float64_t)SNR_THRESHOLD);
  63. ASSERT_REL_ERROR(output,ref,REL_ERROR);
  64. }
  65. void FIRF64::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  66. {
  67. (void)params;
  68. switch(id)
  69. {
  70. case FIRF64::TEST_FIR_F64_1:
  71. break;
  72. }
  73. inputs.reload(FIRF64::FIRINPUTS_F64_ID,mgr);
  74. coefs.reload(FIRF64::FIRCOEFS_F64_ID,mgr);
  75. configs.reload(FIRF64::FIRCONFIGS_S16_ID,mgr);
  76. ref.reload(FIRF64::FIRREFS_F64_ID,mgr);
  77. output.create(ref.nbSamples(),FIRF64::OUT_F64_ID,mgr);
  78. /* Max 2*blockSize + numTaps - 1 as generated by Python script
  79. A temp buffer blockSize is used by Helium implementation.
  80. It is at beginning of state buffer and is NOT the state
  81. of the FIR which is in the following part.
  82. */
  83. state.create(47+47,FIRF64::OUT_F64_ID,mgr);
  84. }
  85. void FIRF64::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  86. {
  87. (void)id;
  88. output.dump(mgr);
  89. }