7.3 KiB
7.3 KiB
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from setupFigure import SetupFigure
from dftSlow import dft_coeff, dft_synthesisIn [ ]:
def dft_fast_coeff(x):
"""
Evaluate Fourier coefficients using Numpy's fast Fourier transform.
This routine only returns the coefficients for the positive frequencies.
If N is even, it goes up to n=N/2.
If N is odd, it goes up to n=(N-1)/2.
:param x: array of function samples
"""
return np.fft.rfft(x, norm='forward')In [ ]:
def dft_fast_synthesis(fc, outnum='even'):
"""
Use numpy's fast Fourier synthesis taking only Fourier coefficients for positive frequencies
:param fc: aray of coefficients for positive frequencies only.
:param outnum: specifies if output time series has an even or odd number of samples (default: 'even')
"""
ns = 2*fc.size-2
if outnum == 'odd': ns = 2*fc.size-1
return np.fft.irfft(fc, ns, norm='forward')In [ ]:
def boxcar(dt, period, tup, tdown):
"""
Calculate samples of a boxcar function
:param dt: sampling interval
:param period: time range is 0 <= t < period (multiple of dt)
:param tup: time where boxcar goes from 0 to 1
:param tdown: time where boxcar goes from 1 to 0
"""
ns = int(period/dt)
t = dt*np.arange(0, ns)
return t, np.where(t < tup, 0, 1)*np.where(t > tdown, 0, 1)In [ ]:
def gaussian(dt, period, tmax, hwidth):
"""
Calculate samples of a Gaussian function
:param dt: sampling interval
:param period: time range is 0 <= t < period (multiple of dt)
:param tmax: time of maximum of Gaussian
:param hwidth: half width of Gaussian
"""
ns = int(period/dt)
t = dt*np.arange(0, ns)
return t, np.exp(-(t-tmax)**2/hwidth**2)In [ ]:
"""Here comes your code"""In [ ]:
"""Here comes your code"""In [ ]:
"""Here comes your code"""In [ ]:
"""Here comes your code"""