Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: KISS FTT Library Port

  1. #1
    Junior Member
    Join Date
    Aug 2015

    KISS FTT Library Port


    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?

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Germany NRW
    The audiolibrary can do that.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    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.

  4. #4
    Junior Member
    Join Date
    Aug 2015
    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??

  5. #5
    Senior Member Wozzy's Avatar
    Join Date
    Jan 2013
    Philadelphia, Pennsylvania USA
    Good question... I have a similar future application where I'd like 1024FFT but with a max sample frequency of 500 Hz.

  6. #6
    Junior Member
    Join Date
    Aug 2015
    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"
    #define TEST_LENGTH_SAMPLES 2048
    #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(", ");

  7. #7
    Senior Member
    Join Date
    Sep 2013
    Sonoma County, CA
    Quote Originally Posted by tjtyson View Post
    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).

  8. #8
    Junior Member
    Join Date
    Aug 2015
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts