Guest User

Untitled

a guest
Apr 26th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #include <math.h>
  2.  
  3. #define DUZINA_BAFERA 256
  4.  
  5. int Mag [DUZINA_BAFERA/2];
  6. int sinus[DUZINA_BAFERA];
  7. int cosinus[DUZINA_BAFERA];
  8.  
  9. int signal[DUZINA_BAFERA] = {
  10. 0, 1771, -163, 721, -721, 1608, 2288, -47, 1022, -46, 2266, 1638,
  11. -728, 720, -163, 1757, 33, -1783, 161, -722, 716, -1576, -2313, 49,
  12. -1022, 46, -2242, -1670, 734, -719, 164, -1742, -67, 1798,
  13. -160, 722, -709, 1545, 2335, -49, 1021, -44, 2218, 1701, -738,
  14. 718, -165, 1728, 101, -1810, 158, -722, 703, -1513, -2358, 47,
  15. -1020, 42, -2194, -1730, 743, -715, 163, -1713, -135, 1823, -156,
  16. 721, -694, 1481, 2380, -48, 1018, -40, 2169, 1761, -747, 713,
  17. -163, 1697, 170, -1835, 154, -721, 687, -1449, -2401, 47, -1016,
  18. 36, -2144, -1792, 751, -711, 162, -1682, -203, 1846, -150, 719,
  19. -678, 1418, 2423, -45, 1014, -33, 2120, 1822, -753, 707, -162,
  20. 1665, 237, -1858, 147, -718, 672, -1385, -2444, 43, -1012, 30,
  21. -2094, -1852, 756, -704, 159, -1650, -272, 1868, -143, 717, -662,
  22. 1353, 2464, -41, 1010, -27, 2070, 1880, -758, 700, -157, 1633,
  23. 305, -1880, 139, -714, 654, -1322, -2485, 38, -1007, 22, -2044,
  24. -1910, 760, -696, 154, -1616, -339, 1889, -134, 713, -644, 1290,
  25. 2504, -35, 1004, -18, 2018, 1939, -762, 692, -152, 1599, 372,
  26. -1898, 130, -710, 634, -1257, -2525, 32, -1001, 12, -1992, -1969,
  27. 763, -688, 149, -1580, -406, 1907, -124, 707, -624, 1225, 2544,
  28. -27, 996, -6, 1965, 1996, -764, 683, -146, 1563, 440, -1915,
  29. 119, -704, 614, -1192, -2562, 23, -993, 1, -1939, -2025, 763,
  30. -677, 142, -1545, -473, 1924, -113, 700, -603, 1159, 2581, -19,
  31. 989, 3, 1913, 2052, -763, 672, -138, 1527, 506, -1931, 107,
  32. -697, 592, -1127, -2600, 13, -984, -10, -1886, -2080, 761, -666,
  33. 135, -1508
  34. };
  35.  
  36. void trigLookup(int sinus[], int cosinus[], int duzina) {
  37. int i;
  38. for(i=0; i<duzina; i++){
  39. sinus[i]=(int)(sin(6.28*i/duzina)*32767); // Q15
  40. cosinus[i]=(int)(cos(6.28*i/duzina)*32767); // Q15
  41. }
  42. }
  43.  
  44. void dft(int x[], int N) {
  45. int i, k;
  46. long xRe, xIm;
  47. for (k=0; k<(N/2); k++) {
  48. xRe=0;
  49. xIm=0;
  50. for(i=0; i<N; i++){
  51. xRe += ((long)x[i]*(long)cosinus[(k*i)%N])>>15;
  52. xIm += ((long)x[i]*(long)sinus[(k*i)%N])>>15;
  53. }
  54. Mag[k]=(((long)(xRe>>7)*(long)(xRe>>7))+((long)(xIm>>7)*(long)(xIm>>7)))>>11;
  55. }
  56. }
  57.  
  58. void main(void) {
  59. int i;
  60.  
  61. // Generisi lookup tabele za sin i cos
  62. trigLookup(sinus, cosinus, DUZINA_BAFERA);
  63.  
  64. // Uradi DFT signala. Spektralne komponente se nalaze u vektoru Mag[]
  65. dft(signal, DUZINA_BAFERA);
  66.  
  67. // Fs = 8kHz, broj odbiraka = 256
  68. // rezolucija = 8000/256 = 31.25
  69. // k1 = 8, f1 = 31.25 * k1 = 250
  70. // k2 = 56, f2 = 1750
  71. // k3 = 104, f3 = 31.25 * 104 = 3250
  72.  
  73. while(1);
  74. }
Add Comment
Please, Sign In to add comment