for Danillo

Dependencies:   MBed_Adafruit-GPS-Library SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
ncfronk
Date:
Tue Nov 18 08:50:58 2014 +0000
Parent:
0:37d4e78b2076
Child:
2:abcf77d0e77d
Commit message:
gps does not work concurrently with sampling;

Changed in this revision

MBed_Adafruit-GPS-Library.lib Show annotated file Show diff for this revision Revisions of this file
QAM.h Show annotated file Show diff for this revision Revisions of this file
realtimeQAM.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MBed_Adafruit-GPS-Library.lib	Tue Nov 18 08:50:58 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mlee350/code/MBed_Adafruit-GPS-Library/#a23e3099bb0a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QAM.h	Tue Nov 18 08:50:58 2014 +0000
@@ -0,0 +1,99 @@
+#include "mbed.h"
+#include "math.h"
+
+#define SAMPLE_LENGTH       512 
+#define NUM_TAPS            513
+#define CARRIER_FREQ        225
+#define TIME_CONST          0.00006
+#define PI                  3.14159265
+
+float firCoeffs[NUM_TAPS] = { -0.0192878684408550, -0.000565436854162197, -0.000574062372234321, -0.000581179079003090, -0.000589412242712984, -0.000596329290925752,
+-0.000604183313496965, -0.000610787449621752, -0.000618254890021300, -0.000624441235452662, -0.000631532852699149, -0.000637317640388987, -0.000644060044878972, -0.000649408145295391, 
+-0.000655730318423711, -0.000660536584899437, -0.000666350155348239, -0.000670543670441799, -0.000675811138190482, -0.000679345019980268, -0.000684011485494165, -0.000686779420740873,
+-0.000690735948708760, -0.000692604062270113, -0.000695783521327534, -0.000696695831913496, -0.000699146857491809, -0.000699128468616956, -0.000700978318797988, -0.000700085972408138,
+-0.000701562144359961, -0.000699960260396518, -0.000701552559161197, -0.000699587125715329, -0.000702084347004260, -0.000699951609455988, -0.000704184938277025, -0.000700822488823546, 
+-0.000707053158406025, -0.000689238102101884, -0.000675432749281130, -0.000692284271988876, -0.000679003259712778, -0.000679427972422059, -0.000670867964963519, -0.000668435478754011, 
+-0.000660330946718933, -0.000656187894249034, -0.000647892827216824, -0.000642486260779654, -0.000633714444974831, -0.000627154674611770, -0.000617702529114801, -0.000610043338194475, 
+-0.000599831070682668, -0.000591137773968283, -0.000580109977377959, -0.000570367122683910, -0.000558402454183533, -0.000547524082087984, -0.000534508605134922, -0.000522458425410067, 
+-0.000508372396429405, -0.000495193607822494, -0.000480069347179249, -0.000465821362319299, -0.000449698934449484, -0.000434475552201623, -0.000417460223522498, -0.000401443504121743, 
+-0.000383669251697455, -0.000366972910244881, -0.000348312520886679, -0.000330677260377738, -0.000310488418329100, -0.000291306404219105, -0.000268590084163264, -0.000247735016213375, 
+-0.000223063752779904, -0.000208020109997019, -0.000182718834161682, -0.000158038013340163, -0.000135672987348502, -0.000110658422989979, -8.63859218366082e-05, -6.07302747179699e-05, 
+-3.52380267488923e-05, -8.75000381957480e-06, 1.79220776252956e-05, 4.53634810869086e-05, 7.31488512081353e-05, 0.000101522460573350, 0.000130337162460535, 0.000159652043314615, 
+0.000189518312913980, 0.000219864413943603, 0.000250843940298056, 0.000282270121591107, 0.000314346397337869, 0.000346811034408436, 0.000379918194843229, 0.000413368163653855, 
+0.000447462473702899, 0.000481854744689647, 0.000516877376372632, 0.000552121769556217, 0.000587977722826699, 0.000623999763683269, 0.000660700340823140, 0.000697608811340494, 
+0.000735367166639595, 0.000773394513145455, 0.000812374375990954, 0.000851487293223158, 0.000891382011561606, 0.000931001117497454, 0.000970883568971010, 0.00101069578059601, 
+0.00105169774350639, 0.00109588295343421, 0.00113549685886290, 0.00117866383169451, 0.00122111516589616, 0.00126425191781228, 0.00130756685560331, 0.00135135745612168, 
+0.00139547947313276, 0.00143990979242900, 0.00148466890906943, 0.00152967223986802, 0.00157503442488970, 0.00162066455214233, 0.00166668113637550, 0.00171297190814002, 
+0.00175961611250325, 0.00180649714239756, 0.00185367729128575, 0.00190106604757396, 0.00194872602458623, 0.00199658259647564, 0.00204468151104454, 0.00209294223259948, 
+0.00214139247713316, 0.00218996963721177, 0.00223871049041842, 0.00228761026923322, 0.00233669674897580, 0.00238601381783270, 0.00243548525436868, 0.00248518758501967, 
+0.00253485686222383, 0.00258470295716680, 0.00263426676950411, 0.00268414140692153, 0.00273361748949242, 0.00278404942218042, 0.00283412527109201, 0.00288512840396260, 
+0.00293445800039565, 0.00298408012351935, 0.00303527354743087, 0.00308448377238342, 0.00313512165505945, 0.00318474186231553, 0.00323506931441536, 0.00328460350198885, 
+0.00333460199814310, 0.00338400592135627, 0.00343378958762444, 0.00348308365845938, 0.00353265733443406, 0.00358174124596574, 0.00363100325859950, 0.00367976183349975, 
+0.00372865317317631, 0.00377704959506895, 0.00382555699048792, 0.00387355440986243, 0.00392161316870967, 0.00396912079239840, 0.00401664308061543, 0.00406360815542227, 
+0.00411058555257416, 0.00415703554738502, 0.00420348722135172, 0.00424939516950231, 0.00429522177839473, 0.00434042896145653, 0.00438546971668745, 0.00442986742204268, 
+0.00447414198154179, 0.00451784282884279, 0.00456156022215696, 0.00460464825220905, 0.00464779963068343, 0.00468955284268770, 0.00473169248365623, 0.00477223280278857, 
+0.00481424852813673, 0.00485403860423785, 0.00489420623498588, 0.00493373299658250, 0.00497262699146714, 0.00501099496582253, 0.00504887367893452, 0.00508624698184808, 
+0.00512316386346786, 0.00515946810910305, 0.00519528393985568, 0.00523039315379049, 0.00526503059762880, 0.00529893784256351, 0.00533241509486141, 0.00536513893964146, 
+0.00539742537221889, 0.00542889931428335, 0.00545989970145767, 0.00549004893072241, 0.00551972419584414, 0.00554855435612888, 0.00557692734453731, 0.00560444087154133, 
+0.00563147234239205, 0.00565757686128727, 0.00568316642545793, 0.00570777861250159, 0.00573192298998399, 0.00575509504545748, 0.00577790201469266, 0.00579969134709878, 
+0.00582115054736086, 0.00584139221452850, 0.00586128734004678, 0.00587972989282672, 0.00589808690052833, 0.00591540333198250, 0.00593205379805961, 0.00594813880209655, 
+0.00596267377455868, 0.00597741589424509, 0.00599039453248084, 0.00600314980390327, 0.00601494155132523, 0.00602610113531495, 0.00603636342822522, 0.00604578641469852, 
+0.00605437894886202, 0.00606211163669993, 0.00606910653387789, 0.00607525672904290, 0.00608068579068155, 0.00608523210616189, 0.00608901297897988, 0.00609187619324112, 
+0.00609396152547327, 0.00609514946463964, 0.00609558653157114, 0.00609514946463964, 0.00609396152547327, 0.00609187619324112, 0.00608901297897988, 0.00608523210616189, 
+0.00608068579068155, 0.00607525672904290, 0.00606910653387789, 0.00606211163669993, 0.00605437894886202, 0.00604578641469852, 0.00603636342822522, 0.00602610113531495, 
+0.00601494155132523, 0.00600314980390327, 0.00599039453248084, 0.00597741589424509, 0.00596267377455868, 0.00594813880209655, 0.00593205379805961, 0.00591540333198250, 
+0.00589808690052833, 0.00587972989282672, 0.00586128734004678, 0.00584139221452850, 0.00582115054736086, 0.00579969134709878, 0.00577790201469266, 0.00575509504545748, 
+0.00573192298998399, 0.00570777861250159, 0.00568316642545793, 0.00565757686128727, 0.00563147234239205, 0.00560444087154133, 0.00557692734453731, 0.00554855435612888, 
+0.00551972419584414, 0.00549004893072241, 0.00545989970145767, 0.00542889931428335, 0.00539742537221889, 0.00536513893964146, 0.00533241509486141, 0.00529893784256351, 
+0.00526503059762880, 0.00523039315379049, 0.00519528393985568, 0.00515946810910305, 0.00512316386346786, 0.00508624698184808, 0.00504887367893452, 0.00501099496582253, 
+0.00497262699146714, 0.00493373299658250, 0.00489420623498588, 0.00485403860423785, 0.00481424852813673, 0.00477223280278857, 0.00473169248365623, 0.00468955284268770, 
+0.00464779963068343, 0.00460464825220905, 0.00456156022215696, 0.00451784282884279, 0.00447414198154179, 0.00442986742204268, 0.00438546971668745, 0.00434042896145653, 
+0.00429522177839473, 0.00424939516950231, 0.00420348722135172, 0.00415703554738502, 0.00411058555257416, 0.00406360815542227, 0.00401664308061543, 0.00396912079239840, 
+0.00392161316870967, 0.00387355440986243, 0.00382555699048792, 0.00377704959506895, 0.00372865317317631, 0.00367976183349975, 0.00363100325859950, 0.00358174124596574, 
+0.00353265733443406, 0.00348308365845938, 0.00343378958762444, 0.00338400592135627, 0.00333460199814310, 0.00328460350198885, 0.00323506931441536, 0.00318474186231553, 
+0.00313512165505945, 0.00308448377238342, 0.00303527354743087, 0.00298408012351935, 0.00293445800039565, 0.00288512840396260, 0.00283412527109201, 0.00278404942218042, 
+0.00273361748949242, 0.00268414140692153, 0.00263426676950411, 0.00258470295716680, 0.00253485686222383, 0.00248518758501967, 0.00243548525436868, 0.00238601381783270, 
+0.00233669674897580, 0.00228761026923322, 0.00223871049041842, 0.00218996963721177, 0.00214139247713316, 0.00209294223259948, 0.00204468151104454, 0.00199658259647564, 
+0.00194872602458623, 0.00190106604757396, 0.00185367729128575, 0.00180649714239756, 0.00175961611250325, 0.00171297190814002, 0.00166668113637550, 0.00162066455214233, 
+0.00157503442488970, 0.00152967223986802, 0.00148466890906943, 0.00143990979242900, 0.00139547947313276, 0.00135135745612168, 0.00130756685560331, 0.00126425191781228, 
+0.00122111516589616, 0.00117866383169451, 0.00113549685886290, 0.00109588295343421, 0.00105169774350639, 0.00101069578059601, 0.000970883568971010, 0.000931001117497454, 
+0.000891382011561606, 0.000851487293223158, 0.000812374375990954, 0.000773394513145455, 0.000735367166639595, 0.000697608811340494, 0.000660700340823140, 0.000623999763683269, 
+0.000587977722826699, 0.000552121769556217, 0.000516877376372632, 0.000481854744689647, 0.000447462473702899, 0.000413368163653855, 0.000379918194843229, 0.000346811034408436, 
+0.000314346397337869, 0.000282270121591107, 0.000250843940298056, 0.000219864413943603, 0.000189518312913980, 0.000159652043314615, 0.000130337162460535, 0.000101522460573350, 
+7.31488512081353e-05, 4.53634810869086e-05, 1.79220776252956e-05, -8.75000381957480e-06, -3.52380267488923e-05, -6.07302747179699e-05, -8.63859218366082e-05, -0.000110658422989979, 
+-0.000135672987348502, -0.000158038013340163, -0.000182718834161682, -0.000208020109997019, -0.000223063752779904, -0.000247735016213375, -0.000268590084163264, -0.000291306404219105, 
+-0.000310488418329100, -0.000330677260377738, -0.000348312520886679, -0.000366972910244881, -0.000383669251697455, -0.000401443504121743, -0.000417460223522498, -0.000434475552201623, -0.000449698934449484, -0.000465821362319299, -0.000480069347179249, -0.000495193607822494, -0.000508372396429405, -0.000522458425410067, -0.000534508605134922, -0.000547524082087984, -0.000558402454183533, -0.000570367122683910, -0.000580109977377959, -0.000591137773968283, -0.000599831070682668, -0.000610043338194475, -0.000617702529114801, -0.000627154674611770, -0.000633714444974831, -0.000642486260779654, -0.000647892827216824, -0.000656187894249034, -0.000660330946718933, -0.000668435478754011, -0.000670867964963519, -0.000679427972422059, -0.000679003259712778, -0.000692284271988876, -0.000675432749281130, -0.000689238102101884, -0.000707053158406025, -0.000700822488823546, -0.000704184938277025, -0.000699951609455988, -0.000702084347004260, -0.000699587125715329, -0.000701552559161197, -0.000699960260396518, -0.000701562144359961, -0.000700085972408138, -0.000700978318797988, -0.000699128468616956, -0.000699146857491809, -0.000696695831913496, -0.000695783521327534, -0.000692604062270113, -0.000690735948708760, -0.000686779420740873, -0.000684011485494165, -0.000679345019980268, -0.000675811138190482, -0.000670543670441799, -0.000666350155348239, -0.000660536584899437, -0.000655730318423711, -0.000649408145295391, -0.000644060044878972, -0.000637317640388987, -0.000631532852699149, -0.000624441235452662, -0.000618254890021300, -0.000610787449621752, -0.000604183313496965, -0.000596329290925752, -0.000589412242712984, -0.000581179079003090, -0.000574062372234321, -0.000565436854162197, -0.0192878684408550
+};
+
+float filter( float *in, int sampleIndex)
+{
+    unsigned int i, j, k;
+    float out = 0;
+    k = 0;
+    
+    for( j = 0; j < NUM_TAPS; j++ ){
+        k = (sampleIndex - j+SAMPLE_LENGTH-1)&(SAMPLE_LENGTH-1);
+        out += in[ k ] * firCoeffs[ j ];
+    }
+    return out;
+}
+
+//=------------------------------------------ DSP END ------------------------------------------------------------------------------
+
+//-------------------------------------uiu----- QAM ------------------------------------------------------------------------------------
+
+float qam_in(float *in, int sampleIndex, float *sI, float *sQ){
+    float filteredSI = 0;
+    float filteredSQ = 0;
+    int k = 0;
+    for(int i = 0; i < SAMPLE_LENGTH; i++){
+        k = (sampleIndex - i+SAMPLE_LENGTH-1)&(SAMPLE_LENGTH-1);
+        sI[k] = in[k]*cos(2*PI*CARRIER_FREQ*i*TIME_CONST);
+        sQ[k] = -in[k]*sin(2*PI*CARRIER_FREQ*i*TIME_CONST);
+    }
+    filteredSI = filter(sI, sampleIndex);
+    filteredSQ = filter(sQ, sampleIndex);
+    return sqrt(filteredSI*filteredSI+filteredSQ*filteredSQ);
+}
+
+//------------------------------------------- QAM END ------------------------------------------------------------------------------
--- a/realtimeQAM.cpp	Tue Nov 11 07:53:38 2014 +0000
+++ b/realtimeQAM.cpp	Tue Nov 18 08:50:58 2014 +0000
@@ -1,45 +1,53 @@
+#pragma once
 #include "mbed.h"
 #include "math.h"
+#include "MBed_Adafruit_GPS.h"
+
+#include "QAM.h"
 
 #define SAMPLE_LENGTH       512 
 #define SAMPLE_RATE         16666
-#define TIME_CONST          0.00006
-#define NUM_TAPS            513
 #define SIN_LENGTH          500
-#define CARRIER_FREQ        225
 #define OUTAVG_LENGTH       1000
+#define PI                  3.14159265
+ 
+Serial * gps_Serial;
 
 Ticker tick1;
 Ticker tick2;
-AnalogIn AnIn(A0);
+AnalogIn AnLong(A0);
+AnalogIn AnShort(A1);
+AnalogIn AnRef(A2);
 AnalogOut dac0(DAC0_OUT);
 DigitalOut led_red(LED_RED);
 Serial pc(USBTX, USBRX);
 
-float pi = 3.14159;
 int sinRes = 74; // resolution of sinWave 74 for 225 hz
 int freq = 1;
 
 float sinWave[SIN_LENGTH] = {};
 int sinIndex = 0;
 
-float samples[SAMPLE_LENGTH] = {};
+float samplesLong[SAMPLE_LENGTH] = {};
+float samplesShort[SAMPLE_LENGTH] = {};
+float samplesRef[SAMPLE_LENGTH] = {};
 int sampleIndex = 0;
+
 float sI[SAMPLE_LENGTH] = {};
-float filteredSI = 0;
 float sQ[SAMPLE_LENGTH] = {};
-float filteredSQ = 0;
-float output[SAMPLE_LENGTH] = {};
-float avgs[OUTAVG_LENGTH] = {};
+
+float filtered[OUTAVG_LENGTH] = {};
+float filteredRef[OUTAVG_LENGTH] = {};
+
+float totalAVG = 0;
 
 bool newValue = false;
 bool isSampling = true;
 int avgIndex = 0;
 
-
-void print_sin(float *bar){
+void print_array(float *bar,int length){
     int i =0;
-    for(i = 0; i < SAMPLE_LENGTH; i++){
+    for(i = 0; i < length; i++){
         pc.printf("%f, ", bar[i]);
     }
     pc.printf("\n\n\n\n");
@@ -48,9 +56,11 @@
 void tick_out(){
     if(isSampling){
         //read
-        samples[sampleIndex] = AnIn.read();
+        samplesLong[sampleIndex] = AnLong.read();
+        samplesShort[sampleIndex] = AnLong.read();
+        samplesRef[sampleIndex] = AnRef.read();
         sampleIndex++;
-        if(sampleIndex > SAMPLE_LENGTH){
+        if(sampleIndex+1 > SAMPLE_LENGTH){
             sampleIndex = 0;
         }
         //sampleIndex = (sampleIndex+1)&(SAMPLE_LENGTH-1);
@@ -69,7 +79,7 @@
 void create_sinWave(){
     int i = 0;
     for(i = 0; i < sinRes; i++){
-        sinWave[i] = 0.25 * sin(2.0*pi*i/sinRes) + 0.75;
+        sinWave[i] = 0.5 * sin(2.0*PI*i/sinRes) + 0.5;
     }
 }
 
@@ -78,130 +88,83 @@
     create_sinWave();
 }
 
-
-//---------------------------------------------------------DSP----------------------------------------------------------------------------
-
-float firCoeffs[NUM_TAPS] = { -0.0192878684408550, -0.000565436854162197, -0.000574062372234321, -0.000581179079003090, -0.000589412242712984, -0.000596329290925752,
--0.000604183313496965, -0.000610787449621752, -0.000618254890021300, -0.000624441235452662, -0.000631532852699149, -0.000637317640388987, -0.000644060044878972, -0.000649408145295391, 
--0.000655730318423711, -0.000660536584899437, -0.000666350155348239, -0.000670543670441799, -0.000675811138190482, -0.000679345019980268, -0.000684011485494165, -0.000686779420740873,
--0.000690735948708760, -0.000692604062270113, -0.000695783521327534, -0.000696695831913496, -0.000699146857491809, -0.000699128468616956, -0.000700978318797988, -0.000700085972408138,
--0.000701562144359961, -0.000699960260396518, -0.000701552559161197, -0.000699587125715329, -0.000702084347004260, -0.000699951609455988, -0.000704184938277025, -0.000700822488823546, 
--0.000707053158406025, -0.000689238102101884, -0.000675432749281130, -0.000692284271988876, -0.000679003259712778, -0.000679427972422059, -0.000670867964963519, -0.000668435478754011, 
--0.000660330946718933, -0.000656187894249034, -0.000647892827216824, -0.000642486260779654, -0.000633714444974831, -0.000627154674611770, -0.000617702529114801, -0.000610043338194475, 
--0.000599831070682668, -0.000591137773968283, -0.000580109977377959, -0.000570367122683910, -0.000558402454183533, -0.000547524082087984, -0.000534508605134922, -0.000522458425410067, 
--0.000508372396429405, -0.000495193607822494, -0.000480069347179249, -0.000465821362319299, -0.000449698934449484, -0.000434475552201623, -0.000417460223522498, -0.000401443504121743, 
--0.000383669251697455, -0.000366972910244881, -0.000348312520886679, -0.000330677260377738, -0.000310488418329100, -0.000291306404219105, -0.000268590084163264, -0.000247735016213375, 
--0.000223063752779904, -0.000208020109997019, -0.000182718834161682, -0.000158038013340163, -0.000135672987348502, -0.000110658422989979, -8.63859218366082e-05, -6.07302747179699e-05, 
--3.52380267488923e-05, -8.75000381957480e-06, 1.79220776252956e-05, 4.53634810869086e-05, 7.31488512081353e-05, 0.000101522460573350, 0.000130337162460535, 0.000159652043314615, 
-0.000189518312913980, 0.000219864413943603, 0.000250843940298056, 0.000282270121591107, 0.000314346397337869, 0.000346811034408436, 0.000379918194843229, 0.000413368163653855, 
-0.000447462473702899, 0.000481854744689647, 0.000516877376372632, 0.000552121769556217, 0.000587977722826699, 0.000623999763683269, 0.000660700340823140, 0.000697608811340494, 
-0.000735367166639595, 0.000773394513145455, 0.000812374375990954, 0.000851487293223158, 0.000891382011561606, 0.000931001117497454, 0.000970883568971010, 0.00101069578059601, 
-0.00105169774350639, 0.00109588295343421, 0.00113549685886290, 0.00117866383169451, 0.00122111516589616, 0.00126425191781228, 0.00130756685560331, 0.00135135745612168, 
-0.00139547947313276, 0.00143990979242900, 0.00148466890906943, 0.00152967223986802, 0.00157503442488970, 0.00162066455214233, 0.00166668113637550, 0.00171297190814002, 
-0.00175961611250325, 0.00180649714239756, 0.00185367729128575, 0.00190106604757396, 0.00194872602458623, 0.00199658259647564, 0.00204468151104454, 0.00209294223259948, 
-0.00214139247713316, 0.00218996963721177, 0.00223871049041842, 0.00228761026923322, 0.00233669674897580, 0.00238601381783270, 0.00243548525436868, 0.00248518758501967, 
-0.00253485686222383, 0.00258470295716680, 0.00263426676950411, 0.00268414140692153, 0.00273361748949242, 0.00278404942218042, 0.00283412527109201, 0.00288512840396260, 
-0.00293445800039565, 0.00298408012351935, 0.00303527354743087, 0.00308448377238342, 0.00313512165505945, 0.00318474186231553, 0.00323506931441536, 0.00328460350198885, 
-0.00333460199814310, 0.00338400592135627, 0.00343378958762444, 0.00348308365845938, 0.00353265733443406, 0.00358174124596574, 0.00363100325859950, 0.00367976183349975, 
-0.00372865317317631, 0.00377704959506895, 0.00382555699048792, 0.00387355440986243, 0.00392161316870967, 0.00396912079239840, 0.00401664308061543, 0.00406360815542227, 
-0.00411058555257416, 0.00415703554738502, 0.00420348722135172, 0.00424939516950231, 0.00429522177839473, 0.00434042896145653, 0.00438546971668745, 0.00442986742204268, 
-0.00447414198154179, 0.00451784282884279, 0.00456156022215696, 0.00460464825220905, 0.00464779963068343, 0.00468955284268770, 0.00473169248365623, 0.00477223280278857, 
-0.00481424852813673, 0.00485403860423785, 0.00489420623498588, 0.00493373299658250, 0.00497262699146714, 0.00501099496582253, 0.00504887367893452, 0.00508624698184808, 
-0.00512316386346786, 0.00515946810910305, 0.00519528393985568, 0.00523039315379049, 0.00526503059762880, 0.00529893784256351, 0.00533241509486141, 0.00536513893964146, 
-0.00539742537221889, 0.00542889931428335, 0.00545989970145767, 0.00549004893072241, 0.00551972419584414, 0.00554855435612888, 0.00557692734453731, 0.00560444087154133, 
-0.00563147234239205, 0.00565757686128727, 0.00568316642545793, 0.00570777861250159, 0.00573192298998399, 0.00575509504545748, 0.00577790201469266, 0.00579969134709878, 
-0.00582115054736086, 0.00584139221452850, 0.00586128734004678, 0.00587972989282672, 0.00589808690052833, 0.00591540333198250, 0.00593205379805961, 0.00594813880209655, 
-0.00596267377455868, 0.00597741589424509, 0.00599039453248084, 0.00600314980390327, 0.00601494155132523, 0.00602610113531495, 0.00603636342822522, 0.00604578641469852, 
-0.00605437894886202, 0.00606211163669993, 0.00606910653387789, 0.00607525672904290, 0.00608068579068155, 0.00608523210616189, 0.00608901297897988, 0.00609187619324112, 
-0.00609396152547327, 0.00609514946463964, 0.00609558653157114, 0.00609514946463964, 0.00609396152547327, 0.00609187619324112, 0.00608901297897988, 0.00608523210616189, 
-0.00608068579068155, 0.00607525672904290, 0.00606910653387789, 0.00606211163669993, 0.00605437894886202, 0.00604578641469852, 0.00603636342822522, 0.00602610113531495, 
-0.00601494155132523, 0.00600314980390327, 0.00599039453248084, 0.00597741589424509, 0.00596267377455868, 0.00594813880209655, 0.00593205379805961, 0.00591540333198250, 
-0.00589808690052833, 0.00587972989282672, 0.00586128734004678, 0.00584139221452850, 0.00582115054736086, 0.00579969134709878, 0.00577790201469266, 0.00575509504545748, 
-0.00573192298998399, 0.00570777861250159, 0.00568316642545793, 0.00565757686128727, 0.00563147234239205, 0.00560444087154133, 0.00557692734453731, 0.00554855435612888, 
-0.00551972419584414, 0.00549004893072241, 0.00545989970145767, 0.00542889931428335, 0.00539742537221889, 0.00536513893964146, 0.00533241509486141, 0.00529893784256351, 
-0.00526503059762880, 0.00523039315379049, 0.00519528393985568, 0.00515946810910305, 0.00512316386346786, 0.00508624698184808, 0.00504887367893452, 0.00501099496582253, 
-0.00497262699146714, 0.00493373299658250, 0.00489420623498588, 0.00485403860423785, 0.00481424852813673, 0.00477223280278857, 0.00473169248365623, 0.00468955284268770, 
-0.00464779963068343, 0.00460464825220905, 0.00456156022215696, 0.00451784282884279, 0.00447414198154179, 0.00442986742204268, 0.00438546971668745, 0.00434042896145653, 
-0.00429522177839473, 0.00424939516950231, 0.00420348722135172, 0.00415703554738502, 0.00411058555257416, 0.00406360815542227, 0.00401664308061543, 0.00396912079239840, 
-0.00392161316870967, 0.00387355440986243, 0.00382555699048792, 0.00377704959506895, 0.00372865317317631, 0.00367976183349975, 0.00363100325859950, 0.00358174124596574, 
-0.00353265733443406, 0.00348308365845938, 0.00343378958762444, 0.00338400592135627, 0.00333460199814310, 0.00328460350198885, 0.00323506931441536, 0.00318474186231553, 
-0.00313512165505945, 0.00308448377238342, 0.00303527354743087, 0.00298408012351935, 0.00293445800039565, 0.00288512840396260, 0.00283412527109201, 0.00278404942218042, 
-0.00273361748949242, 0.00268414140692153, 0.00263426676950411, 0.00258470295716680, 0.00253485686222383, 0.00248518758501967, 0.00243548525436868, 0.00238601381783270, 
-0.00233669674897580, 0.00228761026923322, 0.00223871049041842, 0.00218996963721177, 0.00214139247713316, 0.00209294223259948, 0.00204468151104454, 0.00199658259647564, 
-0.00194872602458623, 0.00190106604757396, 0.00185367729128575, 0.00180649714239756, 0.00175961611250325, 0.00171297190814002, 0.00166668113637550, 0.00162066455214233, 
-0.00157503442488970, 0.00152967223986802, 0.00148466890906943, 0.00143990979242900, 0.00139547947313276, 0.00135135745612168, 0.00130756685560331, 0.00126425191781228, 
-0.00122111516589616, 0.00117866383169451, 0.00113549685886290, 0.00109588295343421, 0.00105169774350639, 0.00101069578059601, 0.000970883568971010, 0.000931001117497454, 
-0.000891382011561606, 0.000851487293223158, 0.000812374375990954, 0.000773394513145455, 0.000735367166639595, 0.000697608811340494, 0.000660700340823140, 0.000623999763683269, 
-0.000587977722826699, 0.000552121769556217, 0.000516877376372632, 0.000481854744689647, 0.000447462473702899, 0.000413368163653855, 0.000379918194843229, 0.000346811034408436, 
-0.000314346397337869, 0.000282270121591107, 0.000250843940298056, 0.000219864413943603, 0.000189518312913980, 0.000159652043314615, 0.000130337162460535, 0.000101522460573350, 
-7.31488512081353e-05, 4.53634810869086e-05, 1.79220776252956e-05, -8.75000381957480e-06, -3.52380267488923e-05, -6.07302747179699e-05, -8.63859218366082e-05, -0.000110658422989979, 
--0.000135672987348502, -0.000158038013340163, -0.000182718834161682, -0.000208020109997019, -0.000223063752779904, -0.000247735016213375, -0.000268590084163264, -0.000291306404219105, 
--0.000310488418329100, -0.000330677260377738, -0.000348312520886679, -0.000366972910244881, -0.000383669251697455, -0.000401443504121743, -0.000417460223522498, -0.000434475552201623, -0.000449698934449484, -0.000465821362319299, -0.000480069347179249, -0.000495193607822494, -0.000508372396429405, -0.000522458425410067, -0.000534508605134922, -0.000547524082087984, -0.000558402454183533, -0.000570367122683910, -0.000580109977377959, -0.000591137773968283, -0.000599831070682668, -0.000610043338194475, -0.000617702529114801, -0.000627154674611770, -0.000633714444974831, -0.000642486260779654, -0.000647892827216824, -0.000656187894249034, -0.000660330946718933, -0.000668435478754011, -0.000670867964963519, -0.000679427972422059, -0.000679003259712778, -0.000692284271988876, -0.000675432749281130, -0.000689238102101884, -0.000707053158406025, -0.000700822488823546, -0.000704184938277025, -0.000699951609455988, -0.000702084347004260, -0.000699587125715329, -0.000701552559161197, -0.000699960260396518, -0.000701562144359961, -0.000700085972408138, -0.000700978318797988, -0.000699128468616956, -0.000699146857491809, -0.000696695831913496, -0.000695783521327534, -0.000692604062270113, -0.000690735948708760, -0.000686779420740873, -0.000684011485494165, -0.000679345019980268, -0.000675811138190482, -0.000670543670441799, -0.000666350155348239, -0.000660536584899437, -0.000655730318423711, -0.000649408145295391, -0.000644060044878972, -0.000637317640388987, -0.000631532852699149, -0.000624441235452662, -0.000618254890021300, -0.000610787449621752, -0.000604183313496965, -0.000596329290925752, -0.000589412242712984, -0.000581179079003090, -0.000574062372234321, -0.000565436854162197, -0.0192878684408550
-};
-
-float filter( float *in)
-{
-    float *taps = firCoeffs;
-    unsigned int i, j, k;
-    float out[SAMPLE_LENGTH] = {};
-    k = 0;
-    
-    
-    for( i = 0; i < SAMPLE_LENGTH - NUM_TAPS + 1; i++ )
-    {
-        out[ i ] = 0.0;
-        for( j = 0; j < NUM_TAPS; j++ ){
-            k = (i + sampleIndex - j)&(SAMPLE_LENGTH-1);
-            out[ i ] += in[ k ] * taps[ j ];
-        }
-    }
-    return out[0];
-}
-
-//=------------------------------------------ DSP END ------------------------------------------------------------------------------
-
-//-------------------------------------uiu----- QAM ------------------------------------------------------------------------------------
-
-float qam_in(){
-    int j = 0;
-    for(int i = 0; i < SAMPLE_LENGTH; i++){
-        j = (i+sampleIndex)&(SAMPLE_LENGTH-1);
-        sI[i] = samples[i]*cos(2*pi*CARRIER_FREQ*i*TIME_CONST);
-        sQ[i] = -samples[i]*sin(2*pi*CARRIER_FREQ*i*TIME_CONST);
-    }
-    filteredSI = filter(sI);
-    filteredSQ = filter(sQ);
-    return sqrt(filteredSI*filteredSI + filteredSQ*filteredSQ);
-}
-
-//------------------------------------------- QAM END ------------------------------------------------------------------------------
-
 void print_values(){
     printf("\n\r--------------------------------------SAMPLES-----------------------------------\n\r \r\n");
-    print_sin(avgs);
+    print_array(samplesLong, SAMPLE_LENGTH);
     printf("\n\r-------------------------------------------SI-------------------------------------\n\r \r\n");
-    print_sin(sI);
+    print_array(sI, SAMPLE_LENGTH);
     printf("\n\r-----------------------------------------SQ--------------------------------------\n\r \r\n");
-    print_sin(sQ);
+    print_array(sQ, SAMPLE_LENGTH);
 }
 
 int main(){
     pc.baud(115200);
     
-    tick1.attach(&tick_out, 0.00006); // below 0.00005 the board can no longer output and read
+    gps_Serial = new Serial(D1,D0); //serial object for use w/ GPS
+    Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class
+    char c; //when read via Adafruit_GPS::read(), the class returns single character stored here
+    Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info?
+    const int refresh_Time = 10000; //refresh time in ms
+    
+    myGPS.begin(9600);  //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *)
+                        //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf
+    
+    myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //these commands are defined in MBed_Adafruit_GPS.h; a link is provided there for command creation
+    myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
+    myGPS.sendCommand(PGCMD_ANTENNA);
+    
+    tick1.attach(&tick_out, 0.06); // below 0.00005 the board can no longer output and read
     //tick2.attach(&print_values, 20);
     
     set_Values(225);
     pc.printf("Set values\n");
     
+    float filteredLongTemp = 0;
+    float filteredShortTemp = 0;
+    float filteredRefTemp = 0;
+    
+    refresh_Timer.start();  //starts the clock on the timer
+    
     while(1){
-        if(newValue){
-           avgs[avgIndex] = qam_in();
+        //isSampling = false;
+         c = myGPS.read();   //queries the GPS
+        
+        //if (c) { pc.printf("%c", c); } //this line will echo the GPS data if not paused
+        
+        //check if we recieved a new message from GPS, if so, attempt to parse it,
+        if ( myGPS.newNMEAreceived() ) {
+            if ( !myGPS.parse(myGPS.lastNMEA()) ) {
+                continue;   
+            }    
+        }
+        
+        //check if enough time has passed to warrant printing GPS info to screen
+        //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing
+        if (refresh_Timer.read_ms() >= refresh_Time) {
+            refresh_Timer.reset();
+            pc.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);   
+            pc.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year);
+            //pc.printf("Fix: %d\n", (int) myGPS.fix);
+            //pc.printf("Quality: %d\n", (int) myGPS.fixquality);
+            if (myGPS.fix) {
+                pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+            }
+        }
+        //isSampling = true;
+        if(newValue){ //newValue){ 
+           filteredLongTemp = qam_in(samplesLong, sampleIndex, sI, sQ); 
+           filtered[avgIndex] = filteredLongTemp;
+           filteredRefTemp = qam_in(samplesRef, sampleIndex, sI, sQ);
+           filteredRef[avgIndex] = filteredRefTemp;
+           pc.printf("%f, ", filteredLongTemp);
            avgIndex++;
-           if(avgIndex > OUTAVG_LENGTH){
-               pc.printf("you");
+           if(avgIndex+1 > OUTAVG_LENGTH){
+               isSampling = false;
+               //print_values();
+               print_array(filtered,  OUTAVG_LENGTH);
                avgIndex = 0;
-            }
+               isSampling = true;
+           }
             newValue = false;
         }
     }