vector_op.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "RTE_Components.h"
  2. #include CMSIS_device_header
  3. #if defined(MPS3)
  4. #include "cmsis_driver_config.h"
  5. #include "stdout_USART.h"
  6. #endif
  7. #include <iostream>
  8. #include <dsppp/memory_pool.hpp>
  9. #include <dsppp/fixed_point.hpp>
  10. #include <dsppp/matrix.hpp>
  11. using namespace arm_cmsis_dsp;
  12. int main(void)
  13. {
  14. #if defined(MPS3)
  15. stdout_init();
  16. #endif
  17. std::cout << "Vector operation examples\r\n";
  18. constexpr int NB = 32;
  19. // float32 example
  20. Vector<float32_t,NB> a;
  21. Vector<float32_t,NB> b;
  22. Vector<float32_t,NB> c;
  23. for(int i = 0;i< NB;i++)
  24. {
  25. a[i] = b[i] = c[i] = i;
  26. }
  27. Vector<float32_t,NB> d = a + b * c;
  28. std::cout << "Result = " << d ;
  29. // Vector view example 1
  30. auto subD = d.sub(2);
  31. subD = subD + 2.0f;
  32. // d vector has been modified starting from the 3rd element
  33. // (index 2)
  34. std::cout << "Result = " << d ;
  35. // Now we set all odd elements to 0.
  36. d.sub<2>(1) = 0.0f;
  37. std::cout << "Result = " << d ;
  38. // Q15 example
  39. Vector<Q15,NB> aQ15;
  40. Vector<Q15,NB> bQ15;
  41. Vector<Q15,NB> cQ15;
  42. for(int i = 0;i< NB;i++)
  43. {
  44. aQ15[i] = bQ15[i] = cQ15[i] = Q15(i);
  45. }
  46. Vector<Q15,NB> dQ15 = aQ15 + bQ15 * cQ15;
  47. std::cout << "Result = " << dQ15 ;
  48. #if defined(MPS3)
  49. while(1);
  50. #endif
  51. }