View Full Version : KISS FTT Library Port

09-19-2015, 02:40 PM

I am new and I was curious has anyone ported the KISS FFT library to the Teensy yet? And if Not how hard would it be?

I know their is a library for the Audio board out there, but I am looking to just sample an ADC pin, store the result to memory and at a later time perform a 1024 point FFT on the sections of the data.

Any help or suggestions?

Frank B
09-19-2015, 03:39 PM
The audiolibrary can do that.

09-21-2015, 01:24 PM
I haven't looked at this library and I've not heard of anyone using it (yet).

Indeed you can use the audio library to do this sort of thing. The "queue" objects are used to get the actual audio samples transferred between the audio library and the arduino sketch. See File > Examples > Audio > Recorder to see how to read and store the actual audio. Of course, if you're just looking for a chunk to do a FFT, you can probably just store it into a big array rather than writing to a SD card.

09-24-2015, 02:02 PM
Hi Paul,

Thank you for your reply. My understanding is the Audio library FFT is hard coded with a known sample frequency of ~44KHz. If I am sampling my data at 2.5KHz is it possible to still use the audio library FFT function??

09-24-2015, 04:02 PM
Good question... I have a similar future application where I'd like 1024FFT but with a max sample frequency of 500 Hz.

09-24-2015, 05:16 PM
Hi Paul,

I found this thread that might be a better option to fit my needs but I am having a few problems with the code compiling due to not being able to find "arm_fft_sine_data.h" Can you provide advice on how to solve this issue?

Do you know of any examples for using the Radix FFT functions within the arm_math.h?

#define ARM_MATH_CM4
#include "arm_math.h"

#include "arm_fft_sine_data.h"

// NOTE: q15t is int16_t in arm_math.h
uint32_t fftSize = 512;

/* ------------------------------------------------------------------
* Global variables for FFT Bin Example
* ------------------------------------------------------------------- */
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;

uint32_t testInputIndex = 0;
float32_t testInput[TEST_LENGTH_SAMPLES];
static float32_t testOutput[TEST_LENGTH_SAMPLES/2];

void setup() {
pinMode(13, OUTPUT);
for (int i=0; i < 10; i++) {
Serial.println(" start program ");

bool pit3Triggered = false;

extern "C" {
//! Audio input interrupt handler running at 15kHz
void pit3_isr(void)
pit3Triggered = true;
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
PIT_TFLG3 = 1;

void startup_late_hook(void) {
// This is called from mk20dx128.c
//Turn on interrupts:
// turn on PIT
PIT_MCR = 0x00;

PIT_LDVAL3 = 3200 - 1; // setup timer 2 for frame timer period (15kHz) = 48MHz / 15kHz
PIT_TCTRL3 = 0x2; // enable Timer 3 interrupts
PIT_TCTRL3 |= 0x1; // start Timer 3
PIT_TFLG3 |= 1;

void loop() {

float32_t maxValue;
float32_t length = 256.0;
if (pit3Triggered) {
int sample;
sample = analogRead (14);
testInput[testInputIndex] = sample / 1024 * 10.0;
if (testInputIndex >= TEST_LENGTH_SAMPLES) {
testInputIndex = 0;

if (testInputIndex == 0) {
arm_cfft_radix4_instance_f32 fft_inst; /* CFFT Structure instance */
arm_cfft_radix4_init_f32(&fft_inst, length, ifftFlag, doBitReverse);

uint32_t startTime, fftTime, magTime, maxTime;
startTime = millis();
/* Process the data through the CFFT/CIFFT module */
arm_cfft_radix4_f32(&fft_inst, testInput_f32_10khz);
fftTime = millis();
/* Process the data through the Complex Magnitude Module for
calculating the magnitude at each bin */
arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, fftSize);
magTime = millis();
/* Calculates maxValue and returns corresponding BIN value */
arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
maxTime = millis();

Serial.println(fftTime - startTime);
Serial.println(magTime - fftTime);
Serial.println(maxTime - magTime);
Serial.println("TOTAL: ");
Serial.println(maxTime - startTime);

Serial.print("MaxValue: ");
Serial.print("MaxIndex: ");

Serial.print("Magnitudes: ");
for (int j=0; j < length / 2; j++) {
Serial.print(", ");

09-24-2015, 11:05 PM
My understanding is the Audio library FFT is hard coded with a known sample frequency of ~44KHz. If I am sampling my data at 2.5KHz is it possible to still use the audio library FFT function??

The FFT itself doesn't care what the sample rate is, you just have to be careful how you interpret the output. For a 44kHz sample rate, the max frequency component (the last bin) is at Fs/2 = 22kHz. If you change the sample rate to anything else, the last bin will always have a frequency component of ~ Fs/2 (this is only approximate because the last positive frequency bin in an FFT is actually Fs/2 - Fs/fft_length for even FFT lengths).

09-25-2015, 02:42 AM
Hi paul and whollender,

Thank you both for the advice, after a lot of reading and digging it made prefect sense and I was able to figure it out. Niw where as hard as I was making.

Thank you so much!