Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. 0,1,0
  2. 0.1220703125,1,0
  3. 0.244140625,1,0
  4. 0.3662109375,1,0
  5. 0.48828125,1,0
  6. 0.6103515625,1,0
  7. .....
  8. -0.6103515625,1,0
  9. -0.48828125,1,0
  10. -0.3662109375,1,0
  11. -0.244140625,1,0
  12. -0.1220703125,1,0
  13.  
  14. 0.000,819,0
  15. 0.001,805.600848087199,4.11892742135933E-12
  16. 0.002,766.191083986647,7.80009390410896E-12
  17. 0.003,703.07869137741,1.07704956064936E-11
  18. 0.004,619.930866652693,1.26768595620774E-11
  19. 0.005,521.519198753447,1.32877042702262E-11
  20. 0.006,413.390428478234,1.26576527037514E-11
  21. 0.007,301.48763797423,1.08400510789863E-11
  22. 8,0.008,191.750273447113,7.79765141345479E-12
  23. ....
  24. 8.186,413.390428478235,7.79385628257856E-09
  25. 8.187,521.519198753448,9.84392145575441E-09
  26. 8.188,619.930866652693,1.17116023545805E-08
  27. 8.189,703.07869137741,1.32913150485692E-08
  28. 8.19,766.191083986645,1.44921696865197E-08
  29. 8.191,805.600848087196,1.52439926792702E-08
  30.  
  31. SF: Sample Frequency
  32. Samples: is array with samples 0..255
  33. N: is number of samples (8192)
  34. NP: is root of 2^NP = N (13)
  35. CF: cutoff freq of filter (30)
  36. W: number of coefficients in filter (40)
  37. dare: real data input
  38. daim: imaginary data input
  39.  
  40. for i = 0 To N – 1
  41. {
  42. // time axis for graphing results
  43. time(i) = i / SF
  44.  
  45. // freq axis for graphing, note symetric FFT so need -ve freq
  46. if i <= N / 2 then // Positive frequencies
  47. freq(i) = i * SF / N
  48. else // Negative frequencies
  49. freq(i) = i * SF / N - SF
  50.  
  51. // copy input data to local array
  52. // and normalise to 127 = 0, centering the input/transform
  53.  
  54. dare(i) = Samples(i) – 127
  55. daim(i) = 0
  56. }
  57.  
  58. // fft the input data
  59. FFT(NP, N, dare, daim)
  60.  
  61. // Create the impulse response of the filter in the frequency domain
  62. // this could be any filter but I use a simple box here: 1 in the passband and 0 elsewhere. Could use any filter here:
  63.  
  64. // Note that I used symmetric complex FFT: it is necessary
  65. // fill in the negative frequencies as well.
  66.  
  67. for i = 0 To N - 1
  68. {
  69. re(i) = 0
  70. if i <= (CF * N / SF) or i >= (N - CF * N / SF)
  71. re(i) = 1
  72. im(i) = 0
  73. }
  74.  
  75. // Inverse filter into the time domain
  76. // Note: imaginary parts should be ~ 0 after iFFT
  77. IFFT(NP, N, re, im)
  78.  
  79. // Hann window to truncate the filter series at say +/-20
  80. // can use other window formulas (e.g. bartlett) if desired
  81. for i = 0 To N – 1
  82. {
  83. window(i) = 0
  84. if i <= Won2 then
  85. window(i) = (0.5 + 0.5 * Cos(i * 2pi / (W + 1)))
  86. else if i >= N - Won2 then
  87. window(i) = (0.5 + 0.5 * Cos((N - i) * 2pi / (W + 1)))
  88. }
  89.  
  90. // Apply the Hann window to the filter
  91. for i = 0 To N – 1
  92. {
  93. //careful here if complex multiply required
  94. re(i) = re(i) * window(i)
  95. im(i) = 0
  96. }
  97.  
  98. // can IFFT and check for freq response and back again
  99.  
  100. // Shift the filter to make it i.e. +ve times only
  101. //shift lower coefs up
  102. for i = Won2 To 0 Step -1
  103. {
  104. re(i + Won2) = re(i) //
  105. }
  106. //wrap -ve coeffs around
  107. for i = 0 To Won2 – 1
  108. {
  109. re(i) = re(N - Won2 + i) //wrap N -> 0, N - 1 -> 1 etc
  110. re(N - Won2 + i) = 0
  111. }
  112.  
  113. // Transform filter back into the frequency domain
  114. FFT(NP, N, re, im)
  115.  
  116. //multiply input data by filter COMPLEX MULT REQUIRED!!
  117. // may be able to shorten this step if desired
  118. for i = 0 To N – 1
  119. {
  120. tmpre = dare(i) * re(i) - daim(i) * im(i)
  121. tmpim = dare(i) * im(i) + daim(i) * re(i)
  122. dare(i) = tmpre
  123. daim(i) = tmpim
  124. }
  125.  
  126. //inverse back to time domain
  127. IFFT(NP, N, dare, daim)
  128.  
  129. // copy back to input normalised and re centered
  130. // may need to normalise/scale at this stage
  131. for i = 0 To N – 1
  132. {
  133. Samples(i) = dare(i) + 127
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement