from tftb.generators import fmlin, amgauss from tftb.processing import loctime, locfreq import numpy as np import matplotlib.pyplot as plt # generate signal signal = fmlin(256)[0] * amgauss(256) plt.subplot(211), plt.plot(np.real(signal)) plt.xlim(0, 256) plt.xlabel('Time') plt.ylabel('Real part') plt.title('Signal') plt.grid() fsig = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2) plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig) plt.xlabel('Normalized frequency') plt.ylabel('Squared modulus') plt.title('Spectrum') plt.grid() plt.subplots_adjust(hspace=0.5) plt.show() tm, T = loctime(signal) print("Time Center: {}".format(tm)) print("Time Duration: {}".format(T)) num, B = locfreq(signal) print("Frequency Center: {}".format(num)) print("Frequency Spreading: {}".format(B))
# # Copyright © 2015 jaidev <jaidev@newton> # # Distributed under terms of the MIT license. """ Example in section 2.4 of the tutorial. """ import numpy as np import matplotlib.pyplot as plt from tftb.generators import amgauss, fmlin from tftb.processing import loctime, locfreq, inst_freq, group_delay time_instants = np.arange(2, 256) sig1 = amgauss(256, 128, 90) * fmlin(256)[0] tm, T1 = loctime(sig1) fm, B1 = locfreq(sig1) ifr1 = inst_freq(sig1, time_instants)[0] f1 = np.linspace(0, 0.5 - 1.0 / 256, 256) gd1 = group_delay(sig1, f1) plt.subplot(211) plt.plot(time_instants, ifr1, '*', label='inst_freq') plt.plot(gd1, f1, '-', label='group delay') plt.xlim(0, 256) plt.grid(True) plt.legend() plt.title("Time-Bandwidth product: {0}".format(T1 * B1)) plt.xlabel('Time') plt.ylabel('Normalized Frequency')
Instantaneous frequency and group delay are very closely related. The former is the frequency of a signal at a given instant, and the latter is the time delay of frequency components. As this example shows, they coincide with each other for a given signal when the time bandwidth product of the signal is sufficiently high. """ import numpy as np import matplotlib.pyplot as plt from tftb.generators import amgauss, fmlin from tftb.processing import loctime, locfreq, inst_freq, group_delay time_instants = np.arange(2, 256) sig1 = amgauss(256, 128, 90) * fmlin(256)[0] tm, T1 = loctime(sig1) fm, B1 = locfreq(sig1) ifr1 = inst_freq(sig1, time_instants)[0] f1 = np.linspace(0, 0.5 - 1.0 / 256, 256) gd1 = group_delay(sig1, f1) plt.subplot(211) plt.plot(time_instants, ifr1, '*', label='inst_freq') plt.plot(gd1, f1, '-', label='group delay') plt.xlim(0, 256) plt.grid(True) plt.legend() plt.title("Time-Bandwidth product: {0}".format(T1 * B1)) plt.xlabel('Time') plt.ylabel('Normalized Frequency')
from tftb.generators import amgauss from tftb.processing import loctime, locfreq import numpy as np import matplotlib.pyplot as plt # generate signal signal = amgauss(256) plt.subplot(211), plt.plot(np.real(signal)) plt.xlim(0, 256) plt.xlabel('Time') plt.ylabel('Real part') plt.title('Signal') plt.grid() fsig = np.fft.fftshift(np.abs(np.fft.fft(signal))**2) plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig) plt.xlabel('Normalized frequency') plt.ylabel('Squared modulus') plt.title('Spectrum') plt.grid() plt.subplots_adjust(hspace=0.5) plt.show() tm, T = loctime(signal) print "Time Center: {}".format(tm) print "Time Duration: {}".format(T) fm, B = locfreq(signal) print "Frequency Center: {}".format(fm) print "Frequency Spreading: {}".format(B) print "Time-bandwidth product: {}".format(T * B)