#include #include #include #include #include using namespace std; #include "GPS.h" #include "util/util.h" #include "param/complex.h" #include "param/fft.h" typedef double real_t; typedef Complex complex_t; #define IF_FREQ 4.309E6 // Hz #define CLK_FREQ 5.714E6 // Hz /* * 5714 sampled data = 1 ms, resolution 1000 Hz => 21 step (+-10KHz) * 4096(2^{14}) sampled data = 0.717 ms, resolution 1395 Hz => 15 step (+-10KHz) * 8192(2^{15}) sampled data = 1.434 ms, resolution 697.5 Hz => 29 step (+-10KHz) */ #define DATA_SIZE_AQ 5714 //#define DATA_SIZE_AQ 8192 //#define DATA_SIZE_AQ 64 #define FREQ_RANGE_AQ 10E3 #define FREQ_STEP (CLK_FREQ / DATA_SIZE_AQ) typedef struct{ template Complex operator()(const T &value){return Complex(value);} template Complex operator()(const Complex &value){return value.conjugate();} } Func_conj; typedef struct{ template T operator()(const T &value1, const T &value2){return value1 * value2;} } Func_multi; typedef struct{ template T operator()(const T &value){return (value > 0 ? value : -value);} template T operator()(const Complex &value){return value.abs();} } Func_abs; int main(int argc, char *argv[]){ char buf[64]; strstream line(buf, sizeof(buf), strstream::in); vector data; while(!cin.eof()){ cin.getline(buf, sizeof(buf)); buf[cin.gcount()] = '\0'; //cout << buf << endl; int value; line.seekg(0); line >> value; data.push_back(value); } cout << "DATA Length: " << data.size() << endl; vector data_aq(DATA_SIZE_AQ); copy(data.begin(), data.begin() + DATA_SIZE_AQ, data_aq.begin()); cout << "DATA_AQ Length: " << data_aq.size() << endl; copy(data_aq.begin(), data_aq.end(), ostream_iterator(cout, " ")); cout << endl; // Perform the FFT on the data_aq, x(n) -> X(k) vector data_aq_fd(FFT::fft(data_aq)); cout << "FFT" << endl; copy(data_aq_fd.begin(), data_aq_fd.end(), ostream_iterator(cout, "\n")); cout << endl; // Perform the IFFT on the data_aq, x(n) -> X(k) vector data_aq_td2(FFT::ifft(data_aq_fd)); cout << "IFFT" << endl; copy(data_aq_td2.begin(), data_aq_td2.end(), ostream_iterator(cout, "\n")); cout << endl; vector data_aq_power(data_aq_fd.size()); transform(data_aq_fd.begin(), data_aq_fd.end(), data_aq_power.begin(), Func_abs()); cout << "Power Spectrum" << endl; copy(data_aq_power.begin(), data_aq_power.end(), ostream_iterator(cout, "\n")); cout << endl; }