Gen_Triangular.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 X = fft(x) 25 L =len(X) 26 l = np.arange(L) 27 T = L*Ts 28 freq = l/T 29 30 31 plt.figure(figsize = (12, 6)) 32 plt.subplot(121) 33 plt.stem(freq, np.abs(X), 'b', \ 34 markerfmt=" ", basefmt="-b") 35 plt.xlabel('Freq (Hz)') 36 plt.ylabel('FFT Amplitude |Y(freq)|') 37 plt.xlim(0, (fmax+fmax/10)) 38 plt.ylim(0, 20) 39 40 plt.subplot(122) 41 plt.plot(2*n, y) 42 plt.xlabel('Time (s)') 43 plt.ylabel('Amplitude') 44 plt.tight_layout() 45 46 plt.show()