2
0

complex_tests.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * complex.c
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2008 Steve Underwood
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2, as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*! \page complex_tests_page Complex arithmetic tests
  26. \section complex_tests_page_sec_1 What does it do?
  27. \section complex_tests_page_sec_2 How is it used?
  28. */
  29. #if defined(HAVE_CONFIG_H)
  30. #include "config.h"
  31. #endif
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <fcntl.h>
  35. #include <string.h>
  36. #if defined(HAVE_TGMATH_H)
  37. #include <tgmath.h>
  38. #endif
  39. #if defined(HAVE_MATH_H)
  40. #include <math.h>
  41. #endif
  42. #include "floating_fudge.h"
  43. #include <assert.h>
  44. #include "spandsp.h"
  45. int main(int argc, char *argv[])
  46. {
  47. complexf_t fa;
  48. complexf_t fb;
  49. complexf_t fz;
  50. complexi16_t i16a;
  51. complexi16_t i16b;
  52. complexi16_t i16z;
  53. #if 0
  54. complexi32_t i32a;
  55. complexi32_t i32b;
  56. complexi32_t i32z;
  57. #endif
  58. fa = complex_setf(0.5f, 0.25f);
  59. fb = complex_setf(0.25f, 0.5f);
  60. fz = complex_mulf(&fa, &fb);
  61. printf("(%f, %f) * (%f, %f) => (%f, %f)\n", fa.re, fa.im, fb.re, fb.im, fz.re, fz.im);
  62. i16a = complex_seti16(16383, 8191);
  63. i16b = complex_seti16(8191, 16383);
  64. i16z = complex_mul_q1_15(&i16a, &i16b);
  65. printf("(%f, %f) * (%f, %f) => (%f, %f)\n", i16a.re/32768.0, i16a.im/32768.0, i16b.re/32768.0, i16b.im/32768.0, i16z.re/32768.0, i16z.im/32768.0);
  66. printf("Tests passed.\n");
  67. return 0;
  68. }
  69. /*- End of function --------------------------------------------------------*/
  70. /*- End of file ------------------------------------------------------------*/