Skip to main content

A package with some fft utility functions

Project description

fft_calculations

This is a small package with some fft utility functions.

functions

fft(wave, max_f=None, output='dBVrms')

The function fft calculates the fast fourier transform of 'wave' using scipy.fft.rfft with default arguments.

The argument 'max-f' determines the maximum frequency for which to return results. With this argument higher frequencies which are not of interest can be chopped of the results.

The argument 'output' determines the unit of the returned magnitudes.

  • 'dBVrms' returns the magnitudes in dBVrms
  • 'dBV' returns the magnitudes in dBV
  • 'V' returns the magnitudes in V (same unit as the unit of wave[1]) This assumes the unit of wave[1] is V, can be substituted for any other unit.

In the future support for windowing functions should be added.

The function returns a tuple (xf,yf,fft_max_f,fft_f_res) in which:

  • xf is an array of frequency bins [0..max_f] is max_f is not None, else [0..fft_max_f]
  • yf is an equally sized array of magnitudes with th eunit determined by the argument 'output'
  • fft_max_f is the maximum frequency if the fft (equal to the Nyquist frequency)
  • fft_f_res is the frequency resolution in the resulting fft. This is the distance between frequency bins.

thd(fft,f0,correct_peaks=False,min_level=None)

This function calculates the total harmonic distortion of a signal. The fft for the signal to be analyzed is in the argument 'fft', where fft is a tuple (t,v) in which t is an array of time, and v is an equally sized array of values.

The argument 'f0' is the fundamental frequency for which the harmonics are searched in the suuplied signal.

The argument 'correct_peaks' will decide if frequency bin correction is applied. Frequency bin correction means that after finding the bin for a harmonic, the bin with highest value will take over. This is only for bins directly neighbouring with the original bin, and without any inbetween bins with lower values.

The argument 'min_level' defines the lowest signal level for which harmonics will be included in the THD calculation. Any values lower than 'min_level' will be skipped.

The function returns a tuple (thd,bins) where

  • thd is a float giving the total harmonic distortion (in %)
  • bins is an array of indices into the frequency bins for the harmonics (regardless if they have been taken into account for the thd calculation or not)

frequency_window(fft,centre,span)

Returns a slice from 'fft'. The argument 'fft' is a tuple (f,y) where f and y are equally sized arrays. The array f contains the centre frequency of the frequency bins of the fft. The array y contains the magnitude (any unit) of the respective frequency bins.

The returned slice is determined by the arguments 'centre' and 'span'. The argument 'centre' determines the centre of the frequency range to return, and 'span' is the entire span of the returned frequency range. The returned frequency range thus will be [centre-span/2:centre+span/2].

The returned slice will be in the same format as the input argument 'fft', namely a tuple (f',y'), where f' is the reduced frequency range, and y' the according magnitudes.

installation

python3 -m pip install fft_calculations

requirements

  • numpy
  • scipy

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

fft_calculations-0.2.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

fft_calculations-0.2.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file fft_calculations-0.2.3.tar.gz.

File metadata

  • Download URL: fft_calculations-0.2.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for fft_calculations-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6f2a05b0ab52964020546fec43eae3acccbc5e7d97581fe1c3b2131b4b586c33
MD5 98dc7e81a98a7137910c16df3f21a343
BLAKE2b-256 5bdd617c3dd4ba040f2b79ec6319547dd71605b24410ef577ece2627212536d5

See more details on using hashes here.

File details

Details for the file fft_calculations-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fft_calculations-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ded61d97adc19ff813c2269ca90a2ee76e3e9fe1693be6b11c5cf133d4e8e750
MD5 67f94cdb8fe52ea45f843c14dc825d62
BLAKE2b-256 db9d3a30a058ccfb2ce6835acd7e9239077dec90d2253f3458ecc1ea05ae5938

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