Skip to main content

A library for computing Fourier Series made for Physics Students!

Project description

Hello!

It has become evident to me that Python Scipy lacks a Fourier SERIES function! Unbelievable! I have made this for my peers in the Imperial College London Physics Department, I hope you find it useful :).

This package contains two components under the 'series' directory so far. Firstly, Fourier series computation for a periodic function, 'FSeries'. Secondly, Fourier Series computation for a periodic dataset, 'nFSeries'.

Please direct bug reports, feature requests, or anything else regarding this custom library to my personal email: LiuLouis1@gmail.com

For those of you reading on GitHub, running 'pip install FSeries' in Python should import this library!

Happy coding!

'series': 'series.FSeries': Compute the Fourier coefficients (a_n, b_n, a_0) for a periodic function f(x) using numerical integration.

    Parameters:
        x: array type int/float - the 'x' axis column
        f: function - the function to be decomposed
        T: float - period of the function (if periodic), or interval length (if non-periodic)
        n_terms: int - number of Fourier terms (default is 10)

    Returns: 
        series: numpy array - Fourier series approximation along x
        a_n: numpy array - Fourier cosine coefficients
        b_n: numpy array - Fourier sine coefficients
        a_0: float - Fourier a_0 coefficient

    Examples: 
        ... #generate x values
        def f_custom(x):
            return 0.5 * np.sin(3 * x) + 0.25 * np.cos(4 * x)

        T = np.pi
        series, a_n, b_n, a_0 = FSeries(x, f_custom, T=T, n_terms=10)

        #You can also plot the series function:
        plt.plot(x, series, label='Fourier Series Approximation')
    

'series.nFSeries': 
    Compute the Fourier coefficients (a_n, b_n, a_0) for a discrete, periodic dataset using numerical summations for each datapoint.
            
    Parameters: 
        data: pandas DataFrame or 2D array, shape - with columns for 'x' and 'y' axis, the dataset to be numerically analyzed
        T: float - period of the function (if periodic), or interval length (if non-periodic)
        n_terms: int - number of Fourier terms (default is 10)

    Returns: 
        series: numpy array - Fourier series approximation along x
        a_n: numpy array - Fourier cosine coefficients
        b_n: numpy array - Fourier sine coefficients
        a_0: float - Fourier a_0 coefficient

    Examples: 
        data = [[ 0.          0.        ]
                [ 0.1010101   0.10083842]
                [ 0.2020202   0.20064886]
                [ 0.3030303   0.2984138 ]
                [ 0.4040404   0.39313661]]
        #the first column here is x, the second is y
 
        series, a_n, b_n, a_0 = FSeries.series.nFSeries(data, 240, 20)
        
    
        data = [[ 0.          0.        ]
                [ 0.1010101   0.10083842]
                [ 0.2020202   0.20064886]
                [ 0.3030303   0.2984138 ]
                [ 0.4040404   0.39313661]]
        df = pd.DataFrame(data, columns=['x', 'y'])

        series, a_n, b_n, a_0 = FSeries.series.nFSeries(df, 120, 40)


        #You might even find this useful with the scipy.signal.sawtooth 
        function!

        f_values = signal.sawtooth(2 * np.pi * x / (2 * np.pi))  # Sawtooth wave
        data = np.column_stack((x, f_values))

        T = 2 * np.pi  # Period of the sawtooth wave
        series, a_n, b_n, a_0 = FSeries.series.nFSeries(data, T, n_terms=10)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epic_fourier-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epic_fourier-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file epic_fourier-0.1.0.tar.gz.

File metadata

  • Download URL: epic_fourier-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for epic_fourier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 95d438265c9046a7ba797ed14f48a35d723b2b7baef4892c585f297dd1fa8392
MD5 0391a20989882ccd4e6ec12f9535b624
BLAKE2b-256 6583432de81df8f5963762951750f911f3e3d6402c086fc8ccd2643e7ab30e1d

See more details on using hashes here.

File details

Details for the file epic_fourier-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: epic_fourier-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for epic_fourier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1571dd5dfdc3027e067e391281a8baade46302e3ec5187d0eab7b1a1a0a31a1b
MD5 f3b39c25b2e6b176317ea6a8bd2f7bf0
BLAKE2b-256 08aad32e6f8f2febae41302b433b815b130805eedf484832dd587f291a939485

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page