2
0

dc_restore_tests.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * dc_restore_tests.c - Tests for the dc_restore functions.
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2001 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 dc_restore_tests_page DC restoration tests
  26. \section dc_restore_tests_page_sec_1 What does it do?
  27. */
  28. #if defined(HAVE_CONFIG_H)
  29. #include "config.h"
  30. #endif
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <memory.h>
  34. #include <time.h>
  35. #include "spandsp.h"
  36. int main (int argc, char *argv[])
  37. {
  38. awgn_state_t *noise_source;
  39. dc_restore_state_t dc_state;
  40. int i;
  41. int idum = 1234567;
  42. int16_t dirty;
  43. int estimate;
  44. int min;
  45. int max;
  46. int dc_offset;
  47. dc_offset = 5000;
  48. noise_source = awgn_init_dbm0(NULL, idum, -10.0);
  49. dc_restore_init(&dc_state);
  50. for (i = 0; i < 100000; i++)
  51. {
  52. dirty = awgn(noise_source) + dc_offset;
  53. dc_restore(&dc_state, dirty);
  54. if ((i % 1000) == 0)
  55. {
  56. printf("Sample %6d: %d (expect %d)\n",
  57. i,
  58. dc_restore_estimate(&dc_state),
  59. dc_offset);
  60. }
  61. }
  62. /* We should have settled by now. Look at the variation we get */
  63. min = 99999;
  64. max = -99999;
  65. for (i = 0; i < 100000; i++)
  66. {
  67. dirty = awgn(noise_source) + dc_offset;
  68. dc_restore(&dc_state, dirty);
  69. estimate = dc_restore_estimate(&dc_state);
  70. if (estimate < min)
  71. min = estimate;
  72. if (estimate > max)
  73. max = estimate;
  74. }
  75. printf("Spread of DC estimate for an offset of %d was %d to %d\n", dc_offset, min, max);
  76. if (min < dc_offset - 50 || max > dc_offset + 50)
  77. {
  78. printf("Test failed.\n");
  79. exit(2);
  80. }
  81. awgn_free(noise_source);
  82. printf("Test passed.\n");
  83. return 0;
  84. }
  85. /*- End of function --------------------------------------------------------*/
  86. /*- End of file ------------------------------------------------------------*/