BIQUADQ15.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "BIQUADQ15.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. /*
  5. Accuracy issues on biquad df1 q15
  6. It will have to be reworked
  7. */
  8. #define SNR_THRESHOLD 30
  9. #define ABS_ERROR_Q15 ((q15_t)500)
  10. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  11. static __ALIGNED(8) q15_t coeffArray[32];
  12. #endif
  13. void BIQUADQ15::test_biquad_cascade_df1()
  14. {
  15. q15_t *statep = state.ptr();
  16. const q15_t *coefsp = coefs.ptr();
  17. const q15_t *inputp = inputs.ptr();
  18. q15_t *outp = output.ptr();
  19. int blockSize;
  20. /*
  21. Python script is generating different tests with
  22. different blockSize and numTaps.
  23. We loop on those configs.
  24. */
  25. blockSize = inputs.nbSamples() >> 1;
  26. /*
  27. The filter is initialized with the coefs, blockSize and numTaps.
  28. */
  29. arm_biquad_cascade_df1_init_q15(&this->S,3,coefsp,statep,2);
  30. /*
  31. Python script is filtering a 2*blockSize number of samples.
  32. We do the same filtering in two pass to check (indirectly that
  33. the state management of the fir is working.)
  34. */
  35. arm_biquad_cascade_df1_q15(&this->S,inputp,outp,blockSize);
  36. outp += blockSize;
  37. inputp += blockSize;
  38. arm_biquad_cascade_df1_q15(&this->S,inputp,outp,blockSize);
  39. outp += blockSize;
  40. ASSERT_EMPTY_TAIL(output);
  41. ASSERT_SNR(output,ref,(q15_t)SNR_THRESHOLD);
  42. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q15);
  43. }
  44. void BIQUADQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  45. {
  46. switch(id)
  47. {
  48. case BIQUADQ15::TEST_BIQUAD_CASCADE_DF1_1:
  49. break;
  50. }
  51. inputs.reload(BIQUADQ15::BIQUADINPUTS_Q15_ID,mgr);
  52. coefs.reload(BIQUADQ15::BIQUADCOEFS_Q15_ID,mgr);
  53. ref.reload(BIQUADQ15::BIQUADREFS_Q15_ID,mgr);
  54. output.create(ref.nbSamples(),BIQUADQ15::OUT_Q15_ID,mgr);
  55. /* max 4 * nbTaps as generated by Python script */
  56. /* Same OUTID is reused. So linked to same output file. If it is dumped
  57. it may overwrite the output
  58. */
  59. state.create(32,BIQUADQ15::OUT_Q15_ID,mgr);
  60. }
  61. void BIQUADQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  62. {
  63. output.dump(mgr);
  64. }