sinc.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. dsp/sinc.h
  3. Copyright 2003-4 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. computes the sinc function: sin (x * pi) / (x * pi).
  6. */
  7. /*
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. 02111-1307, USA or point your web browser to http://www.gnu.org.
  20. */
  21. #ifndef _SINC_H_
  22. #define _SINC_H_
  23. #include "Sine.h"
  24. namespace DSP {
  25. /* sample sinc() with step size omega into s[], centered around s + n / 2 */
  26. inline void
  27. sinc (double omega, sample_t * s, int n)
  28. {
  29. /* initial phase */
  30. double phi = (n / 2) * -omega;
  31. Sine sine (omega, phi);
  32. for (int i = 0; i < n; ++i, phi += omega)
  33. {
  34. double sin_phi = sine.get();
  35. if (fabs (phi) < 0.000000001)
  36. s[i] = 1.;
  37. else
  38. s[i] = sin_phi / phi;
  39. }
  40. }
  41. }; /* namespace DSP */
  42. #endif /* _SINC_H_ */