import matplotlib.pyplot as plt from tftb.generators import fmsin, fmlin, fmconst from tftb.processing import (ideal_tfr, WignerVilleDistribution, smoothed_pseudo_wigner_ville, reassigned_smoothed_pseudo_wigner_ville) sig1, if1 = fmsin(60, 0.16, 0.35, 50, 1, 0.35, 1) sig2, if2 = fmlin(60, 0.3, 0.1) sig3, if3 = fmconst(60, 0.4) sig = np.hstack((sig1, np.zeros((8, )), sig2 + sig3)) iflaw = np.zeros((2, 128)) iflaw[0, :] = np.hstack((if1, np.nan * np.ones((8, )), if2)) iflaw[1, :] = np.hstack((np.nan * np.ones((68, )), if3)) tfr, t, f = ideal_tfr(iflaw) plt.figure(figsize=(10, 8)) plt.subplot(221) plt.contour(t, f, tfr, 1) plt.gca().set_xticklabels([]) plt.grid(True) plt.title("Ideal instantaneous frequencies") plt.ylabel('Normalized Frequencies') tfr = WignerVilleDistribution(sig).run()[0] threshold = np.amax(np.abs(tfr)**2) * 0.05 tfr[np.abs(tfr)**2 <= threshold] = 0.0 plt.subplot(222) plt.imshow(np.abs(tfr)**2, extent=[0, 128, 0, 0.5],
from tftb.generators import fmsin, fmlin, fmconst from tftb.processing.cohen import Spectrogram from tftb.processing.reassigned import spectrogram as re_spectrogram from tftb.processing.reassigned import morlet_scalogram as re_morlet_scalogram from tftb.processing import ideal_tfr sig1, if1 = fmsin(60, 0.16, 0.35, 50, 1, 0.35, 1) sig2, if2 = fmlin(60, 0.3, 0.1) sig3, if3 = fmconst(60, 0.4) sig = np.hstack((sig1, np.zeros((8,)), sig2 + sig3)) iflaw = np.zeros((2, 128)) iflaw[0, :] = np.hstack((if1, np.nan * np.ones((8,)), if2)) iflaw[1, :] = np.hstack((np.nan * np.ones((68,)), if3)) tfr, t, f = ideal_tfr(iflaw) plt.figure(figsize=(10, 8)) plt.subplot(221) plt.contour(t, f, tfr, 1) plt.grid(True) plt.gca().set_xticklabels([]) plt.title("Ideal instantaneous frequencies") plt.ylabel('Normalized Frequencies') tfr, _, _ = Spectrogram(sig).run() threshold = np.amax(np.abs(tfr)) * 0.05 tfr[np.abs(tfr) <= threshold] = 0.0 plt.subplot(222) plt.imshow(np.abs(tfr)[:64, :], extent=[0, 128, 0, 0.5], aspect='auto', origin='bottomleft') plt.grid(True) plt.gca().set_xticklabels([])
hybrid signal (containing sinusoidal, constant and linear frequency modulations), against its ideal time-frequency characteristics. Figure 4.34 from the tutorial. """ from tftb.generators import fmsin, fmhyp from tftb.processing import ideal_tfr, reassigned_spectrogram, Spectrogram import numpy as np import matplotlib.pyplot as plt n_points = 128 sig1, if1 = fmsin(n_points, 0.15, 0.45, 100, 1, 0.4, -1) sig2, if2 = fmhyp(n_points, [1, .5], [32, 0.05]) sig = sig1 + sig2 ideal, t, f = ideal_tfr(np.vstack((if1, if2))) _, re_spec, _ = reassigned_spectrogram(sig) spec, t3, f3 = Spectrogram(sig).run() # Ideal tfr plt.subplot(221) plt.contour(t, f, ideal, 1) plt.grid(True) plt.gca().set_xticklabels([]) plt.title("Ideal time-frequency distro") plt.ylabel('Normalized Frequency') # Spectrogram plt.subplot(222) plt.contour(t3, f3[:64], spec[:64, :]) plt.grid(True)
This example compares the spectrogram and the reassigned spectrogram of a hybrid signal (containing sinusoidal, constant and linear frequency modulations), against its ideal time-frequency characteristics. """ from tftb.generators import fmsin, fmhyp from tftb.processing import ideal_tfr, reassigned_spectrogram, Spectrogram import numpy as np import matplotlib.pyplot as plt n_points = 128 sig1, if1 = fmsin(n_points, 0.15, 0.45, 100, 1, 0.4, -1) sig2, if2 = fmhyp(n_points, [1, .5], [32, 0.05]) sig = sig1 + sig2 ideal, t, f = ideal_tfr(np.vstack((if1, if2))) _, re_spec, _ = reassigned_spectrogram(sig) spec, t3, f3 = Spectrogram(sig).run() # Ideal tfr plt.subplot(221) plt.contour(t, f, ideal, 1) plt.grid(True) plt.gca().set_xticklabels([]) plt.title("Ideal time-frequency distro") plt.ylabel('Normalized Frequency') # Spectrogram plt.subplot(222) plt.contour(t3, f3[:64], spec[:64, :]) plt.grid(True)