Advertisement
Guest User

Pass the bleach

a guest
Oct 13th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. # ------------------------------------------------------------------------------
  2. # Name: Maninder Dhaliwal (1496691)
  3. # Assignment Four - Fourier Spectrums
  4. # This takes a data set and trys to clean it using fourier spectrums.
  5. # ------------------------------------------------------------------------------
  6.  
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9.  
  10. def main():
  11.  
  12. Data = np.genfromtxt("362HW4data.csv", delimiter = ",")
  13.  
  14. fig = plt.figure()
  15. ax1 = fig.add_subplot(3, 1, 1)
  16. ax2 = fig.add_subplot(3, 1, 2)
  17. ax3 = fig.add_subplot(3, 1, 3)
  18.  
  19. GivenDataPlot(Data, ax1)
  20. FourierAmpSpec(Data, ax2)
  21. FourierPhaSpec(Data, ax3)
  22.  
  23. plt.show()
  24.  
  25. return()
  26.  
  27. def GivenDataPlot(Input, canvas):
  28.  
  29. FRow = Input[:, 0] ; SRow = Input[:, 1]
  30.  
  31. canvas.plot(FRow, SRow)
  32.  
  33. canvas.set_xlabel("time")
  34. canvas.set_ylabel("signal")
  35. canvas.set_title("Funk")
  36.  
  37. return()
  38.  
  39. def FourierAmpSpec(Input, canvas):
  40.  
  41. fA_Data = abs(np.fft.rfftn(Input))
  42.  
  43. canvas.plot(fA_Data)
  44.  
  45. canvas.set_xlabel("frequency")
  46. canvas.set_ylabel("power")
  47. canvas.set_title("Da Noize")
  48.  
  49. return()
  50.  
  51. def FourierPhaSpec(Input, canvas):
  52.  
  53. fP_Data = np.angle((np.fft.rfftn(Input)))
  54.  
  55. canvas.plot(fP_Data)
  56.  
  57. canvas.set_xlabel("frequency")
  58. canvas.set_ylabel("phase")
  59. canvas.set_title("faze")
  60.  
  61. return()
  62.  
  63. main()
  64.  
  65. '''
  66. Idk what to do with this at this point ... in class Dr. Meldrum told us about
  67. slicing off the right half of the amplitude spectrum and then using that data
  68. for a cleaner function ... not sure how to do that whatsoever. My phase graph
  69. looks like a tide pod and I really have no clue how to fix it. I took the real
  70. fourier spectrum in 'n' dimensions throughout; a) because it just seems to
  71. match the data set I have so it didn't matter if I put an 'n' after the 'fft'
  72. or a '2' b) I did the real fourier transform because we are after a discrete
  73. fourier series.
  74.  
  75. I will comment this all up when I come back to this post Wednesday and clean
  76. everything up.
  77. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement