Tummas Tomasson / Mbed 2 deprecated PingDetector_mbedadc

Dependencies:   mbed

Revision:
0:efb27fbc92c0
Child:
1:227db871d328
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PingDetect/FFT.cpp	Mon Jul 30 09:57:42 2012 +0000
@@ -0,0 +1,39 @@
+#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]);
+    }
+}
\ No newline at end of file