FFT of truncated signals

FFT of truncated signals#

import numpy as np
def ft(t):
    return np.sin(t*2*np.pi)+np.sin(5*t*2*np.pi)

nt = 500
nT = 100
t = np.linspace(0., 1., nt)
T = np.linspace(.2, 5, nT)

#axeT, axef = np.meshgrid(T, t[0:nt//2], indexing='ij')
axeT = np.zeros((nT, nt//2))
axef = np.zeros((nT, nt//2))
mapf = np.zeros((nT, nt//2))
import matplotlib.pyplot as plt
#
fig, ax = plt.subplots(1,2, figsize=(16,8))
#
for i, iT in enumerate(T):
    signal = ft(t*iT)#*np.hanning(nt)
    mapf[i,:] = np.abs(np.fft.fft(signal))[0:nt//2]
    axef[i,:] = np.fft.fftfreq(signal.size, d=iT/nt)[0:nt//2] # linspace(0, nt/2/iT, nt//2)
    axeT[i,:] = iT
ax[0].contourf(axeT, axef, mapf)
ax[0].set_ylim(0, 10.)
#
for i, iT in enumerate(T):
    signal = ft(t*iT)*np.hanning(nt)
    mapf[i,:] = np.abs(np.fft.fft(signal))[0:nt//2]
    axef[i,:] = np.fft.fftfreq(signal.size, d=iT/nt)[0:nt//2] # linspace(0, nt/2/iT, nt//2)
    axeT[i,:] = iT
ax[1].contourf(axeT, axef, mapf)
ax[1].set_ylim(0, 10.)
(0.0, 10.0)
../_images/00f8e5a2805c59e76de26ac4484cea3d15415fa9c1be0d772cb19f6a38503dd9.png