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 = epic_fourier.series.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 = epic_fourier.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 = epic_fourier.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 = epic_fourier.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.2.1.tar.gz (3.6 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.2.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: epic_fourier-0.1.2.1.tar.gz
  • Upload date:
  • Size: 3.6 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.2.1.tar.gz
Algorithm Hash digest
SHA256 06ade89b2b925dc5faa0922a27cd8f4cbe25523c95b4b0429386fca9ebde7cec
MD5 d4d29db866c035694209c9bf2bde6db6
BLAKE2b-256 cb0629a52225996dd8d34b3e811df61ebd867d98ea6a832dc6dcc7a53742b91f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: epic_fourier-0.1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b024da9364e78e78b2d15c35bd3e1d90c542b28626b6dcc1ea0695b987a42f9d
MD5 53cc653ca2d88d79d534502a130011d1
BLAKE2b-256 9d69bc11a41c799d752da57e20ff9aae2cac24f26df9411912895abe43801875

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