Advertisement
thukon

Fast Fourier Transform

Jun 24th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import csv
  2. import plotly
  3. import plotly.offline as offline
  4. import plotly.graph_objs as go
  5. import scipy
  6. import numpy
  7.  
  8. time = []
  9. voltage = []
  10.  
  11. data_file = open("data_0.dat")
  12. with data_file as csvfile:
  13.     reader = csv.reader(data_file, delimiter = ",")
  14.     for row in reader:
  15.         time.append(row[0])
  16.  
  17.         voltage.append(row[1])
  18.  
  19. N = len(voltage)
  20. #rate = 2500
  21. array = numpy.array(voltage)
  22.  
  23. xplot = time
  24. yplot = numpy.fft.fft(voltage)
  25. freq = numpy.fft.fftfreq(N, .01923)
  26.  
  27. mask = freq > 0
  28.  
  29. trace_accel = go.Scatter(
  30.     x = freq[mask],
  31.     y = numpy.abs(yplot[mask]),
  32.     name = 'Ampl vs Freq',
  33.     line = dict(
  34.         color = ('rgb(255,0,0)'),
  35.         width = 1))
  36.  
  37. data = [trace_accel]
  38. layout = dict(title = "Amplitude vs. Frequency",
  39.     xaxis = dict(title = 'Frequency (Hz)'),
  40.     yaxis = dict(title = 'Amplitude'),
  41.     font = dict(size=16))
  42.  
  43. fig = dict(data=data, layout=layout)
  44.  
  45. offline.plot(fig,
  46.     image_height='1275', image_width='1650', image='png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement