Skip to content
Enrique Condes edited this page Nov 21, 2024 · 6 revisions

API

Migrating from versions prior to 2.0

  • The object name is now capitalized and the constructor requires a floating-point data type, e.g. "ArduinoFFT" instead of "arduinoFFT".
  • All function names are camelCase case now (start with lower-case character), e.g. "windowing()" instead of "Windowing()".

About the number of samples

The number of samples MUST ALWAYS be a power of 2. Any other value will produce an infinite loop during the computing phase. Acceptable values are: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384.

Note

There is a bug causing an overflow when samples==2048 or samples==4096 and the dominant frequency is not properly detected. Don't use those values until further notice.

Constructors

ArduinoFFT<T>()

Simplest constructor possible. Returns an arduinoFFT object that will operate on arguments of the type T where Tis either floator double.

This constructor was kept for backwards compatibility with and using it demands using the functions that at the very least receive the following parameters:

  • Pointers to the data arrays of type T
  • Number of samples
  • Sampling frequency

ArduinoFFT<T>(T *vReal, T *vImag, uint_fast16_t samples, T samplingFrequency, bool windowingFactors)

Returns an arduinoFFT object that will operate on arguments of the type T where Tis either floator double.

Arguments

  • vReal Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • vImag Pointer to a data array of size samples and type T where the imaginary part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • samplingFrequency floating point value of type T indicating the frequency in Hz at which the data sampling was performed.
  • windowingFactors (optional) (Since v2.0) Boolean factor to enable internal storage of the windowing factors, streamlining subsequent windowing operations. Defaults to false.

Data processing functions

void complexToMagnitude(void)

Processes the computed data and calculates magnitudes from complex numbers. The output will overwrite the first half of the integer data array.

void complexToMagnitude(T *vReal, T *vImag, uint_fast16_t samples)

Processes the computed data and calculates magnitudes from complex numbers. The output will overwrite the first half of the integer data array.

Arguments

  • vReal Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • vImag Pointer to a data array of size samples and type T where the imaginary part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.

void compute(FFTDirection dir)

Performs the Fast Fourier Transformation using the Cooley–Tukey algorithm.

Arguments

  • dir Direction on which to perform the transformation. Accepted values are FFTDirection::Forward or FFTDirection::Reverse

void compute(T *vReal, T *vImag, uint_fast16_t samples, FFTDirection dir)

Performs the Fast Fourier Transformation using the Cooley–Tukey algorithm.

Arguments

  • vReal Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • vImag Pointer to a data array of size samples and type T where the imaginary part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • dir Direction on which to perform the transformation. Accepted values are FFTDirection::Forward or FFTDirection::Reverse

void compute(T *vReal, T *vImag, uint_fast16_t samples, uint_fast8_t power, FFTDirection dir)

Performs the Fast Fourier Transformation using the Cooley–Tukey algorithm.

Arguments

  • vReal Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • vImag Pointer to a data array of size samples and type T where the imaginary part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • power Log base 2 of samples.
  • dir Direction on which to perform the transformation. Accepted values are FFTDirection::Forward or FFTDirection::Reverse

void dcRemoval(void)

Offsets the sampled signal so that it is centered around the X-axis of a plot, removing any DC offset that could have been present during sampling.

void dcRemoval(T *vData, uint_fast16_t samples)

Offsets the sampled signal so that it is centered around the X-axis of a plot, removing any DC offset that could have been present during sampling. ** This is the version that must be used when using the simple constructor. **

Arguments

  • vData Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.

T majorPeak(void)

Returns an estimation of the dominant frequency according to the interpolation of the biggest peak found on the magnitude array.

void majorPeak(T *frequency, T *magnitude)

Computes an estimation of the dominant frequency through interpolation of the magnitude array and its magnitude in arbitrary units.

Arguments

  • frequency Pointer to a variable of type T where the interpolated frequency value will be stored.
  • magnitude Pointer to a variable of type T where the magnitude in arbitrary units will be stored.

T majorPeak(T *vData, uint_fast16_t samples, T samplingFrequency)

Returns an estimation of the dominant frequency according to the interpolation of the biggest peak found on the magnitude array.

Arguments

  • vData Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • samplingFrequency floating point value of type T indicating the frequency in Hz at which the data sampling was performed.

void majorPeak(T *vData, uint_fast16_t samples, T samplingFrequency, T *frequency, T *magnitude)

Computes an estimation of the dominant frequency through interpolation of the magnitude array and its magnitude in arbitrary units.

Arguments

  • vData Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • samplingFrequency floating point value of type T indicating the frequency in Hz at which the data sampling was performed.
  • frequency Pointer to a variable of type T where the interpolated frequency value will be stored.
  • magnitude Pointer to a variable of type T where the magnitude in arbitrary units will be stored.

T majorPeakParabola(void)

Returns an estimation of the dominant frequency according to interpolation through the parabola equation of the biggest peak found on the magnitude array.

void majorPeakParabola(T *frequency, T *magnitude)

Computes the interpolated frequency value of the biggest peak found on the magnitude array and its magnitude in arbitrary units using the parabola equation.

Arguments

  • frequency Pointer to a variable of type T where the interpolated frequency value will be stored.
  • magnitude Pointer to a variable of type T where the magnitude in arbitrary units will be stored.

T majorPeakParabola(T *vData, uint_fast16_t samples, T samplingFrequency)

Returns an estimation of the dominant frequency according to interpolation through the parabola equation of the biggest peak found on the magnitude array.

Arguments

  • vData Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • samplingFrequency floating point value of type T indicating the frequency in Hz at which the data sampling was performed.

void majorPeakParabola(T *vData, uint_fast16_t samples, T samplingFrequency, T *frequency, T *magnitude)

Computes the interpolated frequency value of the biggest peak found on the magnitude array and its magnitude in arbitrary units using the parabola equation.

Arguments

  • vData Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • samples Size of the data array in number of elements.
  • samplingFrequency floating point value of type T indicating the frequency in Hz at which the data sampling was performed.
  • frequency Pointer to a variable of type T where the interpolated frequency value will be stored.
  • magnitude Pointer to a variable of type T where the magnitude in arbitrary units will be stored.

void windowing(FFTWindow windowType, FFTDirection dir, bool withCompensation)

Performs a windowing operation on the data to give more or less weight to different data sections.

Arguments

  • windowType Which windowing operation should be performed on the data. Accepted values are:
    • FFTWindow::Rectangle
    • FFTWindow::Hamming
    • FFTWindow::Hann
    • FFTWindow::Triangle
    • FFTWindow::Nuttall
    • FFTWindow::Blackman
    • FFTWindow::Blackman_Nuttall
    • FFTWindow::Blackman_Harris
    • FFTWindow::Flat_top
    • FFTWindow::Welch
  • dir Direction on which to perform the windowing operation, aka apply/remove windowing factors. Accepted values are:
    • FFTDirection::Forward Apply the windowing.
    • FFTDirection::Reverse Remove the windowing.
  • withCompensation (optional) (Since v2.0) Boolean value regarding the use of compensation factors to correct how the signal is modified during windowing. Defaults to false.

void windowing(T *vData, uint_fast16_t samples, FFTWindow windowType, FFTDirection dir, T *windowingFactors, bool withCompensation)

Performs a windowing operation on the data to give more or less weight to different data sections.

Arguments

  • windowType Which windowing operation should be performed on the data. Accepted values are:
    • FFTWindow::Rectangle
    • FFTWindow::Hamming
    • FFTWindow::Hann
    • FFTWindow::Triangle
    • FFTWindow::Nuttall
    • FFTWindow::Blackman
    • FFTWindow::Blackman_Nuttall
    • FFTWindow::Blackman_Harris
    • FFTWindow::Flat_top
    • FFTWindow::Welch
  • dir Direction on which to perform the windowing operation, aka apply/remove windowing factors. Accepted values are:
    • FFTDirection::Forward Apply the windowing.
    • FFTDirection::Reverse Remove the windowing.
  • withCompensation (optional) (Since v2.0) Boolean value regarding the use of compensation factors to correct how the signal is modified during windowing. Defaults to false.

See Windowing for more information regarding the window types.

Helper functions

uint8_t revision(void)

Returns the current revision of the arduinoFFT library with the format 0xMn where M is the mayor version number and n is the minor version number. For example 0x15 corresponds to version 1.5.

void setArrays(T *vReal, T *vImag, uint_fast16_t samples) (Since v2.0)

Replaces the internal data array pointers with new pointers.

  • vReal Pointer to a data array of size samples and type T where the integer part of the data is stored and will be processed.
  • vImag Pointer to a data array of size samples and type T where the imaginary part of the data is stored and will be processed.
  • samples (optional) Size of the data array in number of elements. Only necessary if the number of elements has changed since object creation.
Clone this wiki locally