FIRQ7.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "FIRQ7.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 10
  5. #define ABS_ERROR_Q7 ((q7_t)2)
  6. #if defined(ARM_MATH_MVEI)
  7. static __ALIGNED(8) q7_t coeffArray[32];
  8. #endif
  9. void FIRQ7::test_fir_q7()
  10. {
  11. const int16_t *configp = configs.ptr();
  12. q7_t *statep = state.ptr();
  13. const q7_t *orgcoefsp = coefs.ptr();
  14. const q7_t *coefsp;
  15. const q7_t *inputp = inputs.ptr();
  16. q7_t *outp = output.ptr();
  17. int i;
  18. #if defined(ARM_MATH_MVEI)
  19. int j;
  20. #endif
  21. int blockSize;
  22. int numTaps;
  23. /*
  24. Python script is generating different tests with
  25. different blockSize and numTaps.
  26. We loop on those configs.
  27. */
  28. for(i=0; i < configs.nbSamples() >> 1; i++)
  29. {
  30. blockSize = configp[0];
  31. numTaps = configp[1];
  32. #if defined(ARM_MATH_MVEI)
  33. /* Copy coefficients and pad to zero
  34. */
  35. memset(coeffArray,0,32);
  36. for(j=0;j < numTaps; j++)
  37. {
  38. coeffArray[j] = orgcoefsp[j];
  39. }
  40. coefsp = coeffArray;
  41. #else
  42. coefsp = orgcoefsp;
  43. #endif
  44. /*
  45. The filter is initialized with the coefs, blockSize and numTaps.
  46. */
  47. arm_fir_init_q7(&this->S,numTaps,coefsp,statep,blockSize);
  48. /*
  49. Input pointer is reset since the same input pattern is used
  50. */
  51. inputp = inputs.ptr();
  52. /*
  53. Python script is filtering a 2*blockSize number of samples.
  54. We do the same filtering in two pass to check (indirectly that
  55. the state management of the fir is working.)
  56. */
  57. arm_fir_q7(&this->S,inputp,outp,blockSize);
  58. outp += blockSize;
  59. inputp += blockSize;
  60. arm_fir_q7(&this->S,inputp,outp,blockSize);
  61. outp += blockSize;
  62. configp += 2;
  63. orgcoefsp += numTaps;
  64. }
  65. ASSERT_EMPTY_TAIL(output);
  66. ASSERT_SNR(output,ref,(q7_t)SNR_THRESHOLD);
  67. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q7);
  68. }
  69. void FIRQ7::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  70. {
  71. switch(id)
  72. {
  73. case FIRQ7::TEST_FIR_Q7_1:
  74. break;
  75. }
  76. inputs.reload(FIRQ7::FIRINPUTS_Q7_ID,mgr);
  77. coefs.reload(FIRQ7::FIRCOEFS_Q7_ID,mgr);
  78. configs.reload(FIRQ7::FIRCONFIGS_S16_ID,mgr);
  79. ref.reload(FIRQ7::FIRREFS_Q7_ID,mgr);
  80. output.create(ref.nbSamples(),FIRQ7::OUT_Q7_ID,mgr);
  81. /* Max blockSize + numTaps - 1 as generated by Python script */
  82. state.create(47,FIRQ7::OUT_Q7_ID,mgr);
  83. }
  84. void FIRQ7::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  85. {
  86. output.dump(mgr);
  87. }