/ 8_Utils / Python / Generic_Triangular_Frequency.py
Generic_Triangular_Frequency.py
 1  import numpy as np
 2  from numpy.fft import fft, ifft
 3  import matplotlib.pyplot as plt
 4  
 5  
 6  fs=125*pow(10,6) #sampling frequency
 7  Ts=1/fs # sampling time
 8  Tb=0.25*pow(10,-6) # burst time
 9  Tau=1.5*pow(10,-6) # pulse repetition time
10  fmax=32*pow(10,6) # maximum frequency on ramp
11  fmin=1*pow(10,6) # minimum frequency on ramp
12  n=int(Tb/Ts) # number of samples per ramp
13  N = np.arange(0, n, 1)
14  theta_n= 2*np.pi*(pow(N,2)*pow(Ts,2)*(fmax-fmin)/(2*Tb)+fmin*N*Ts) # instantaneous phase
15  y = 1 + np.sin(theta_n) # ramp signal in time domain
16  
17  M = np.arange(n, 2*n, 1)
18  theta_m= 2*np.pi*(pow(M,2)*pow(Ts,2)*(-fmax+fmin)/(2*Tb)+(-fmin+2*fmax)*M*Ts)-2*np.pi*((fmin-fmax)*Tb/2+(2*fmax-fmin)*Tb) # instantaneous phase
19  z = 1 + np.sin(theta_m) # ramp signal in time domain
20  
21  x = np.concatenate((y, z))
22  
23  t = Ts*np.arange(0,2*n,1)
24  plt.plot(t, x)
25  X = fft(x)
26  L =len(X)
27  l = np.arange(L)
28  T = L*Ts
29  freq = l/T
30  
31  print("The Array is: ", x) #printing the array
32  
33  plt.figure(figsize = (12, 6))
34  plt.subplot(121)
35  plt.stem(freq, np.abs(X), 'b', \
36           markerfmt=" ", basefmt="-b")
37  plt.xlabel('Freq (Hz)')
38  plt.ylabel('FFT Amplitude |Y(freq)|')
39  plt.xlim(0, (fmax+fmax/10))
40  plt.ylim(0, 20)
41  
42  plt.subplot(122)
43  plt.plot(t, ifft(X), 'r')
44  plt.xlabel('Time (s)')
45  plt.ylabel('Amplitude')
46  plt.tight_layout()
47  
48  plt.show()
49