from tftb.generators import fmlin from tftb.processing.linear import ShortTimeFourierTransform import matplotlib.pyplot as plt from scipy.signal import hamming import numpy as np from mpl_toolkits.axes_grid1 import make_axes_locatable N = 128 x1, _ = fmlin(N, 0, 0.2) x2, _ = fmlin(N, 0.3, 0.5) x = x1 + x2 n_fbins = 128 window = hamming(33) tfr, _, _ = ShortTimeFourierTransform(x, timestamps=None, n_fbins=n_fbins, fwindow=window).run() tfr = tfr[:64, :] threshold = np.amax(np.abs(tfr)) * 0.05 tfr[np.abs(tfr) <= threshold] = 0.0 + 1j * 0.0 tfr = np.abs(tfr) ** 2 t = np.arange(tfr.shape[1]) f = np.linspace(0, 0.5, tfr.shape[0]) T, F = np.meshgrid(t, f) fig, axScatter = plt.subplots(figsize=(10, 8)) axScatter.contour(T, F, tfr, 5) axScatter.grid(True) axScatter.set_title('Squared modulus of STFT') axScatter.set_ylabel('Frequency') axScatter.yaxis.set_label_position("right")
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2015 jaidev <jaidev@newton> # # Distributed under terms of the MIT license. """ Example from section 3.1.4 of the tutorial. """ import numpy as np from tftb.processing.linear import ShortTimeFourierTransform from tftb.generators import fmlin, amgauss from matplotlib.pyplot import cm x = np.real(amgauss(128) * fmlin(128)[0]) window = np.array([1]) stft = ShortTimeFourierTransform(x, n_fbins=128, fwindow=window) tfr, _, _ = stft.run() stft.plot(show_tf=True, cmap=cm.gray)
from tftb.processing.linear import ShortTimeFourierTransform from tftb.generators import fmconst import numpy as np sig = np.r_[fmconst(128, 0.2)[0], fmconst(128, 0.4)[0]] tfr = ShortTimeFourierTransform(sig) tfr.run() tfr.plot()