Elektronikprojekt Grupp 13 / Mbed OS test_fft_grp13

Dependencies:   mbed-dsp

Fork of mbed-os-example-blinky by Elektronikprojekt Grupp 13

main.cpp

Committer:
KlaraBengtsson
Date:
2017-04-10
Revision:
64:92745a08320c
Parent:
63:f2972bba6f01
Child:
66:866bf1606317

File content as of revision 64:92745a08320c:

#include "mbed.h"
#include "arm_math.h"
#include "arm_const_structs.h"

const int FFT_SIZE = 32;
int sampleCounter;
float samples[FFT_SIZE*2];
float magnitudes[FFT_SIZE];
const static arm_cfft_instance_f32 *S;

//int SAMPLE_RATE_HZ = 10000;

float testData[] = {10, 20, 30, 40, 50, 60, 70, 80, 10, 20, 30, 40, 50, 60, 70, 80,10, 20, 30, 40, 50, 60, 70, 80, 10, 20, 30, 40, 50, 60, 70, 80};

void samplingBegin(){
    sampleCounter = 0;
    //sätt hårdvaru inställningar här om det behövs
}

void samplingCallback() {
    //läs data
    samples[sampleCounter] = testData[sampleCounter];
    // sätter imaginär till 0
    samples[sampleCounter + 1] = 0.0;
    sampleCounter += 2;
    if (sampleCounter >= FFT_SIZE *2 ) {
        //här är sampling klar, buffert är full
        //skriv hårdvaru kod här
    }   
}    

bool samplingIsDone() {
    return (sampleCounter >= FFT_SIZE*2);
}

// main() runs in its own thread in the OS
int main() { 

    samplingBegin();

    S = & arm_cfft_sR_f32_len32;



    while(1) {
        if(samplingIsDone()){
            arm_cfft_f32(S,samples,0,1);
            arm_cmplx_mag_f32(samples,magnitudes,FFT_SIZE);
            samplingBegin();
        }

    }
}