Source: https://mokxi.com/libraries/arduinofft
Updated: 2026-11-23

Libraries / Data and time

Arduino library · Data and time

# arduinoFFT: the frequency spectrum of a sampled signal

Yes. You can use the arduinoFFT library online in Mokxi with nothing to install, and the sketch runs in your browser. The example below, "Audio spectrum analyzer", runs on the ESP32 DevKit V1.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <arduinoFFT.h> and it builds, with nothing to install. Free, and no account needed.

## What arduinoFFT does

arduinoFFT by Enrique Condes turns a block of samples taken at a steady rate into a spectrum: how much of each frequency the signal holds. People use it to find the pitch of a note picked up by a microphone, drive a spectrum analyzer on an LED matrix, or watch a motor’s vibration. You fill an array of real values, set the imaginary array to zero, and the library does the transform in place.

The steps are always the same: apply a window so the ends of the block do not smear energy across the spectrum, compute the transform, turn the complex results into magnitudes, then read them. Each output bin i stands for i times the sampling rate over the number of samples, and majorPeak() interpolates between bins to give the strongest frequency in hertz.

Version 2 changed the interface. It is a template, ArduinoFFT<double> or ArduinoFFT<float>, built with the arrays, the sample count and the sampling rate, so the calls take no arguments beyond the window and direction. Old sketches written for version 1 use the arduinoFFT class with capitalized methods and pass the arrays every time; Mokxi keeps both, and the example runs both on the same 1000 Hz tone sampled 8000 times a second. The block size must be a power of two, and on an Uno 64 or 128 samples is about as far as the RAM goes.

Library Manager name | arduinoFFT

Author | Enrique Condes

Include | #include <arduinoFFT.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <arduinoFFT.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "arduinoFFT" by Enrique Condes from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add arduinoFFT to lib_deps in PlatformIO. Mokxi follows the calls of release 2.0.4, so a sketch written here builds there too.

- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- ESP32-S3-CAM
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### ArduinoFFT<double> FFT(vReal, vImag, samples, samplingFrequency)

The version 2 object, tied to your two arrays, the number of samples (a power of two) and the rate they were taken at in hertz.

### FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward)

Weights the samples so the block’s edges fade out. Hamming suits most uses; Rectangle means no window at all.

### FFT.compute(FFTDirection::Forward)

Runs the transform in place. Afterward vReal and vImag hold the complex result, not your samples.

### FFT.complexToMagnitude()

Replaces the first half of vReal with the size of each frequency bin. Only bins 0 to samples / 2 mean anything.

### FFT.majorPeak()

The strongest frequency in hertz, interpolated between bins, so it can land closer than one bin’s width.

### FFT.dcRemoval()

Subtracts the average from the samples before the window, so the offset of an analogRead() centered at 512 does not swamp bin 0 and its neighbors.

### legacy.MajorPeak(vReal, samples, samplingFrequency)

The version 1 form on an arduinoFFT object: every method is capitalized and takes the arrays as arguments.

## Example: Audio spectrum analyzer

On the ESP32 DevKit V1. It runs in the browser exactly as printed.

sketch.ino · ESP32 DevKit V1

The sketch is cut short here; the editor has every line of it.

Open it in the editor, wired and ready to run · Audio spectrum analyzer: the project page

## Common errors and how to fix them

### 'FFTWindow' has not been declared, or no matching function for call to arduinoFFT::Windowing

The sketch mixes the two versions. Code with FFT.Windowing(vReal, ...) is version 1 and wants the arduinoFFT class; code with FFTWindow:: is version 2 and wants ArduinoFFT<double>. Pick one form for the whole sketch.

### The peak frequency is wrong by a large, fixed amount

The sampling rate you told the library is not the rate you sampled at. Time the sampling loop with micros() and wait for each sample period, rather than calling analogRead() as fast as it goes and guessing.

### The sketch resets or prints garbage with 256 samples on an Uno

Two arrays of 256 doubles take 2 KB, all of the Uno’s RAM. Use 64 or 128 samples, ArduinoFFT<float>, or a board with more memory such as an ESP32.

## Questions and answers

### Why does version 1 give 1015.9 Hz where version 2 gives 1000?

Version 1’s MajorPeak divides by samples minus one when it converts the bin to hertz. Version 2 fixed that, so its answer lands on the true frequency.

### What is the highest frequency I can measure?

Half the sampling rate. Sampling at 8000 Hz shows frequencies up to 4000 Hz, and anything above that folds back as a false lower peak.

## Keep going

### Learn

- Arduino Sound Sensor (KY-038): Clap Switch
- Arduino 2D Array: Rows, Columns and Strings

### More data and time libraries

- QRCode
- Madgwick
- PID
- TimerOne
- MsTimer2
- Low-Power
- RTClib
- DS1307RTC
- Ds1302
- Chrono
- Tasker
- CountDown
- microDS3231
- DS1307 (Seeed)

Every built-in library · Open the editor

## Try arduinoFFT without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
