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.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.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: epic_fourier-0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 225e6de12535455a442f925c0460a2e8bbde7b384e923d98358cd2c2b6e2aac1
MD5 d68d7518daf8ae1221c22dafc579caf8
BLAKE2b-256 9b7c7a59f321bbb52b0dcf61b099a8d0eae3151e09995089a3819b9679761c7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: epic_fourier-0.1.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1155d0e61a7b4cf0bc5cf456390468472d7bd8d842756a184555a7f7496ef250
MD5 36dc845303f55d8d795b563f4e533fb0
BLAKE2b-256 6e55e5c9fd605a59f9ea4412d2180e7ffc289c46c7b27d9411dc91bd7bf6fd31

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