Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #to start with marplotlib
  2. #ipython --pylab
  3.  
  4. import numpy as np
  5. from scipy.signal import tiang
  6. from scipy.fftpack import fft
  7.  
  8. x = triang(15) #triangular function
  9. x = fft(x)
  10. mX = abs(X)
  11. pX = np.angle(X)
  12.  
  13. #########################################
  14.  
  15. plot(x)
  16. plot(mX) #magnitude and phase. first half are positive, second half are negative
  17. plot(pX) #phase should be zero, why? Because time signal was not centered around zero (it had a shift)
  18.  
  19. #########################################
  20.  
  21. #center around zero
  22. x = triang(15)
  23. fftbuffer = np.zeros(15)
  24. fftbuffer[:8] = x[7:] #from beginning to 8
  25. fftbuffer[8:] = x[:7] #from 8 to end
  26. X = fft(fftbuffer)
  27. mX = abs(X)
  28. pX = np.angle(X)
  29.  
  30. #########################################
  31.  
  32. plot(fftbuffer) #v shaped
  33. plot(mX) #magnitude spectrum. no change
  34. plot(pX) #phase is different
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement