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
    Posts
    5

    KISS FTT Library Port

    Hi,

    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
    Location
    Germany NRW
    Posts
    6,924
    The audiolibrary can do that.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,750
    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
    Posts
    5
    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
    Location
    Philadelphia, Pennsylvania USA
    Posts
    354
    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
    Posts
    5
    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?

    Code:
    #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() {
      Serial.begin(19200);
      pinMode(13, OUTPUT);
      for (int i=0; i < 10; i++) {
        Serial.println(" start program ");
        delay(1000);
      }
    }
     
    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:
      SIM_SCGC6 |= SIM_SCGC6_PIT;
      // turn on PIT
      PIT_MCR = 0x00;
      NVIC_ENABLE_IRQ(IRQ_PIT_CH3);
      
      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;
    	testInputIndex++;
    	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;
    	Serial.println("Start"); 
    	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("End");  
    
    	Serial.println(fftTime - startTime);
    	Serial.println(magTime - fftTime);
    	Serial.println(maxTime - magTime);
    	Serial.println("TOTAL: ");
    	Serial.println(maxTime - startTime);
    
    	Serial.print("MaxValue: ");
    	Serial.println(maxValue);
    	Serial.print("MaxIndex: ");
    	Serial.println(testIndex);
    
    	Serial.print("Magnitudes: ");
    	for (int j=0; j < length / 2; j++) {
    	  Serial.print(j);
    	  Serial.print(", ");
    	  Serial.println(testOutput[j]);
    	}
      }  
    }

  7. #7
    Senior Member
    Join Date
    Sep 2013
    Location
    Sonoma County, CA
    Posts
    141
    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
    Posts
    5
    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
  •