Generic_Ramp_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.5*pow(10,-6) # burst time 9 Tau=900*pow(10,-6) # pulse repetition time 10 fmax=30*pow(10,6) # maximum frequency on ramp 11 fmin=10*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 16 y = 1 + np.sin(theta_n) # ramp signal in time domain 17 18 t = Ts*np.arange(0,n,1) 19 Y = fft(y) 20 M =len(Y) 21 m = np.arange(M) 22 T = M*Ts 23 freq = m/T 24 25 26 plt.figure(figsize = (12, 6)) 27 plt.subplot(121) 28 plt.stem(freq, np.abs(Y), 'b', \ 29 markerfmt=" ", basefmt="-b") 30 plt.xlabel('Freq (Hz)') 31 plt.ylabel('FFT Amplitude |Y(freq)|') 32 plt.xlim(0, (1.3*fmax)) 33 plt.ylim(0, 60) 34 35 plt.subplot(122) 36 plt.plot(t, ifft(Y), 'r') 37 plt.xlabel('Time (s)') 38 plt.ylabel('Amplitude') 39 plt.tight_layout() 40 41 plt.show()