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@0:efb27fbc92c0, 2012-07-30 (annotated)
- Committer:
- tummastt
- Date:
- Mon Jul 30 09:57:42 2012 +0000
- Revision:
- 0:efb27fbc92c0
- Child:
- 1:227db871d328
Working
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| tummastt | 0:efb27fbc92c0 | 1 | #include "FFT.h" | 
| tummastt | 0:efb27fbc92c0 | 2 | |
| tummastt | 0:efb27fbc92c0 | 3 | // Using the Mellen FFT | 
| tummastt | 0:efb27fbc92c0 | 4 | extern "C" void fftR4(short *y, short *x, int N); | 
| tummastt | 0:efb27fbc92c0 | 5 | |
| tummastt | 0:efb27fbc92c0 | 6 | int FFT::DetectSignal(short data[]) { | 
| tummastt | 0:efb27fbc92c0 | 7 | |
| tummastt | 0:efb27fbc92c0 | 8 | CalculateFFT(data); | 
| tummastt | 0:efb27fbc92c0 | 9 | |
| tummastt | 0:efb27fbc92c0 | 10 | // adding the center frequencies with the 4 closesed frequencies | 
| tummastt | 0:efb27fbc92c0 | 11 | // amp = my[centerFreq-2]+my[centerFreq]+my[centerFreq+2]; | 
| tummastt | 0:efb27fbc92c0 | 12 | amp = my[centerFreq-2]+my[centerFreq]+my[centerFreq+2]; | 
| tummastt | 0:efb27fbc92c0 | 13 | // return amp; | 
| tummastt | 0:efb27fbc92c0 | 14 | if (amp >= AMPLITUDE_LIMIT) | 
| tummastt | 0:efb27fbc92c0 | 15 | return found; // indicating pinger signal found | 
| tummastt | 0:efb27fbc92c0 | 16 | |
| tummastt | 0:efb27fbc92c0 | 17 | else | 
| tummastt | 0:efb27fbc92c0 | 18 | return notFound; // indicating no pinger signal found | 
| tummastt | 0:efb27fbc92c0 | 19 | |
| tummastt | 0:efb27fbc92c0 | 20 | } | 
| tummastt | 0:efb27fbc92c0 | 21 | |
| tummastt | 0:efb27fbc92c0 | 22 | void FFT::CalculateFFT(short data[]) { | 
| tummastt | 0:efb27fbc92c0 | 23 | |
| tummastt | 0:efb27fbc92c0 | 24 | // Clearing array | 
| tummastt | 0:efb27fbc92c0 | 25 | for (i=0; i<SAMPLES*2; i++) | 
| tummastt | 0:efb27fbc92c0 | 26 | mx[i]=0; | 
| tummastt | 0:efb27fbc92c0 | 27 | |
| tummastt | 0:efb27fbc92c0 | 28 | // Add data to array | 
| tummastt | 0:efb27fbc92c0 | 29 | for (i=0; i<SAMPLES; i=i+1) | 
| tummastt | 0:efb27fbc92c0 | 30 | mx[i*2]=data[i]-DCOFFSET; | 
| tummastt | 0:efb27fbc92c0 | 31 | |
| tummastt | 0:efb27fbc92c0 | 32 | // calculate fft | 
| tummastt | 0:efb27fbc92c0 | 33 | fftR4(my, mx, SAMPLES); | 
| tummastt | 0:efb27fbc92c0 | 34 | |
| tummastt | 0:efb27fbc92c0 | 35 | // make all values positive | 
| tummastt | 0:efb27fbc92c0 | 36 | for (i=0; i<SAMPLES; i=i+2) { | 
| tummastt | 0:efb27fbc92c0 | 37 | my[i] = abs(my[i]); | 
| tummastt | 0:efb27fbc92c0 | 38 | } | 
| tummastt | 0:efb27fbc92c0 | 39 | } |