Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PingDetect/FFT.cpp
- Committer:
- tummastt
- Date:
- 2012-07-30
- Revision:
- 0:efb27fbc92c0
- Child:
- 1:227db871d328
File content as of revision 0:efb27fbc92c0:
#include "FFT.h"
// Using the Mellen FFT
extern "C" void fftR4(short *y, short *x, int N);
int FFT::DetectSignal(short data[]) {
    CalculateFFT(data);
    // adding the center frequencies with the 4 closesed frequencies
//    amp = my[centerFreq-2]+my[centerFreq]+my[centerFreq+2];
    amp = my[centerFreq-2]+my[centerFreq]+my[centerFreq+2];
//    return amp;
    if (amp >= AMPLITUDE_LIMIT)
        return found; // indicating pinger signal found
    else
        return notFound; // indicating no pinger signal found
}
void FFT::CalculateFFT(short data[]) {
    // Clearing array
    for (i=0; i<SAMPLES*2; i++)
        mx[i]=0;
    // Add data to array
    for (i=0; i<SAMPLES; i=i+1)
        mx[i*2]=data[i]-DCOFFSET;
    // calculate fft
    fftR4(my, mx, SAMPLES);
    // make all values positive
    for (i=0; i<SAMPLES; i=i+2) {
        my[i] = abs(my[i]);
    }
}