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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fft_calculations-0.2.2.tar.gz.
File metadata
- Download URL: fft_calculations-0.2.2.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9ad1f8586b4ed9f0e79d70cafbc46b3511a01cba7f3da4321ef7507e1a7b4e5
|
|
| MD5 |
8c17c6b3f39cbd211376104699f42e38
|
|
| BLAKE2b-256 |
3b0b40622f7f1e48bb5fadb0a0cbfb4a8e4bd0f6ad3d7720bc99839c8818ce4e
|
File details
Details for the file fft_calculations-0.2.2-py3-none-any.whl.
File metadata
- Download URL: fft_calculations-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4849dc4654dfe4f04a146db05dc610980604d498382bef11781be07ad65ff60
|
|
| MD5 |
c0813a8a0aa8ed8844a2f250d91a2986
|
|
| BLAKE2b-256 |
26583032056ac10bbee97974af2c242c3e86c2ea1afa7bebcf9b163c3053ef67
|