for Danillo
Dependencies: MBed_Adafruit-GPS-Library SDFileSystem mbed
realtimeQAM.cpp@0:37d4e78b2076, 2014-11-11 (annotated)
- Committer:
- ncfronk
- Date:
- Tue Nov 11 07:53:38 2014 +0000
- Revision:
- 0:37d4e78b2076
- Child:
- 1:f5770d9636b4
error state;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ncfronk | 0:37d4e78b2076 | 1 | #include "mbed.h" |
ncfronk | 0:37d4e78b2076 | 2 | #include "math.h" |
ncfronk | 0:37d4e78b2076 | 3 | |
ncfronk | 0:37d4e78b2076 | 4 | #define SAMPLE_LENGTH 512 |
ncfronk | 0:37d4e78b2076 | 5 | #define SAMPLE_RATE 16666 |
ncfronk | 0:37d4e78b2076 | 6 | #define TIME_CONST 0.00006 |
ncfronk | 0:37d4e78b2076 | 7 | #define NUM_TAPS 513 |
ncfronk | 0:37d4e78b2076 | 8 | #define SIN_LENGTH 500 |
ncfronk | 0:37d4e78b2076 | 9 | #define CARRIER_FREQ 225 |
ncfronk | 0:37d4e78b2076 | 10 | #define OUTAVG_LENGTH 1000 |
ncfronk | 0:37d4e78b2076 | 11 | |
ncfronk | 0:37d4e78b2076 | 12 | Ticker tick1; |
ncfronk | 0:37d4e78b2076 | 13 | Ticker tick2; |
ncfronk | 0:37d4e78b2076 | 14 | AnalogIn AnIn(A0); |
ncfronk | 0:37d4e78b2076 | 15 | AnalogOut dac0(DAC0_OUT); |
ncfronk | 0:37d4e78b2076 | 16 | DigitalOut led_red(LED_RED); |
ncfronk | 0:37d4e78b2076 | 17 | Serial pc(USBTX, USBRX); |
ncfronk | 0:37d4e78b2076 | 18 | |
ncfronk | 0:37d4e78b2076 | 19 | float pi = 3.14159; |
ncfronk | 0:37d4e78b2076 | 20 | int sinRes = 74; // resolution of sinWave 74 for 225 hz |
ncfronk | 0:37d4e78b2076 | 21 | int freq = 1; |
ncfronk | 0:37d4e78b2076 | 22 | |
ncfronk | 0:37d4e78b2076 | 23 | float sinWave[SIN_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 24 | int sinIndex = 0; |
ncfronk | 0:37d4e78b2076 | 25 | |
ncfronk | 0:37d4e78b2076 | 26 | float samples[SAMPLE_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 27 | int sampleIndex = 0; |
ncfronk | 0:37d4e78b2076 | 28 | float sI[SAMPLE_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 29 | float filteredSI = 0; |
ncfronk | 0:37d4e78b2076 | 30 | float sQ[SAMPLE_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 31 | float filteredSQ = 0; |
ncfronk | 0:37d4e78b2076 | 32 | float output[SAMPLE_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 33 | float avgs[OUTAVG_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 34 | |
ncfronk | 0:37d4e78b2076 | 35 | bool newValue = false; |
ncfronk | 0:37d4e78b2076 | 36 | bool isSampling = true; |
ncfronk | 0:37d4e78b2076 | 37 | int avgIndex = 0; |
ncfronk | 0:37d4e78b2076 | 38 | |
ncfronk | 0:37d4e78b2076 | 39 | |
ncfronk | 0:37d4e78b2076 | 40 | void print_sin(float *bar){ |
ncfronk | 0:37d4e78b2076 | 41 | int i =0; |
ncfronk | 0:37d4e78b2076 | 42 | for(i = 0; i < SAMPLE_LENGTH; i++){ |
ncfronk | 0:37d4e78b2076 | 43 | pc.printf("%f, ", bar[i]); |
ncfronk | 0:37d4e78b2076 | 44 | } |
ncfronk | 0:37d4e78b2076 | 45 | pc.printf("\n\n\n\n"); |
ncfronk | 0:37d4e78b2076 | 46 | } |
ncfronk | 0:37d4e78b2076 | 47 | |
ncfronk | 0:37d4e78b2076 | 48 | void tick_out(){ |
ncfronk | 0:37d4e78b2076 | 49 | if(isSampling){ |
ncfronk | 0:37d4e78b2076 | 50 | //read |
ncfronk | 0:37d4e78b2076 | 51 | samples[sampleIndex] = AnIn.read(); |
ncfronk | 0:37d4e78b2076 | 52 | sampleIndex++; |
ncfronk | 0:37d4e78b2076 | 53 | if(sampleIndex > SAMPLE_LENGTH){ |
ncfronk | 0:37d4e78b2076 | 54 | sampleIndex = 0; |
ncfronk | 0:37d4e78b2076 | 55 | } |
ncfronk | 0:37d4e78b2076 | 56 | //sampleIndex = (sampleIndex+1)&(SAMPLE_LENGTH-1); |
ncfronk | 0:37d4e78b2076 | 57 | //write |
ncfronk | 0:37d4e78b2076 | 58 | dac0 = sinWave[sinIndex]; |
ncfronk | 0:37d4e78b2076 | 59 | sinIndex++; |
ncfronk | 0:37d4e78b2076 | 60 | if((sinIndex+1) > sinRes){ |
ncfronk | 0:37d4e78b2076 | 61 | sinIndex = 0; |
ncfronk | 0:37d4e78b2076 | 62 | } |
ncfronk | 0:37d4e78b2076 | 63 | |
ncfronk | 0:37d4e78b2076 | 64 | newValue = true; |
ncfronk | 0:37d4e78b2076 | 65 | } |
ncfronk | 0:37d4e78b2076 | 66 | |
ncfronk | 0:37d4e78b2076 | 67 | } |
ncfronk | 0:37d4e78b2076 | 68 | |
ncfronk | 0:37d4e78b2076 | 69 | void create_sinWave(){ |
ncfronk | 0:37d4e78b2076 | 70 | int i = 0; |
ncfronk | 0:37d4e78b2076 | 71 | for(i = 0; i < sinRes; i++){ |
ncfronk | 0:37d4e78b2076 | 72 | sinWave[i] = 0.25 * sin(2.0*pi*i/sinRes) + 0.75; |
ncfronk | 0:37d4e78b2076 | 73 | } |
ncfronk | 0:37d4e78b2076 | 74 | } |
ncfronk | 0:37d4e78b2076 | 75 | |
ncfronk | 0:37d4e78b2076 | 76 | void set_Values(int inFreq){ |
ncfronk | 0:37d4e78b2076 | 77 | freq = inFreq; |
ncfronk | 0:37d4e78b2076 | 78 | create_sinWave(); |
ncfronk | 0:37d4e78b2076 | 79 | } |
ncfronk | 0:37d4e78b2076 | 80 | |
ncfronk | 0:37d4e78b2076 | 81 | |
ncfronk | 0:37d4e78b2076 | 82 | //---------------------------------------------------------DSP---------------------------------------------------------------------------- |
ncfronk | 0:37d4e78b2076 | 83 | |
ncfronk | 0:37d4e78b2076 | 84 | float firCoeffs[NUM_TAPS] = { -0.0192878684408550, -0.000565436854162197, -0.000574062372234321, -0.000581179079003090, -0.000589412242712984, -0.000596329290925752, |
ncfronk | 0:37d4e78b2076 | 85 | -0.000604183313496965, -0.000610787449621752, -0.000618254890021300, -0.000624441235452662, -0.000631532852699149, -0.000637317640388987, -0.000644060044878972, -0.000649408145295391, |
ncfronk | 0:37d4e78b2076 | 86 | -0.000655730318423711, -0.000660536584899437, -0.000666350155348239, -0.000670543670441799, -0.000675811138190482, -0.000679345019980268, -0.000684011485494165, -0.000686779420740873, |
ncfronk | 0:37d4e78b2076 | 87 | -0.000690735948708760, -0.000692604062270113, -0.000695783521327534, -0.000696695831913496, -0.000699146857491809, -0.000699128468616956, -0.000700978318797988, -0.000700085972408138, |
ncfronk | 0:37d4e78b2076 | 88 | -0.000701562144359961, -0.000699960260396518, -0.000701552559161197, -0.000699587125715329, -0.000702084347004260, -0.000699951609455988, -0.000704184938277025, -0.000700822488823546, |
ncfronk | 0:37d4e78b2076 | 89 | -0.000707053158406025, -0.000689238102101884, -0.000675432749281130, -0.000692284271988876, -0.000679003259712778, -0.000679427972422059, -0.000670867964963519, -0.000668435478754011, |
ncfronk | 0:37d4e78b2076 | 90 | -0.000660330946718933, -0.000656187894249034, -0.000647892827216824, -0.000642486260779654, -0.000633714444974831, -0.000627154674611770, -0.000617702529114801, -0.000610043338194475, |
ncfronk | 0:37d4e78b2076 | 91 | -0.000599831070682668, -0.000591137773968283, -0.000580109977377959, -0.000570367122683910, -0.000558402454183533, -0.000547524082087984, -0.000534508605134922, -0.000522458425410067, |
ncfronk | 0:37d4e78b2076 | 92 | -0.000508372396429405, -0.000495193607822494, -0.000480069347179249, -0.000465821362319299, -0.000449698934449484, -0.000434475552201623, -0.000417460223522498, -0.000401443504121743, |
ncfronk | 0:37d4e78b2076 | 93 | -0.000383669251697455, -0.000366972910244881, -0.000348312520886679, -0.000330677260377738, -0.000310488418329100, -0.000291306404219105, -0.000268590084163264, -0.000247735016213375, |
ncfronk | 0:37d4e78b2076 | 94 | -0.000223063752779904, -0.000208020109997019, -0.000182718834161682, -0.000158038013340163, -0.000135672987348502, -0.000110658422989979, -8.63859218366082e-05, -6.07302747179699e-05, |
ncfronk | 0:37d4e78b2076 | 95 | -3.52380267488923e-05, -8.75000381957480e-06, 1.79220776252956e-05, 4.53634810869086e-05, 7.31488512081353e-05, 0.000101522460573350, 0.000130337162460535, 0.000159652043314615, |
ncfronk | 0:37d4e78b2076 | 96 | 0.000189518312913980, 0.000219864413943603, 0.000250843940298056, 0.000282270121591107, 0.000314346397337869, 0.000346811034408436, 0.000379918194843229, 0.000413368163653855, |
ncfronk | 0:37d4e78b2076 | 97 | 0.000447462473702899, 0.000481854744689647, 0.000516877376372632, 0.000552121769556217, 0.000587977722826699, 0.000623999763683269, 0.000660700340823140, 0.000697608811340494, |
ncfronk | 0:37d4e78b2076 | 98 | 0.000735367166639595, 0.000773394513145455, 0.000812374375990954, 0.000851487293223158, 0.000891382011561606, 0.000931001117497454, 0.000970883568971010, 0.00101069578059601, |
ncfronk | 0:37d4e78b2076 | 99 | 0.00105169774350639, 0.00109588295343421, 0.00113549685886290, 0.00117866383169451, 0.00122111516589616, 0.00126425191781228, 0.00130756685560331, 0.00135135745612168, |
ncfronk | 0:37d4e78b2076 | 100 | 0.00139547947313276, 0.00143990979242900, 0.00148466890906943, 0.00152967223986802, 0.00157503442488970, 0.00162066455214233, 0.00166668113637550, 0.00171297190814002, |
ncfronk | 0:37d4e78b2076 | 101 | 0.00175961611250325, 0.00180649714239756, 0.00185367729128575, 0.00190106604757396, 0.00194872602458623, 0.00199658259647564, 0.00204468151104454, 0.00209294223259948, |
ncfronk | 0:37d4e78b2076 | 102 | 0.00214139247713316, 0.00218996963721177, 0.00223871049041842, 0.00228761026923322, 0.00233669674897580, 0.00238601381783270, 0.00243548525436868, 0.00248518758501967, |
ncfronk | 0:37d4e78b2076 | 103 | 0.00253485686222383, 0.00258470295716680, 0.00263426676950411, 0.00268414140692153, 0.00273361748949242, 0.00278404942218042, 0.00283412527109201, 0.00288512840396260, |
ncfronk | 0:37d4e78b2076 | 104 | 0.00293445800039565, 0.00298408012351935, 0.00303527354743087, 0.00308448377238342, 0.00313512165505945, 0.00318474186231553, 0.00323506931441536, 0.00328460350198885, |
ncfronk | 0:37d4e78b2076 | 105 | 0.00333460199814310, 0.00338400592135627, 0.00343378958762444, 0.00348308365845938, 0.00353265733443406, 0.00358174124596574, 0.00363100325859950, 0.00367976183349975, |
ncfronk | 0:37d4e78b2076 | 106 | 0.00372865317317631, 0.00377704959506895, 0.00382555699048792, 0.00387355440986243, 0.00392161316870967, 0.00396912079239840, 0.00401664308061543, 0.00406360815542227, |
ncfronk | 0:37d4e78b2076 | 107 | 0.00411058555257416, 0.00415703554738502, 0.00420348722135172, 0.00424939516950231, 0.00429522177839473, 0.00434042896145653, 0.00438546971668745, 0.00442986742204268, |
ncfronk | 0:37d4e78b2076 | 108 | 0.00447414198154179, 0.00451784282884279, 0.00456156022215696, 0.00460464825220905, 0.00464779963068343, 0.00468955284268770, 0.00473169248365623, 0.00477223280278857, |
ncfronk | 0:37d4e78b2076 | 109 | 0.00481424852813673, 0.00485403860423785, 0.00489420623498588, 0.00493373299658250, 0.00497262699146714, 0.00501099496582253, 0.00504887367893452, 0.00508624698184808, |
ncfronk | 0:37d4e78b2076 | 110 | 0.00512316386346786, 0.00515946810910305, 0.00519528393985568, 0.00523039315379049, 0.00526503059762880, 0.00529893784256351, 0.00533241509486141, 0.00536513893964146, |
ncfronk | 0:37d4e78b2076 | 111 | 0.00539742537221889, 0.00542889931428335, 0.00545989970145767, 0.00549004893072241, 0.00551972419584414, 0.00554855435612888, 0.00557692734453731, 0.00560444087154133, |
ncfronk | 0:37d4e78b2076 | 112 | 0.00563147234239205, 0.00565757686128727, 0.00568316642545793, 0.00570777861250159, 0.00573192298998399, 0.00575509504545748, 0.00577790201469266, 0.00579969134709878, |
ncfronk | 0:37d4e78b2076 | 113 | 0.00582115054736086, 0.00584139221452850, 0.00586128734004678, 0.00587972989282672, 0.00589808690052833, 0.00591540333198250, 0.00593205379805961, 0.00594813880209655, |
ncfronk | 0:37d4e78b2076 | 114 | 0.00596267377455868, 0.00597741589424509, 0.00599039453248084, 0.00600314980390327, 0.00601494155132523, 0.00602610113531495, 0.00603636342822522, 0.00604578641469852, |
ncfronk | 0:37d4e78b2076 | 115 | 0.00605437894886202, 0.00606211163669993, 0.00606910653387789, 0.00607525672904290, 0.00608068579068155, 0.00608523210616189, 0.00608901297897988, 0.00609187619324112, |
ncfronk | 0:37d4e78b2076 | 116 | 0.00609396152547327, 0.00609514946463964, 0.00609558653157114, 0.00609514946463964, 0.00609396152547327, 0.00609187619324112, 0.00608901297897988, 0.00608523210616189, |
ncfronk | 0:37d4e78b2076 | 117 | 0.00608068579068155, 0.00607525672904290, 0.00606910653387789, 0.00606211163669993, 0.00605437894886202, 0.00604578641469852, 0.00603636342822522, 0.00602610113531495, |
ncfronk | 0:37d4e78b2076 | 118 | 0.00601494155132523, 0.00600314980390327, 0.00599039453248084, 0.00597741589424509, 0.00596267377455868, 0.00594813880209655, 0.00593205379805961, 0.00591540333198250, |
ncfronk | 0:37d4e78b2076 | 119 | 0.00589808690052833, 0.00587972989282672, 0.00586128734004678, 0.00584139221452850, 0.00582115054736086, 0.00579969134709878, 0.00577790201469266, 0.00575509504545748, |
ncfronk | 0:37d4e78b2076 | 120 | 0.00573192298998399, 0.00570777861250159, 0.00568316642545793, 0.00565757686128727, 0.00563147234239205, 0.00560444087154133, 0.00557692734453731, 0.00554855435612888, |
ncfronk | 0:37d4e78b2076 | 121 | 0.00551972419584414, 0.00549004893072241, 0.00545989970145767, 0.00542889931428335, 0.00539742537221889, 0.00536513893964146, 0.00533241509486141, 0.00529893784256351, |
ncfronk | 0:37d4e78b2076 | 122 | 0.00526503059762880, 0.00523039315379049, 0.00519528393985568, 0.00515946810910305, 0.00512316386346786, 0.00508624698184808, 0.00504887367893452, 0.00501099496582253, |
ncfronk | 0:37d4e78b2076 | 123 | 0.00497262699146714, 0.00493373299658250, 0.00489420623498588, 0.00485403860423785, 0.00481424852813673, 0.00477223280278857, 0.00473169248365623, 0.00468955284268770, |
ncfronk | 0:37d4e78b2076 | 124 | 0.00464779963068343, 0.00460464825220905, 0.00456156022215696, 0.00451784282884279, 0.00447414198154179, 0.00442986742204268, 0.00438546971668745, 0.00434042896145653, |
ncfronk | 0:37d4e78b2076 | 125 | 0.00429522177839473, 0.00424939516950231, 0.00420348722135172, 0.00415703554738502, 0.00411058555257416, 0.00406360815542227, 0.00401664308061543, 0.00396912079239840, |
ncfronk | 0:37d4e78b2076 | 126 | 0.00392161316870967, 0.00387355440986243, 0.00382555699048792, 0.00377704959506895, 0.00372865317317631, 0.00367976183349975, 0.00363100325859950, 0.00358174124596574, |
ncfronk | 0:37d4e78b2076 | 127 | 0.00353265733443406, 0.00348308365845938, 0.00343378958762444, 0.00338400592135627, 0.00333460199814310, 0.00328460350198885, 0.00323506931441536, 0.00318474186231553, |
ncfronk | 0:37d4e78b2076 | 128 | 0.00313512165505945, 0.00308448377238342, 0.00303527354743087, 0.00298408012351935, 0.00293445800039565, 0.00288512840396260, 0.00283412527109201, 0.00278404942218042, |
ncfronk | 0:37d4e78b2076 | 129 | 0.00273361748949242, 0.00268414140692153, 0.00263426676950411, 0.00258470295716680, 0.00253485686222383, 0.00248518758501967, 0.00243548525436868, 0.00238601381783270, |
ncfronk | 0:37d4e78b2076 | 130 | 0.00233669674897580, 0.00228761026923322, 0.00223871049041842, 0.00218996963721177, 0.00214139247713316, 0.00209294223259948, 0.00204468151104454, 0.00199658259647564, |
ncfronk | 0:37d4e78b2076 | 131 | 0.00194872602458623, 0.00190106604757396, 0.00185367729128575, 0.00180649714239756, 0.00175961611250325, 0.00171297190814002, 0.00166668113637550, 0.00162066455214233, |
ncfronk | 0:37d4e78b2076 | 132 | 0.00157503442488970, 0.00152967223986802, 0.00148466890906943, 0.00143990979242900, 0.00139547947313276, 0.00135135745612168, 0.00130756685560331, 0.00126425191781228, |
ncfronk | 0:37d4e78b2076 | 133 | 0.00122111516589616, 0.00117866383169451, 0.00113549685886290, 0.00109588295343421, 0.00105169774350639, 0.00101069578059601, 0.000970883568971010, 0.000931001117497454, |
ncfronk | 0:37d4e78b2076 | 134 | 0.000891382011561606, 0.000851487293223158, 0.000812374375990954, 0.000773394513145455, 0.000735367166639595, 0.000697608811340494, 0.000660700340823140, 0.000623999763683269, |
ncfronk | 0:37d4e78b2076 | 135 | 0.000587977722826699, 0.000552121769556217, 0.000516877376372632, 0.000481854744689647, 0.000447462473702899, 0.000413368163653855, 0.000379918194843229, 0.000346811034408436, |
ncfronk | 0:37d4e78b2076 | 136 | 0.000314346397337869, 0.000282270121591107, 0.000250843940298056, 0.000219864413943603, 0.000189518312913980, 0.000159652043314615, 0.000130337162460535, 0.000101522460573350, |
ncfronk | 0:37d4e78b2076 | 137 | 7.31488512081353e-05, 4.53634810869086e-05, 1.79220776252956e-05, -8.75000381957480e-06, -3.52380267488923e-05, -6.07302747179699e-05, -8.63859218366082e-05, -0.000110658422989979, |
ncfronk | 0:37d4e78b2076 | 138 | -0.000135672987348502, -0.000158038013340163, -0.000182718834161682, -0.000208020109997019, -0.000223063752779904, -0.000247735016213375, -0.000268590084163264, -0.000291306404219105, |
ncfronk | 0:37d4e78b2076 | 139 | -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 |
ncfronk | 0:37d4e78b2076 | 140 | }; |
ncfronk | 0:37d4e78b2076 | 141 | |
ncfronk | 0:37d4e78b2076 | 142 | float filter( float *in) |
ncfronk | 0:37d4e78b2076 | 143 | { |
ncfronk | 0:37d4e78b2076 | 144 | float *taps = firCoeffs; |
ncfronk | 0:37d4e78b2076 | 145 | unsigned int i, j, k; |
ncfronk | 0:37d4e78b2076 | 146 | float out[SAMPLE_LENGTH] = {}; |
ncfronk | 0:37d4e78b2076 | 147 | k = 0; |
ncfronk | 0:37d4e78b2076 | 148 | |
ncfronk | 0:37d4e78b2076 | 149 | |
ncfronk | 0:37d4e78b2076 | 150 | for( i = 0; i < SAMPLE_LENGTH - NUM_TAPS + 1; i++ ) |
ncfronk | 0:37d4e78b2076 | 151 | { |
ncfronk | 0:37d4e78b2076 | 152 | out[ i ] = 0.0; |
ncfronk | 0:37d4e78b2076 | 153 | for( j = 0; j < NUM_TAPS; j++ ){ |
ncfronk | 0:37d4e78b2076 | 154 | k = (i + sampleIndex - j)&(SAMPLE_LENGTH-1); |
ncfronk | 0:37d4e78b2076 | 155 | out[ i ] += in[ k ] * taps[ j ]; |
ncfronk | 0:37d4e78b2076 | 156 | } |
ncfronk | 0:37d4e78b2076 | 157 | } |
ncfronk | 0:37d4e78b2076 | 158 | return out[0]; |
ncfronk | 0:37d4e78b2076 | 159 | } |
ncfronk | 0:37d4e78b2076 | 160 | |
ncfronk | 0:37d4e78b2076 | 161 | //=------------------------------------------ DSP END ------------------------------------------------------------------------------ |
ncfronk | 0:37d4e78b2076 | 162 | |
ncfronk | 0:37d4e78b2076 | 163 | //-------------------------------------uiu----- QAM ------------------------------------------------------------------------------------ |
ncfronk | 0:37d4e78b2076 | 164 | |
ncfronk | 0:37d4e78b2076 | 165 | float qam_in(){ |
ncfronk | 0:37d4e78b2076 | 166 | int j = 0; |
ncfronk | 0:37d4e78b2076 | 167 | for(int i = 0; i < SAMPLE_LENGTH; i++){ |
ncfronk | 0:37d4e78b2076 | 168 | j = (i+sampleIndex)&(SAMPLE_LENGTH-1); |
ncfronk | 0:37d4e78b2076 | 169 | sI[i] = samples[i]*cos(2*pi*CARRIER_FREQ*i*TIME_CONST); |
ncfronk | 0:37d4e78b2076 | 170 | sQ[i] = -samples[i]*sin(2*pi*CARRIER_FREQ*i*TIME_CONST); |
ncfronk | 0:37d4e78b2076 | 171 | } |
ncfronk | 0:37d4e78b2076 | 172 | filteredSI = filter(sI); |
ncfronk | 0:37d4e78b2076 | 173 | filteredSQ = filter(sQ); |
ncfronk | 0:37d4e78b2076 | 174 | return sqrt(filteredSI*filteredSI + filteredSQ*filteredSQ); |
ncfronk | 0:37d4e78b2076 | 175 | } |
ncfronk | 0:37d4e78b2076 | 176 | |
ncfronk | 0:37d4e78b2076 | 177 | //------------------------------------------- QAM END ------------------------------------------------------------------------------ |
ncfronk | 0:37d4e78b2076 | 178 | |
ncfronk | 0:37d4e78b2076 | 179 | void print_values(){ |
ncfronk | 0:37d4e78b2076 | 180 | printf("\n\r--------------------------------------SAMPLES-----------------------------------\n\r \r\n"); |
ncfronk | 0:37d4e78b2076 | 181 | print_sin(avgs); |
ncfronk | 0:37d4e78b2076 | 182 | printf("\n\r-------------------------------------------SI-------------------------------------\n\r \r\n"); |
ncfronk | 0:37d4e78b2076 | 183 | print_sin(sI); |
ncfronk | 0:37d4e78b2076 | 184 | printf("\n\r-----------------------------------------SQ--------------------------------------\n\r \r\n"); |
ncfronk | 0:37d4e78b2076 | 185 | print_sin(sQ); |
ncfronk | 0:37d4e78b2076 | 186 | } |
ncfronk | 0:37d4e78b2076 | 187 | |
ncfronk | 0:37d4e78b2076 | 188 | int main(){ |
ncfronk | 0:37d4e78b2076 | 189 | pc.baud(115200); |
ncfronk | 0:37d4e78b2076 | 190 | |
ncfronk | 0:37d4e78b2076 | 191 | tick1.attach(&tick_out, 0.00006); // below 0.00005 the board can no longer output and read |
ncfronk | 0:37d4e78b2076 | 192 | //tick2.attach(&print_values, 20); |
ncfronk | 0:37d4e78b2076 | 193 | |
ncfronk | 0:37d4e78b2076 | 194 | set_Values(225); |
ncfronk | 0:37d4e78b2076 | 195 | pc.printf("Set values\n"); |
ncfronk | 0:37d4e78b2076 | 196 | |
ncfronk | 0:37d4e78b2076 | 197 | while(1){ |
ncfronk | 0:37d4e78b2076 | 198 | if(newValue){ |
ncfronk | 0:37d4e78b2076 | 199 | avgs[avgIndex] = qam_in(); |
ncfronk | 0:37d4e78b2076 | 200 | avgIndex++; |
ncfronk | 0:37d4e78b2076 | 201 | if(avgIndex > OUTAVG_LENGTH){ |
ncfronk | 0:37d4e78b2076 | 202 | pc.printf("you"); |
ncfronk | 0:37d4e78b2076 | 203 | avgIndex = 0; |
ncfronk | 0:37d4e78b2076 | 204 | } |
ncfronk | 0:37d4e78b2076 | 205 | newValue = false; |
ncfronk | 0:37d4e78b2076 | 206 | } |
ncfronk | 0:37d4e78b2076 | 207 | } |
ncfronk | 0:37d4e78b2076 | 208 | } |