sourcecode_fs.py
def produceFourierSeries(x, nMax, xMin, xMax, f):
    """ Produces Fourier Series approximation of a function
    
        ----------

        Parameters

        ----------

        x: array_like
            sample values

        nMax: int
            number of terms

        xMin: float
            lower bound on window/approximation

        xMax: float
            upper bound on window/approximation

        f: function
            function to be approximated

    """
    T = xMax - xMin

    # need new range over the actual range of the approximation (not the plotting range)
    # so integration is correct
    xFuncPeriod = np.arange(xMin, xMax, 0.001)

    # set initial state of series to be the a0 constant
    series = np.zeros(len(x))
    series += (1./T)*np.trapz(f(xFuncPeriod,xMin,xMax), x=xFuncPeriod)

    prev = None

    for i in range(nMax):
        n = i+1 # set n term number based on loop counter
        an = (2./T)*np.trapz(f(xFuncPeriod,xMin,xMax)*np.cos(2*n*np.pi*xFuncPeriod*(1/T)), x=xFuncPeriod)
        bn = (2./T)*np.trapz(f(xFuncPeriod,xMin,xMax)*np.sin(2*n*np.pi*xFuncPeriod*(1/T)), x=xFuncPeriod)

        prev = np.add(an * np.cos(2*n*np.pi*x*(1/T)), bn * np.sin(2*n*np.pi*x*(1/T)))
        series = np.add(series, prev)

    return series, prev
 Produces Fourier Series approximation of a function
    
        ----------

        Parameters

        ----------

        x: array_like
            sample values

        nMax: int
            number of terms

        xMin: float
            lower bound on window/approximation

        xMax: float
            upper bound on window/approximation

        f: function
            function to be approximated

    
Produces Fourier Series approximation of a function
Parameters





int
number of terms

float
lower bound on window/approximation

float
upper bound on window/approximation

function
function to be approximated
Produces Fourier Series approximation of a function Parameters int number of terms float lower bound on window / approximation float upper bound on window / approximation function function to be approximated
def produceFourierSeries(x, nMax, xMin, xMax, f):
    T = xMax - xMin
    xFuncPeriod = np.arange(xMin, xMax, 0.001)
    series = np.zeros(len(x))
    series += (1./T)*np.trapz(f(xFuncPeriod,xMin,xMax), x=xFuncPeriod)
    prev = None
    for i in range(nMax):
        n = i+1 
        an = (2./T)*np.trapz(f(xFuncPeriod,xMin,xMax)*np.cos(2*n*np.pi*xFuncPeriod*(1/T)), x=xFuncPeriod)
        bn = (2./T)*np.trapz(f(xFuncPeriod,xMin,xMax)*np.sin(2*n*np.pi*xFuncPeriod*(1/T)), x=xFuncPeriod)
        prev = np.add(an * np.cos(2*n*np.pi*x*(1/T)), bn * np.sin(2*n*np.pi*x*(1/T)))
        series = np.add(series, prev)
    return series, prev
def produceFourierSeries ( x , nMax , xMin , xMax , f ) : T = xMax - xMin xFuncPeriod = np . arange ( xMin , xMax , 0.001 ) series = np . zeros ( len ( x ) ) series += ( 1. / T ) * np . trapz ( f ( xFuncPeriod , xMin , xMax ) , x = xFuncPeriod ) prev = None for i in range ( nMax ) : n = i + 1 an = ( 2. / T ) * np . trapz ( f ( xFuncPeriod , xMin , xMax ) * np . cos ( 2 * n * np . pi * xFuncPeriod * ( 1 / T ) ) , x = xFuncPeriod ) bn = ( 2. / T ) * np . trapz ( f ( xFuncPeriod , xMin , xMax ) * np . sin ( 2 * n * np . pi * xFuncPeriod * ( 1 / T ) ) , x = xFuncPeriod ) prev = np . add ( an * np . cos ( 2 * n * np . pi * x * ( 1 / T ) ) , bn * np . sin ( 2 * n * np . pi * x * ( 1 / T ) ) ) series = np . add ( series , prev ) return series , prev
Produces Fourier Series approximation of a function
Parameters
Produces Fourier Series approximation of a function Parameters
""" Produces Fourier Series approximation of a function
    
        ----------

        Parameters

        ----------

        x: array_like
            sample values

        nMax: int
            number of terms

        xMin: float
            lower bound on window/approximation

        xMax: float
            upper bound on window/approximation

        f: function
            function to be approximated

    """ # need new range over the actual range of the approximation (not the plotting range) # so integration is correct # set initial state of series to be the a0 constant # set n term number based on loop counter
x
nMax
xMin
xMax
f