Advertisement
patryk

KCK - Signals 2

Dec 8th, 2015
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from numpy import *
  2. from numpy.fft import fft
  3. import matplotlib.pyplot as plt
  4.  
  5. def zad1():
  6.     array = genfromtxt("spots.txt")
  7.     n = len(array)
  8.     fs = n/12
  9.     signal = fft(array)
  10.     signal = abs(signal)
  11.     temp_signal = signal[1:]
  12.     maximum = max(temp_signal)
  13.  
  14.     print(maximum)
  15.     lista = list(signal)
  16.     print(lista.index(maximum))
  17.  
  18.     t = linspace(0,fs,len(array), endpoint=False)
  19.     plt.stem(t,signal)
  20.     plt.show()
  21.  
  22.  
  23. def zad2():
  24.     A = 1
  25.     F = 1.0
  26.     T = 1/F
  27.     f = lambda t : (A * (sin(2*pi*t) + sin(4*pi*t)))
  28.  
  29.     LP = 10
  30.     w = 20
  31.     TW = 1/w
  32.  
  33.     t = arange(0, LP*T, TW)
  34.     n = len(t)
  35.    
  36.     signal = f(t)
  37.  
  38.     signal1 = fft(signal)
  39.     signal1 = abs(signal1)
  40.  
  41.     freqs = linspace(0, w, n)
  42.     plt.stem(freqs, signal1, '-*')
  43.     plt.show()
  44.  
  45. def zad3():
  46.     A = 1
  47.     F = 1.0
  48.     T = 1/F
  49.     f = lambda t : (A * (sin(2*pi*t) + sin(4*pi*t)))
  50.  
  51.     LP = 10
  52.     w = 20
  53.     TW = 1/w
  54.    
  55.     t = arange(0, LP*T, TW)
  56.     n = len(t)
  57.  
  58.     signal = f(t)
  59.     signal1 = fft(signal)
  60.     signal1 = abs(signal1)
  61.  
  62.     z = a+bi
  63.     faza = arg(z)
  64.    
  65.     freqs = linspace(0, w, n)
  66.     plt.plot(freqs, signal1, '-*')
  67.     plt.plot(freqs, faza, '-^')
  68.     plt.show()
  69.    
  70.  
  71.    
  72.  
  73.  
  74.  
  75.  
  76. if __name__ == "__main__":
  77.     zad1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement