for Danillo
Dependencies: MBed_Adafruit-GPS-Library SDFileSystem mbed
Diff: QAM.h
- Revision:
- 2:abcf77d0e77d
- Parent:
- 1:f5770d9636b4
- Child:
- 3:0cc40383d016
--- a/QAM.h Tue Nov 18 08:50:58 2014 +0000 +++ b/QAM.h Thu Dec 11 01:23:24 2014 +0000 @@ -1,99 +1,72 @@ #include "mbed.h" #include "math.h" -#define SAMPLE_LENGTH 512 +#define SAMPLE_LENGTH 2000 #define NUM_TAPS 513 -#define CARRIER_FREQ 225 -#define TIME_CONST 0.00006 +#define CARRIER_FREQ 220 +#define TIME_CONST 0.0001 #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 -}; +bool decimate = false; + +float firCoeffs[NUM_TAPS] = {-0.0144708808511496,-0.000385188817745075,-0.000390533183235675,-0.000394742906792089,-0.000399769196519628,-0.000403738202294335,-0.000408404623158276,-0.000412113149650395,-0.000416462833527476,-0.000419815012719482,-0.000423797959228978,-0.000426739337854087,-0.000430334330303594,-0.000432832690421492,-0.000436010304838419,-0.000438015762483701,-0.000440725998487324,-0.000442176271462813,-0.000444366451120004,-0.000445200741523877,-0.000446824764367193,-0.000446985068265349,-0.000448006554506719,-0.000447442784206942,-0.000447849219199270,-0.000446533842477948,-0.000446356250904501,-0.000444298930233344,-0.000443635712144896,-0.000440904172137380,-0.000439959781942889,-0.000436697184341028,-0.000435806956375018,-0.000432172615546733,-0.000431753345765173,-0.000427687598858029,-0.000428156810812652,-0.000422747252741829,-0.000424187630414963,-0.000407818792155013,-0.000395501352613792,-0.000405744503950700,-0.000392851507058367,-0.000390382687328383,-0.000381121528334916,-0.000376496114768088,-0.000367538945283741,-0.000361525919288397,-0.000352310773450881,-0.000345231412211433,-0.000335566815920174,-0.000327541463775560,-0.000317294849082828,-0.000308353744912893,-0.000297429505735636,-0.000287581380689517,-0.000275914761004970,-0.000265156646491960,-0.000252692261710763,-0.000241008558077738,-0.000227700089453720,-0.000215083331568167,-0.000200913782464340,-0.000187389392522164,-0.000172384694451466,-0.000158020178787410,-0.000142244665767066,-0.000127136823721230,-0.000110658475023229,-9.48790548136458e-05,-7.76831002440304e-05,-6.11819123150781e-05,-4.30660620622803e-05,-2.56168041232741e-05,-6.17332989349961e-06,1.25088872664492e-05,3.37927012878936e-05,5.35608705831692e-05,7.59589602239430e-05,9.15368291316554e-05,0.000115204777102917,0.000138069211971015,0.000159190880367532,0.000182373449206352,0.000205067466595210,0.000228860953939147,0.000252562953392044,0.000277043582173064,0.000301679014228284,0.000326937646605074,0.000352496019331738,0.000378568482119590,0.000405024475185201,0.000431919761467725,0.000459260045317933,0.000486996257677674,0.000515223422553390,0.000543812348041683,0.000572911638300866,0.000602328160312027,0.000632248178590089,0.000662431004457176,0.000693100970238447,0.000723983335774392,0.000755351502448320,0.000786905176937580,0.000818981905467808,0.000851254211738706,0.000884129083715379,0.000917225959710777,0.000951002817600966,0.000984976999461651,0.00101962720509619,0.00105433282442391,0.00108958012424409,0.00112464418634772,0.00115993840154260,0.00119539198931307,0.00123186816927046,0.00127036077901721,0.00130541180260479,0.00134335225448012,0.00138072879053652,0.00141863315366209,0.00145663029979914,0.00149499706458300,0.00153361610136926,0.00157251046039164,0.00161168223712593,0.00165107252541929,0.00169074663426727,0.00173062458634377,0.00177079136483371,0.00181115593295544,0.00185179221443832,0.00189260160550475,0.00193364149890840,0.00197481806389987,0.00201618182472885,0.00205765641294420,0.00209929421544075,0.00214104214683175,0.00218295189552009,0.00222499505616725,0.00226720655336976,0.00230957893654704,0.00235209893435240,0.00239478098228574,0.00243752682581544,0.00248040445148945,0.00252320826984942,0.00256614456884563,0.00260887923650444,0.00265189493075013,0.00269464123994112,0.00273811141960323,0.00278127146884799,0.00282487273216248,0.00286725582554936,0.00291011668741703,0.00295400852337480,0.00299631315283477,0.00303968228399754,0.00308228214271367,0.00312544335611165,0.00316800503060222,0.00321092060767114,0.00325335212983191,0.00329604768194258,0.00333833065815270,0.00338080571964383,0.00342287984676659,0.00346506666392088,0.00350683252327144,0.00354864820837975,0.00359002966433764,0.00363143184222281,0.00367240631021559,0.00371339474804699,0.00375396921299398,0.00379455066286027,0.00383471907116473,0.00387486722320318,0.00391457835212350,0.00395421450957656,0.00399336963891983,0.00403239345178008,0.00407090689986944,0.00410927413031459,0.00414714356884360,0.00418491195887327,0.00422220071777701,0.00425944291055203,0.00429609837010503,0.00433271517977119,0.00436816038563848,0.00440392829477787,0.00443863216787577,0.00447419332340360,0.00450790720060468,0.00454199779778719,0.00457557942718267,0.00460866745561361,0.00464128935709596,0.00467348005622625,0.00470521813258529,0.00473655480891466,0.00476738158613443,0.00479778554290533,0.00482760230079293,0.00485697947442532,0.00488572614267468,0.00491404812783003,0.00494172982871532,0.00496901245787740,0.00499565014615655,0.00502189761027694,0.00504747871309519,0.00507265469059348,0.00509712658822537,0.00512116774916649,0.00514446385204792,0.00516731571406126,0.00518939504399896,0.00521104829385877,0.00523192156106234,0.00525241391733289,0.00527210766449571,0.00529145309701562,0.00530992168933153,0.00532803731039166,0.00534513592720032,0.00536190019920468,0.00537753105163574,0.00539305759593844,0.00540779717266560,0.00542178330942988,0.00543520553037524,0.00544764194637537,0.00546016823500395,0.00547122210264206,0.00548202730715275,0.00549201155081391,0.00550147471949458,0.00551019050180912,0.00551821896806359,0.00552552472800016,0.00553208775818348,0.00553797790780664,0.00554313324391842,0.00554766040295363,0.00555146159604192,0.00555464252829552,0.00555708399042487,0.00555888703092933,0.00555992824956775,0.00556031381711364,0.00555992824956775,0.00555888703092933,0.00555708399042487,0.00555464252829552,0.00555146159604192,0.00554766040295363,0.00554313324391842,0.00553797790780664,0.00553208775818348,0.00552552472800016,0.00551821896806359,0.00551019050180912,0.00550147471949458,0.00549201155081391,0.00548202730715275,0.00547122210264206,0.00546016823500395,0.00544764194637537,0.00543520553037524,0.00542178330942988,0.00540779717266560,0.00539305759593844,0.00537753105163574,0.00536190019920468,0.00534513592720032,0.00532803731039166,0.00530992168933153,0.00529145309701562,0.00527210766449571,0.00525241391733289,0.00523192156106234,0.00521104829385877,0.00518939504399896,0.00516731571406126,0.00514446385204792,0.00512116774916649,0.00509712658822537,0.00507265469059348,0.00504747871309519,0.00502189761027694,0.00499565014615655,0.00496901245787740,0.00494172982871532,0.00491404812783003,0.00488572614267468,0.00485697947442532,0.00482760230079293,0.00479778554290533,0.00476738158613443,0.00473655480891466,0.00470521813258529,0.00467348005622625,0.00464128935709596,0.00460866745561361,0.00457557942718267,0.00454199779778719,0.00450790720060468,0.00447419332340360,0.00443863216787577,0.00440392829477787,0.00436816038563848,0.00433271517977119,0.00429609837010503,0.00425944291055203,0.00422220071777701,0.00418491195887327,0.00414714356884360,0.00410927413031459,0.00407090689986944,0.00403239345178008,0.00399336963891983,0.00395421450957656,0.00391457835212350,0.00387486722320318,0.00383471907116473,0.00379455066286027,0.00375396921299398,0.00371339474804699,0.00367240631021559,0.00363143184222281,0.00359002966433764,0.00354864820837975,0.00350683252327144,0.00346506666392088,0.00342287984676659,0.00338080571964383,0.00333833065815270,0.00329604768194258,0.00325335212983191,0.00321092060767114,0.00316800503060222,0.00312544335611165,0.00308228214271367,0.00303968228399754,0.00299631315283477,0.00295400852337480,0.00291011668741703,0.00286725582554936,0.00282487273216248,0.00278127146884799,0.00273811141960323,0.00269464123994112,0.00265189493075013,0.00260887923650444,0.00256614456884563,0.00252320826984942,0.00248040445148945,0.00243752682581544,0.00239478098228574,0.00235209893435240,0.00230957893654704,0.00226720655336976,0.00222499505616725,0.00218295189552009,0.00214104214683175,0.00209929421544075,0.00205765641294420,0.00201618182472885,0.00197481806389987,0.00193364149890840,0.00189260160550475,0.00185179221443832,0.00181115593295544,0.00177079136483371,0.00173062458634377,0.00169074663426727,0.00165107252541929,0.00161168223712593,0.00157251046039164,0.00153361610136926,0.00149499706458300,0.00145663029979914,0.00141863315366209,0.00138072879053652,0.00134335225448012,0.00130541180260479,0.00127036077901721,0.00123186816927046,0.00119539198931307,0.00115993840154260,0.00112464418634772,0.00108958012424409,0.00105433282442391,0.00101962720509619,0.000984976999461651,0.000951002817600966,0.000917225959710777,0.000884129083715379,0.000851254211738706,0.000818981905467808,0.000786905176937580,0.000755351502448320,0.000723983335774392,0.000693100970238447,0.000662431004457176,0.000632248178590089,0.000602328160312027,0.000572911638300866,0.000543812348041683,0.000515223422553390,0.000486996257677674,0.000459260045317933,0.000431919761467725,0.000405024475185201,0.000378568482119590,0.000352496019331738,0.000326937646605074,0.000301679014228284,0.000277043582173064,0.000252562953392044,0.000228860953939147,0.000205067466595210,0.000182373449206352,0.000159190880367532,0.000138069211971015,0.000115204777102917,9.15368291316554e-05,7.59589602239430e-05,5.35608705831692e-05,3.37927012878936e-05,1.25088872664492e-05,-6.17332989349961e-06,-2.56168041232741e-05,-4.30660620622803e-05,-6.11819123150781e-05,-7.76831002440304e-05,-9.48790548136458e-05,-0.000110658475023229,-0.000127136823721230,-0.000142244665767066,-0.000158020178787410,-0.000172384694451466,-0.000187389392522164,-0.000200913782464340,-0.000215083331568167,-0.000227700089453720,-0.000241008558077738,-0.000252692261710763,-0.000265156646491960,-0.000275914761004970,-0.000287581380689517,-0.000297429505735636,-0.000308353744912893,-0.000317294849082828,-0.000327541463775560,-0.000335566815920174,-0.000345231412211433,-0.000352310773450881,-0.000361525919288397,-0.000367538945283741,-0.000376496114768088,-0.000381121528334916,-0.000390382687328383,-0.000392851507058367,-0.000405744503950700,-0.000395501352613792,-0.000407818792155013,-0.000424187630414963,-0.000422747252741829,-0.000428156810812652,-0.000427687598858029,-0.000431753345765173,-0.000432172615546733,-0.000435806956375018,-0.000436697184341028,-0.000439959781942889,-0.000440904172137380,-0.000443635712144896,-0.000444298930233344,-0.000446356250904501,-0.000446533842477948,-0.000447849219199270,-0.000447442784206942,-0.000448006554506719,-0.000446985068265349,-0.000446824764367193,-0.000445200741523877,-0.000444366451120004,-0.000442176271462813,-0.000440725998487324,-0.000438015762483701,-0.000436010304838419,-0.000432832690421492,-0.000430334330303594,-0.000426739337854087,-0.000423797959228978,-0.000419815012719482,-0.000416462833527476,-0.000412113149650395,-0.000408404623158276,-0.000403738202294335,-0.000399769196519628,-0.000394742906792089,-0.000390533183235675,-0.000385188817745075,-0.0144708808511496}; + +float decimatedFIR[NUM_TAPS] = { + -0.00140781220330616, -0.000139680243382954, -0.000146404247129533, -0.000153380260487868, -0.000160358054902775, -0.000167594998778230, -0.000174826685798307, -0.000182327525649789, -0.000189824946371562, -0.000197598785182405, -0.000205384397733665, -0.000213427887696411, -0.000221470958675043, -0.000229772807811465, -0.000238049618312475, -0.000246567591545414, -0.000255034938034355, -0.000263721934820429, -0.000272321168079272, -0.000281131948836483, -0.000289843221436450, -0.000298765562188730, -0.000307585101529890, -0.000316650955348761, -0.000325618969853878, -0.000334855342718481, -0.000343975936992935, -0.000353357974172664, -0.000362544634184449, -0.000371941004210931, -0.000381024111936636, -0.000390255657684682, -0.000399088156676523, -0.000408207165488917, -0.000417020789208928, -0.000426496295026695, -0.000435648489505876, -0.000445439550183399, -0.000453172230024789, -0.000461660268788097, -0.000471635316163514, -0.000479499372082719, -0.000488476288769188, -0.000496672136936235, -0.000505189086295845, -0.000513218974024207, -0.000521360025966030, -0.000529114793277384, -0.000536854478912505, -0.000544249696796157, -0.000551583323282700, -0.000558584824336864, -0.000565477747623975, -0.000572054035563717, -0.000578468965223928, -0.000584552174690912, -0.000590425893175921, -0.000595949081082807, -0.000601200253942484, -0.000606082637475742, -0.000610668920187883, -0.000614882217079890, -0.000618778259830580, -0.000622308694572542, -0.000625497626837207, -0.000628297254986301, -0.000630695498825983, -0.000632650443402028, -0.000634130868631187, -0.000635164264832922, -0.000635761026451823, -0.000635967181300185, -0.000635724143226076, -0.000635003078358038, -0.000633597273946612, -0.000631631482873466, -0.000629134411213307, -0.000626603803355716, -0.000622782505082791, -0.000618727770214896, -0.000614148178145395, -0.000608790885954232, -0.000602983809420617, -0.000596430516098165, -0.000589338175725318, -0.000581501779768414, -0.000573069125627472, -0.000563911455667894, -0.000554101021810418, -0.000543559747075306, -0.000532354016357830, -0.000520395055447092, -0.000507745859224283, -0.000494335043762342, -0.000480203234628012, -0.000465276778512382, -0.000449606833404642, -0.000433138840464187, -0.000415906028795478, -0.000397866600246355, -0.000379060346696341, -0.000359436786270860, -0.000339015894938986, -0.000317740699425894, -0.000295627067522847, -0.000272641014736395, -0.000248836401356591, -0.000224199400086325, -0.000198742160896760, -0.000172407601775126, -0.000145190671156311, -0.000117045347359629, -8.80751272068533e-05, -5.82740696285398e-05, -2.76411999534569e-05, 4.04401613033564e-06, 3.65984391749181e-05, 6.98079135743859e-05, 0.000104194913744367, 0.000139265001871243, 0.000175323843452667, 0.000212225660414214, 0.000250041672541152, 0.000288731639017152, 0.000328303067272255, 0.000368768031558810, 0.000410107369479582, 0.000452307466383416, 0.000495395175265087, 0.000539331552961722, 0.000584135271449011, 0.000629794805723046, 0.000676324434358735, 0.000723692579251588, 0.000771907381438338, 0.000820953090117775, 0.000870821511917016, 0.000921484852485368, 0.000972954215880515, 0.00102521798364415, 0.00107828503717442, 0.00113213502585819, 0.00118675164943918, 0.00124209904820303, 0.00129817383913273, 0.00135497990267232, 0.00141251944417704, 0.00147077043048314, 0.00152970713186801, 0.00158928340180831, 0.00164949846708349, 0.00171039657639008, 0.00177194862277590, 0.00183409607086238, 0.00189672745561680, 0.00196007035416052, 0.00202391903684120, 0.00208824391132099, 0.00215319633049186, 0.00221854583847226, 0.00228445797865602, 0.00235076297219949, 0.00241756988507026, 0.00248475343989325, 0.00255234987121874, 0.00262031356572019, 0.00268863560479671, 0.00275726089169212, 0.00282622747425243, 0.00289545679576046, 0.00296496495561586, 0.00303468793848164, 0.00310465029422548, 0.00317476753523368, 0.00324505506219278, 0.00331546217344017, 0.00338601015522827, 0.00345663256658588, 0.00352733575600996, 0.00359804284729557, 0.00366876468102628, 0.00373945014055407, 0.00381012169646394, 0.00388070876734894, 0.00395120444528220, 0.00402154279639318, 0.00409173171254159, 0.00416173124721950, 0.00423156818582252, 0.00430114706446985, 0.00437044863608342, 0.00443943048745045, 0.00450815205643151, 0.00457651665688236, 0.00464443753488891, 0.00471204573900059, 0.00477916483350526, 0.00484583308784604, 0.00491204135096321, 0.00497770104244254, 0.00504286516134843, 0.00510739858102646, 0.00517139743734042, 0.00523472192447666, 0.00529741817506733, 0.00535943867085980, 0.00542076991779664, 0.00548134825113098, 0.00554120085527070, 0.00560025408386779, 0.00565850878091468, 0.00571590115366314, 0.00577247133665566, 0.00582814600600365, 0.00588293478428767, 0.00593676502246772, 0.00598965488930740, 0.00604154696810768, 0.00609247220464676, 0.00614236085714198, 0.00619121945304127, 0.00623897597939753, 0.00628566236877679, 0.00633122339801930, 0.00637568755846381, 0.00641898891954461, 0.00646112437618597, 0.00650203246575002, 0.00654176987317808, 0.00658027498541388, 0.00661755068828877, 0.00665350784741265, 0.00668825437518407, 0.00672167727481079, 0.00675377453504693, 0.00678459858417483, 0.00681404651496248, 0.00684217008450498, 0.00686891180782161, 0.00689428165948642, 0.00691827851213634, 0.00694083019733330, 0.00696204422560743, 0.00698178676368780, 0.00700012584755218, 0.00701702448731868, 0.00703249360499076, 0.00704647619369649, 0.00705902447003037, 0.00707010915038278, 0.00707974715357706, 0.00708787974661498, 0.00709455322702824, 0.00709972877882829, 0.00710345327398210, 0.00710568171010634, 0.00710644118250910, 0.00710568171010634, 0.00710345327398210, 0.00709972877882829, 0.00709455322702824, 0.00708787974661498, 0.00707974715357706, 0.00707010915038278, 0.00705902447003037, 0.00704647619369649, 0.00703249360499076, 0.00701702448731868, 0.00700012584755218, 0.00698178676368780, 0.00696204422560743, 0.00694083019733330, 0.00691827851213634, 0.00689428165948642, 0.00686891180782161, 0.00684217008450498, 0.00681404651496248, 0.00678459858417483, 0.00675377453504693, 0.00672167727481079, 0.00668825437518407, 0.00665350784741265, 0.00661755068828877, 0.00658027498541388, 0.00654176987317808, 0.00650203246575002, 0.00646112437618597, 0.00641898891954461, 0.00637568755846381, 0.00633122339801930, 0.00628566236877679, 0.00623897597939753, 0.00619121945304127, 0.00614236085714198, 0.00609247220464676, 0.00604154696810768, 0.00598965488930740, 0.00593676502246772, 0.00588293478428767, 0.00582814600600365, 0.00577247133665566, 0.00571590115366314, 0.00565850878091468, 0.00560025408386779, 0.00554120085527070, 0.00548134825113098, 0.00542076991779664, 0.00535943867085980, 0.00529741817506733, 0.00523472192447666, 0.00517139743734042, 0.00510739858102646, 0.00504286516134843, 0.00497770104244254, 0.00491204135096321, 0.00484583308784604, 0.00477916483350526, 0.00471204573900059, 0.00464443753488891, 0.00457651665688236, 0.00450815205643151, 0.00443943048745045, 0.00437044863608342, 0.00430114706446985, 0.00423156818582252, 0.00416173124721950, 0.00409173171254159, 0.00402154279639318, 0.00395120444528220, 0.00388070876734894, 0.00381012169646394, 0.00373945014055407, 0.00366876468102628, 0.00359804284729557, 0.00352733575600996, 0.00345663256658588, 0.00338601015522827, 0.00331546217344017, 0.00324505506219278, 0.00317476753523368, 0.00310465029422548, 0.00303468793848164, 0.00296496495561586, 0.00289545679576046, 0.00282622747425243, 0.00275726089169212, 0.00268863560479671, 0.00262031356572019, 0.00255234987121874, 0.00248475343989325, 0.00241756988507026, 0.00235076297219949, 0.00228445797865602, 0.00221854583847226, 0.00215319633049186, 0.00208824391132099, 0.00202391903684120, 0.00196007035416052, 0.00189672745561680, 0.00183409607086238, 0.00177194862277590, 0.00171039657639008, 0.00164949846708349, 0.00158928340180831, 0.00152970713186801, 0.00147077043048314, 0.00141251944417704, 0.00135497990267232, 0.00129817383913273, 0.00124209904820303, 0.00118675164943918, 0.00113213502585819, 0.00107828503717442, 0.00102521798364415, 0.000972954215880515, 0.000921484852485368, 0.000870821511917016, 0.000820953090117775, 0.000771907381438338, 0.000723692579251588, 0.000676324434358735, 0.000629794805723046, 0.000584135271449011, 0.000539331552961722, 0.000495395175265087, 0.000452307466383416, 0.000410107369479582, 0.000368768031558810, 0.000328303067272255, 0.000288731639017152, 0.000250041672541152, 0.000212225660414214, 0.000175323843452667, 0.000139265001871243, 0.000104194913744367, 6.98079135743859e-05, 3.65984391749181e-05, 4.04401613033564e-06, -2.76411999534569e-05, -5.82740696285398e-05, -8.80751272068533e-05, -0.000117045347359629, -0.000145190671156311, -0.000172407601775126, -0.000198742160896760, -0.000224199400086325, -0.000248836401356591, -0.000272641014736395, -0.000295627067522847, -0.000317740699425894, -0.000339015894938986, -0.000359436786270860, -0.000379060346696341, -0.000397866600246355, -0.000415906028795478, -0.000433138840464187, -0.000449606833404642, -0.000465276778512382, -0.000480203234628012, -0.000494335043762342, -0.000507745859224283, -0.000520395055447092, -0.000532354016357830, -0.000543559747075306, -0.000554101021810418, -0.000563911455667894, -0.000573069125627472, -0.000581501779768414, -0.000589338175725318, -0.000596430516098165, -0.000602983809420617, -0.000608790885954232, -0.000614148178145395, -0.000618727770214896, -0.000622782505082791, -0.000626603803355716, -0.000629134411213307, -0.000631631482873466, -0.000633597273946612, -0.000635003078358038, -0.000635724143226076, -0.000635967181300185, -0.000635761026451823, -0.000635164264832922, -0.000634130868631187, -0.000632650443402028, -0.000630695498825983, -0.000628297254986301, -0.000625497626837207, -0.000622308694572542, -0.000618778259830580, -0.000614882217079890, -0.000610668920187883, -0.000606082637475742, -0.000601200253942484, -0.000595949081082807, -0.000590425893175921, -0.000584552174690912, -0.000578468965223928, -0.000572054035563717, -0.000565477747623975, -0.000558584824336864, -0.000551583323282700, -0.000544249696796157, -0.000536854478912505, -0.000529114793277384, -0.000521360025966030, -0.000513218974024207, -0.000505189086295845, -0.000496672136936235, -0.000488476288769188, -0.000479499372082719, -0.000471635316163514, -0.000461660268788097, -0.000453172230024789, -0.000445439550183399, -0.000435648489505876, -0.000426496295026695, -0.000417020789208928, -0.000408207165488917, -0.000399088156676523, -0.000390255657684682, -0.000381024111936636, -0.000371941004210931, -0.000362544634184449, -0.000353357974172664, -0.000343975936992935, -0.000334855342718481, -0.000325618969853878, -0.000316650955348761, -0.000307585101529890, -0.000298765562188730, -0.000289843221436450, -0.000281131948836483, -0.000272321168079272, -0.000263721934820429, -0.000255034938034355, -0.000246567591545414, -0.000238049618312475, -0.000229772807811465, -0.000221470958675043, -0.000213427887696411, -0.000205384397733665, -0.000197598785182405, -0.000189824946371562, -0.000182327525649789, -0.000174826685798307, -0.000167594998778230, -0.000160358054902775, -0.000153380260487868, -0.000146404247129533, -0.000139680243382954, -0.00140781220330616 + }; + +void print_array_serial(float *bar,int length, Serial *pc){ + int i =0; + for(i = 0; i < length; i++){ + pc->printf("%f, ", bar[i]); + } +} -float filter( float *in, int sampleIndex) +void filter( float *in, Serial *pc) { - unsigned int i, j, k; - float out = 0; - k = 0; + float *taps = firCoeffs; + int i, j; + float out[SAMPLE_LENGTH] = {}; - for( j = 0; j < NUM_TAPS; j++ ){ - k = (sampleIndex - j+SAMPLE_LENGTH-1)&(SAMPLE_LENGTH-1); - out += in[ k ] * firCoeffs[ j ]; + for( i = 0; i < SAMPLE_LENGTH; i++ ) + { + out[ i ] = 0.0; + for( j = 0; j < NUM_TAPS; j++ ){ + if(i-j >= 0) + out[ i ] += in[ i - j ] * taps[ j ]; + } } - return out; + //print_array_serial(out, SAMPLE_LENGTH, pc); + for( i = 0; i < SAMPLE_LENGTH; i++ ) + { + in[ i ] = out[i]; + } } //=------------------------------------------ DSP END ------------------------------------------------------------------------------ //-------------------------------------uiu----- QAM ------------------------------------------------------------------------------------ -float qam_in(float *in, int sampleIndex, float *sI, float *sQ){ - float filteredSI = 0; - float filteredSQ = 0; - int k = 0; +float avg_QAM(float *sI, float *sQ, int length){ + int i = 0; + float total = 0; + int denom = length - 2*NUM_TAPS; + for(i = NUM_TAPS; i < length - NUM_TAPS; i++){ + total = total + sqrt(sI[i]*sI[i] + sQ[i]*sQ[i]); + } + return total/denom; +} + +float qam_in(float *samples, float *sI, float *sQ, Serial *pc){ + //print_array_serial(samples, SAMPLE_LENGTH, pc); 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); + 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, sampleIndex); - filteredSQ = filter(sQ, sampleIndex); - return sqrt(filteredSI*filteredSI+filteredSQ*filteredSQ); + filter(sI, pc); + filter(sQ, pc); + return avg_QAM(sI, sQ, SAMPLE_LENGTH); } //------------------------------------------- QAM END ------------------------------------------------------------------------------ +