Advertisement
Guest User

dsp1

a guest
Oct 27th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include "tistdtypes.h"
  2. #include "gen_sinus.h"
  3. #include "sine_table.h"
  4. #include "math.h"
  5.  
  6. #define PI 3.14159265
  7.  
  8. void gen_sinus(int n, float a, float f, float ph, float buffer[])
  9. {
  10. int i;
  11. for (i=0; i<n; i++)
  12. {
  13. /* TO DO: Generate sine wave using math.h sin() function */
  14. buffer[i]=a*sin(2*PI*f*i+ph);
  15. }
  16. }
  17.  
  18. #define N SINE_TABLE_SIZE
  19. void gen_sinus_table(int n, float a, float f, float ph, float buffer[])
  20. {
  21. int i = 0;
  22. int delta = f * N;
  23. int k = (ph/(2*PI)*N);
  24. int mask = (N-1);
  25.  
  26. for (i = 0; i < n; i++)
  27. {
  28. k = k & mask;
  29. buffer[i] = a*p_sine_table[k];
  30. k+=delta;
  31. }
  32. }
  33.  
  34.  
  35. void gen_sinus_multiton(int n, float a, float f0, float df, float ph, float buffer[])
  36. {
  37. /* TO DO: Generate multitone sine wave */
  38. int i;
  39. for (i=0; i<n; i++)
  40. {
  41. /* TO DO: Generate sine wave using math.h sin() function */
  42. float f=0;
  43. for(f=f0;f<=0.5;){
  44. buffer[i]=a*sin(2*PI*f*i+ph);
  45. f+=df;
  46. }
  47.  
  48. }
  49.  
  50. }
  51.  
  52. void gen_lin_sweep(int n, float a, float f1, float f2, float ph, float buffer[])
  53. {
  54. /* TO DO: Generate linear sweep sine wave*/
  55. int i;
  56. for(i=0;i<n;i++)
  57. {
  58. buffer[i]=f1*i + ((f2-f1)/2*f2)*i*i + ph;
  59. }
  60.  
  61. }
  62.  
  63. void gen_log_sweep(int n, float a, float f1, float f2, float ph, float buffer[])
  64. {
  65. int i = 0;
  66. float ph_t = 0;
  67. for(i = 0; i < n; i++)
  68. {
  69. ph_t = (n*f1/log(f2/f1))*exp((i*log(f2/f1))/n)*2*PI+ph;
  70. buffer[i] = a*sin(ph_t);
  71. }
  72. }
  73.  
  74. void gen_square(int n, float a, float f, float D, float buffer[])
  75. {
  76. int i = 0, j=0;
  77. int T = 1/f;
  78. int Tmax = D*T/100;
  79.  
  80. for(i = 0; i < n; i++)
  81. {
  82. if(j < Tmax)
  83. {
  84. buffer[i] = a;
  85. }
  86. else if(j < T)
  87. {
  88. buffer[i] = 0;
  89. }
  90. else
  91. {
  92. j = 0;
  93. buffer[i] = a;
  94. }
  95. j++;
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement