DCS_TEAM / Mbed 2 deprecated Chemical_Sensor_DMA

Dependencies:   mbed

Dependents:   DCS_FINAL_CODE

Fork of Chemical_Sensor_DMA by Jared Baxter

Revision:
2:3771b3195c7b
Parent:
1:f0a5690db73f
Child:
3:a85b742be262
--- a/main.cpp	Thu Oct 22 17:10:31 2015 +0000
+++ b/main.cpp	Thu Oct 29 17:15:20 2015 +0000
@@ -1,2516 +1,318 @@
-
-// TODO: 
-#include "mbed.h"
-#include <string>
-
-#include <stdio.h>
-#include "PeripheralNames.h"
-#include "PeripheralPins.h"
-#include "fsl_adc_hal.h"
-#include "fsl_clock_manager.h"
-#include "fsl_dspi_hal.h"
-
-
-
-Serial pc(USBTX, USBRX);
-
-/*
-#if DEBUG
-#define DEBUG_PRINT(x) pc.printf(x)
-#else
-#define DEBUG_PRINT(x) do {} while(0)
-#endif
-*/
-DigitalOut led_red(LED_RED);
-DigitalOut led_green(LED_GREEN);
-DigitalOut led_blue(LED_BLUE);
-
-
-#define MAX_FADC 6000000
-
-#define TimerInterruptInMicroSeconds 25 // This is for 40 kHz
-
-
-#define CarrierFrequency 200
-
-#define ISR_counter_loop_reset 8 // 10 kHz sampling of the signal
-
-int ISR_counter = 1;
-
-#define MaxNumSamples 0  //set to 0 if want continuous sampling (i.e. run forever)
-#define NumSamplesAverageInADC 32 //hardware averaging default is 2. values 0..32. Higher values reduce noise and maximum sample rate
-#define NumADCbits 16
-
-int CyclesInState = 0;
-// While 32 is the minimum, it seems to take a few cycles to get things to work right. 32 + 18 + 18 + 18
-#define PreCalculateCycles 256
-#define NumCalculatedAverages 500
-#define PRINTTIMER 1
-
-int printCounter = 0;
-
-AnalogOut WaveOut(DAC0_OUT);
-AnalogIn WaveIn1(A0);
-AnalogIn WaveIn2(A2);
-
-
-double previousTime = 0;
-
-
-volatile unsigned long counter = 0; //keep track of how many times the timer interrupt executes
-
-
-volatile int phase_counter = 0;
-float twopi = 3.14159265359 * 2;
-
-#define pre_compute_length 4000
-float i_mod_pre[pre_compute_length];
-float q_mod_pre[pre_compute_length];
-int out_val_pre[pre_compute_length]; 
-
-float current_i_mod;
-float current_q_mod;
-
-
-#define lp_fir_length 2048
-
-
-float x_0_i[lp_fir_length];
-float x_0_q[lp_fir_length];
-float x_1_i[lp_fir_length];
-float x_1_q[lp_fir_length];
-
-float real_ip = 0;
-float real_ip_total = 0;
-float imag_ip = 0;
-float imag_ip_total = 0;
-float y_0_squared = 0;
-float y_1_squared = 0;
-
-int y_0, y_1;
-
-
-int max_0 = -1;
-int min_0 = 65536;
-int max_1 = -1;
-int min_1 = 65536;
-
-
-// Coefficients for FIR low-pass filter
-// Order: 511
-// Fs = 5000
-// Fpass = 5
-// Fstop = 25
-// Density Factor 20
-float lp_filter_coeff[lp_fir_length] = {
-2.25877153377331e-06,
-2.66244224670397e-07,
-2.81092420097884e-07,
-2.97200797125842e-07,
-3.13057205526705e-07,
-3.30279379977406e-07,
-3.47320034430519e-07,
-3.65790534295599e-07,
-3.84037888145959e-07,
-4.03659300931941e-07,
-4.22883429696171e-07,
-4.43414078442301e-07,
-4.63474354546465e-07,
-4.85127823306893e-07,
-5.06629365749489e-07,
-5.30402400375842e-07,
-5.53883059492054e-07,
-5.79062251172147e-07,
-6.00698053897355e-07,
-6.27541356389415e-07,
-6.53603188407001e-07,
-6.79457125689371e-07,
-7.06900952158772e-07,
-7.34607521511639e-07,
-7.63210937527310e-07,
-7.92457626845786e-07,
-8.22319204892483e-07,
-8.52904112434704e-07,
-8.83993876825403e-07,
-9.15965803598408e-07,
-9.48565090704124e-07,
-9.82217633251451e-07,
-1.01643933513151e-06,
-1.05143714735623e-06,
-1.08676147556840e-06,
-1.12300409054529e-06,
-1.16035624735089e-06,
-1.19822784284488e-06,
-1.23612003796729e-06,
-1.27597253424280e-06,
-1.31548405641171e-06,
-1.35656260640872e-06,
-1.39768396625082e-06,
-1.44009364782760e-06,
-1.48263736669695e-06,
-1.52645417739943e-06,
-1.57052770327227e-06,
-1.61590430260585e-06,
-1.66152581672090e-06,
-1.70832466623602e-06,
-1.75531183154730e-06,
-1.80354697649463e-06,
-1.85213180801677e-06,
-1.90190541457320e-06,
-1.95172125266670e-06,
-2.00274982053528e-06,
-2.05440229847222e-06,
-2.10671996122087e-06,
-2.15960953108923e-06,
-2.21344673621392e-06,
-2.26753452245018e-06,
-2.32270367024371e-06,
-2.37811232502338e-06,
-2.43461484557276e-06,
-2.49131860508909e-06,
-2.54904626588095e-06,
-2.60694079790385e-06,
-2.66588370269542e-06,
-2.72502556403521e-06,
-2.78515359568984e-06,
-2.84534746585168e-06,
-2.90651253940365e-06,
-2.96789707905998e-06,
-3.03026815024548e-06,
-3.09250439907414e-06,
-3.15586112065294e-06,
-3.21917116992942e-06,
-3.28329739015491e-06,
-3.34755725225876e-06,
-3.41254082601689e-06,
-3.47759844620301e-06,
-3.54333509849531e-06,
-3.60908996231663e-06,
-3.67551457730312e-06,
-3.74192777791326e-06,
-3.80892935787303e-06,
-3.87581985935145e-06,
-3.94325856674703e-06,
-4.01062965420015e-06,
-4.07851955438422e-06,
-4.14618562570372e-06,
-4.21424927012473e-06,
-4.28219961892930e-06,
-4.35043829085821e-06,
-4.41836938506806e-06,
-4.48672487737745e-06,
-4.55459997845769e-06,
-4.62281849455623e-06,
-4.69055023332375e-06,
-4.75852881449136e-06,
-4.82598777828551e-06,
-4.89357790491499e-06,
-4.96055708038026e-06,
-5.02759963577756e-06,
-5.09401623836012e-06,
-5.16043301207036e-06,
-5.22609616909151e-06,
-5.29163941340404e-06,
-5.35641256312241e-06,
-5.42102571618858e-06,
-5.48469577560834e-06,
-5.54811134917779e-06,
-5.61062044360571e-06,
-5.67265321372291e-06,
-5.73373682457175e-06,
-5.79431080305923e-06,
-5.85377619609459e-06,
-5.91266194714808e-06,
-5.97030085360536e-06,
-6.02728122072791e-06,
-6.08294572989760e-06,
-6.13786180337324e-06,
-6.19132752972891e-06,
-6.24392081949063e-06,
-6.29499279506742e-06,
-6.34512332808420e-06,
-6.39358822958236e-06,
-6.44096494373972e-06,
-6.48662130412141e-06,
-6.53110576502919e-06,
-6.57367526411895e-06,
-6.61504319391059e-06,
-6.65439635608727e-06,
-6.69234997696170e-06,
-6.72823177451458e-06,
-6.76256992228003e-06,
-6.79475276861382e-06,
-6.82527935353772e-06,
-6.85350874920331e-06,
-6.87995435672755e-06,
-6.90400455258515e-06,
-6.92617579276020e-06,
-6.94581178960161e-06,
-6.96341207782413e-06,
-6.97837546570650e-06,
-6.99121320837930e-06,
-7.00126691500350e-06,
-7.00904991575129e-06,
-7.01399146065940e-06,
-7.01649463335420e-06,
-7.01598906903671e-06,
-7.01299335632421e-06,
-7.00682651919766e-06,
-6.99805670472170e-06,
-6.98598387232265e-06,
-6.97115918378061e-06,
-6.95293670913433e-06,
-6.93184262641915e-06,
-6.90721796243191e-06,
-6.87956544369715e-06,
-6.84826575659092e-06,
-6.81383582649206e-06,
-6.77563271791333e-06,
-6.73414912642070e-06,
-6.68879222648781e-06,
-6.64004566255543e-06,
-6.58726001945506e-06,
-6.53097084557196e-06,
-6.47057633363911e-06,
-6.40649492549257e-06,
-6.33820922296577e-06,
-6.26611753900958e-06,
-6.18969752493548e-06,
-6.10938733149237e-06,
-6.02460876343180e-06,
-5.93581228618980e-06,
-5.84243268710826e-06,
-5.74494125723676e-06,
-5.64275663266799e-06,
-5.53633239754493e-06,
-5.42511044796520e-06,
-5.30955851436901e-06,
-5.18909082922882e-06,
-5.06417106483642e-06,
-4.93426738681860e-06,
-4.79981139928378e-06,
-4.66022392940390e-06,
-4.51602630845954e-06,
-4.36660747560401e-06,
-4.21247294402037e-06,
-4.05305110546832e-06,
-3.88878763289571e-06,
-3.71916450048738e-06,
-3.54462712478025e-06,
-3.36465155419938e-06,
-3.17967167761456e-06,
-2.98917613191769e-06,
-2.79361738719780e-06,
-2.59247412473194e-06,
-2.38618565979242e-06,
-2.17426059604335e-06,
-1.95714227397860e-06,
-1.73430496738356e-06,
-1.50620956228030e-06,
-1.27238963764761e-06,
-1.03324761527409e-06,
-7.88323211174950e-07,
-5.38057114445362e-07,
-2.81944291020029e-07,
-2.04836906979221e-08,
--2.46853106248978e-07,
--5.19577878779430e-07,
--7.98197252838720e-07,
--1.08221647391169e-06,
--1.37213415644316e-06,
--1.66747248399997e-06,
--1.96871121194834e-06,
--2.27536237370173e-06,
--2.58791653823994e-06,
--2.90589263830832e-06,
--3.22973451266772e-06,
--3.55896455485854e-06,
--3.89406743396649e-06,
--4.23452884634043e-06,
--4.58080862054126e-06,
--4.93243163040497e-06,
--5.28980705682264e-06,
--5.65249312334948e-06,
--6.02088801710077e-06,
--6.39451744851171e-06,
--6.77379446388097e-06,
--7.15823725534437e-06,
--7.54825910394332e-06,
--7.94336123069663e-06,
--8.34395800204422e-06,
--8.74955757971436e-06,
--9.16054779162674e-06,
--9.57642228943518e-06,
--9.99759144947471e-06,
--1.04235511544729e-05,
--1.08546628466816e-05,
--1.12904336671393e-05,
--1.17312462832730e-05,
--1.21765651542703e-05,
--1.26267966656990e-05,
--1.30813839859992e-05,
--1.35407068370928e-05,
--1.40042432894668e-05,
--1.44723391847100e-05,
--1.49444772391115e-05,
--1.54209897807815e-05,
--1.59013657273958e-05,
--1.63859206132667e-05,
--1.68741290759562e-05,
--1.73663104823494e-05,
--1.78619508850454e-05,
--1.83613352518811e-05,
--1.88639344535055e-05,
--1.93700580786767e-05,
--1.98791701832643e-05,
--2.03915446858796e-05,
--2.09066661112072e-05,
--2.14247833830322e-05,
--2.19453728209874e-05,
--2.24687067756074e-05,
--2.29942189701287e-05,
--2.35221919064648e-05,
--2.40520571098411e-05,
--2.45840821429991e-05,
--2.51176919541455e-05,
--2.56531458365802e-05,
--2.61898800092312e-05,
--2.67281307655500e-05,
--2.72673160896635e-05,
--2.78076813742880e-05,
--2.83486572194740e-05,
--2.88904561028569e-05,
--2.94324977036388e-05,
--2.99750102268205e-05,
--3.05173890710438e-05,
--3.10598620379927e-05,
--3.16018340271438e-05,
--3.21434903845723e-05,
--3.26842631134414e-05,
--3.32243219343559e-05,
--3.37630833740885e-05,
--3.43007203295382e-05,
--3.48366443059829e-05,
--3.53710230750429e-05,
--3.59032455798272e-05,
--3.64334836149489e-05,
--3.69611383814916e-05,
--3.74863645989061e-05,
--3.80085391108475e-05,
--3.85278288122663e-05,
--3.90436126582742e-05,
--3.95560344208977e-05,
--4.00644784803627e-05,
--4.05690860811782e-05,
--4.10692160068759e-05,
--4.15650349494434e-05,
--4.20558816044656e-05,
--4.25419079114848e-05,
--4.30224723840039e-05,
--4.34977023194285e-05,
--4.39669575807467e-05,
--4.44303536014418e-05,
--4.48872654011353e-05,
--4.53378004294169e-05,
--4.57813127757766e-05,
--4.62179102441466e-05,
--4.66469626401911e-05,
--4.70685624133195e-05,
--4.74820663998248e-05,
--4.78875779787031e-05,
--4.82844457389913e-05,
--4.86727623947596e-05,
--4.90518974627560e-05,
--4.94219173993094e-05,
--4.97821954537253e-05,
--5.01328087389260e-05,
--5.04731070890493e-05,
--5.08031767792133e-05,
--5.11223701960069e-05,
--5.14307728917283e-05,
--5.17277278570648e-05,
--5.20133133082317e-05,
--5.22868899566335e-05,
--5.25485330801741e-05,
--5.27975890619123e-05,
--5.30341352214345e-05,
--5.32575308256433e-05,
--5.34678403499526e-05,
--5.36644291832927e-05,
--5.38473696441733e-05,
--5.40160121859755e-05,
--5.41704376199963e-05,
--5.43100072156885e-05,
--5.44347778383721e-05,
--5.45441409303223e-05,
--5.46381421707785e-05,
--5.47161726277983e-05,
--5.47782796545640e-05,
--5.48238615891289e-05,
--5.48529777470327e-05,
--5.48650134478435e-05,
--5.48600304498624e-05,
--5.48374279367193e-05,
--5.47972707257875e-05,
--5.47389540962183e-05,
--5.46625553812279e-05,
--5.45674740408066e-05,
--5.44537801178265e-05,
--5.43208932117335e-05,
--5.41688832854903e-05,
--5.39971664557209e-05,
--5.38058373779503e-05,
--5.35943020304215e-05,
--5.33626591300992e-05,
--5.31103372807938e-05,
--5.28374339049068e-05,
--5.25433860531435e-05,
--5.22282871255255e-05,
--5.18915929674119e-05,
--5.15334084359192e-05,
--5.11531883719458e-05,
--5.07510470767421e-05,
--5.03264565435712e-05,
--4.98795298499818e-05,
--4.94097492621224e-05,
--4.89172468415742e-05,
--4.84015062909820e-05,
--4.78626656356439e-05,
--4.73002336655060e-05,
--4.67143388964721e-05,
--4.61045141628936e-05,
--4.54709069617551e-05,
--4.48130436182427e-05,
--4.41310892863899e-05,
--4.34245803720504e-05,
--4.26937043233061e-05,
--4.19380012096953e-05,
--4.11576670903313e-05,
--4.03522641202012e-05,
--3.95219995716669e-05,
--3.86664427936628e-05,
--3.77858193439538e-05,
--3.68797197976284e-05,
--3.59483680766746e-05,
--3.49913775019667e-05,
--3.40089900319630e-05,
--3.30008251544588e-05,
--3.19671510883658e-05,
--3.09076019921684e-05,
--2.98224428705179e-05,
--2.87113445271020e-05,
--2.75745824745532e-05,
--2.64118441851114e-05,
--2.52234156518926e-05,
--2.40090034267166e-05,
--2.27689200068355e-05,
--2.15028786303040e-05,
--2.02112093356898e-05,
--1.88936525600629e-05,
--1.75505489714928e-05,
--1.61816522718723e-05,
--1.47873283970059e-05,
--1.33673529297333e-05,
--1.19221016313184e-05,
--1.04513793212540e-05,
--8.95557028181646e-06,
--7.43449717788015e-06,
--5.88858138346941e-06,
--4.31765074336527e-06,
--2.72214441335228e-06,
--1.10191546986540e-06,
-5.42576135735981e-07,
-2.21145327612140e-06,
-3.90424732482530e-06,
-5.62105051139952e-06,
-7.36137384262456e-06,
-9.12529459068137e-06,
-1.09123048193875e-05,
-1.27224474678529e-05,
-1.45552032584862e-05,
-1.64105928172265e-05,
-1.82880735840279e-05,
-2.01876489388426e-05,
-2.21087489487933e-05,
-2.40513485984833e-05,
-2.60148760416192e-05,
-2.79992736446810e-05,
-3.00039407582481e-05,
-3.20288053388297e-05,
-3.40732419683153e-05,
-3.61371619724216e-05,
-3.82199078901064e-05,
-4.03213747021350e-05,
-4.24408877592610e-05,
-4.45783101891342e-05,
-4.67329465682261e-05,
-4.89046419944162e-05,
-5.10926798053942e-05,
-5.32968764479913e-05,
-5.55164983346224e-05,
-5.77513323125343e-05,
-6.00006282654158e-05,
-6.22641611239781e-05,
-6.45411398811771e-05,
-6.68313202374356e-05,
-6.91339016622066e-05,
-7.14486074938142e-05,
-7.37746190907099e-05,
-7.61116330506792e-05,
-7.84588166968576e-05,
-8.08158423081462e-05,
-8.31818494755366e-05,
-8.55564956212588e-05,
-8.79389017808088e-05,
-9.03286966625331e-05,
-9.27249827027176e-05,
-9.51273684116554e-05,
-9.75349342814310e-05,
-9.99472748819797e-05,
-0.000102363447520479,
-0.000104783014763168,
-0.000107205025896024,
-0.000109629029400713,
-0.000112054039942443,
-0.000114479594239356,
-0.000116904687981786,
-0.000119328839927821,
-0.000121751025536885,
-0.000124170741112682,
-0.000126586955396263,
-0.000128999137073690,
-0.000131406237902807,
-0.000133807710854935,
-0.000136202494636464,
-0.000138590020743407,
-0.000140969217664355,
-0.000143339493063055,
-0.000145699758496409,
-0.000148049419840621,
-0.000150387365819865,
-0.000152712978884051,
-0.000155025147047118,
-0.000157323233199747,
-0.000159606113351142,
-0.000161873135563338,
-0.000164123164418827,
-0.000166355539329688,
-0.000168569105181148,
-0.000170763192929278,
-0.000172936642681967,
-0.000175088769080921,
-0.000177218404031216,
-0.000179324852197408,
-0.000181406934825622,
-0.000183463950477444,
-0.000185494717916349,
-0.000187498516812910,
-0.000189474160690418,
-0.000191420933229610,
-0.000193337632742739,
-0.000195223538589502,
-0.000197077449370729,
-0.000198898632343484,
-0.000200685889922636,
-0.000202438477037224,
-0.000204155202780923,
-0.000205835317231766,
-0.000207477624265485,
-0.000209081375510424,
-0.000210645375770233,
-0.000212168874797709,
-0.000213650681871823,
-0.000215090046105722,
-0.000216485772585174,
-0.000217837122420945,
-0.000219142904089215,
-0.000220402374841213,
-0.000221614355063568,
-0.000222778105957421,
-0.000223892449138464,
-0.000224956657801864,
-0.000225969559300686,
-0.000226930435535397,
-0.000227838120949022,
-0.000228691904367779,
-0.000229490637305569,
-0.000230233614422397,
-0.000230919699867762,
-0.000231548200624833,
-0.000232117991545114,
-0.000232628392706581,
-0.000233078299941400,
-0.000233467042490252,
-0.000233793529306281,
-0.000234057114622203,
-0.000234256717572874,
-0.000234391707980239,
-0.000234461034429087,
-0.000234464075886551,
-0.000234399804148527,
-0.000234267616643166,
-0.000234066510095474,
-0.000233795906658708,
-0.000233454817877378,
-0.000233042694337553,
-0.000232558571806248,
-0.000232001923306693,
-0.000231371813425932,
-0.000230667742461277,
-0.000229888797324386,
-0.000229034509219026,
-0.000228103997682251,
-0.000227096814542036,
-0.000226012115545807,
-0.000224849486757965,
-0.000223608106379000,
-0.000222287594558100,
-0.000220887169687286,
-0.000219406480827707,
-0.000217844783243759,
-0.000216201753070026,
-0.000214476690763218,
-0.000212669306710065,
-0.000210778935093994,
-0.000208805327647997,
-0.000206747856525214,
-0.000204606309833789,
-0.000202380104774549,
-0.000200069067435948,
-0.000197672653272001,
-0.000195190736945890,
-0.000192622814021790,
-0.000189968793862972,
-0.000187228227821168,
-0.000184401067781124,
-0.000181486906935768,
-0.000178485741364642,
-0.000175397211774938,
-0.000172221367164218,
-0.000168957890495671,
-0.000165606876476172,
-0.000162168061864114,
-0.000158641588326119,
-0.000155027243685390,
-0.000151325219415721,
-0.000147535354241219,
-0.000143657889880845,
-0.000139692722584275,
-0.000135640137861556,
-0.000131500087828142,
-0.000127272919603931,
-0.000122958632897122,
-0.000118557624222376,
-0.000114069956263803,
-0.000109496077969276,
-0.000104836112476280,
-0.000100090556969088,
-9.52595926807594e-05,
-9.03437806713531e-05,
-8.53433537117259e-05,
-8.02589335085685e-05,
-7.50908090508799e-05,
-6.98396606723608e-05,
-6.45058395701152e-05,
-5.90900818618602e-05,
-5.35927957604024e-05,
-4.80147832320940e-05,
-4.23565146651483e-05,
-3.66188412855488e-05,
-3.08022998861741e-05,
-2.49078076002350e-05,
-1.89359578000643e-05,
-1.28877281875480e-05,
-6.76377196319473e-06,
-5.65130739446817e-07,
--5.70747618704037e-06,
--1.20529518122427e-05,
--1.84705123312578e-05,
--2.49589991720766e-05,
--3.15175650599888e-05,
--3.81449885574943e-05,
--4.48403630718286e-05,
--5.16024050889186e-05,
--5.84301376752338e-05,
--6.53222224894314e-05,
--7.22776238052609e-05,
--7.92949306753459e-05,
--8.63730463095441e-05,
--9.35105054098079e-05,
--0.000100706144186103,
--0.000107958436359977,
--0.000115266152994485,
--0.000122627706760917,
--0.000130041811681510,
--0.000137506814203479,
--0.000145021368821121,
--0.000152583759222027,
--0.000160192579466020,
--0.000167846056910789,
--0.000175542718661153,
--0.000183280733901876,
--0.000191058573185037,
--0.000198874346379858,
--0.000206726455104848,
--0.000214612960310208,
--0.000222532206706049,
--0.000230482190676936,
--0.000238461200747511,
--0.000246467177406058,
--0.000254498351409696,
--0.000262552611408044,
--0.000270628125294601,
--0.000278722730787134,
--0.000286834539691710,
--0.000294961336084192,
--0.000303101180604228,
--0.000311251799327546,
--0.000319411202616472,
--0.000327577068996273,
--0.000335747350207106,
--0.000343919676673919,
--0.000352091955603402,
--0.000360261765094418,
--0.000368426959623216,
--0.000376585075147441,
--0.000384733917580314,
--0.000392870977630007,
--0.000400994015796423,
--0.000409100475389566,
--0.000417188075990567,
--0.000425254218742792,
--0.000433296579745569,
--0.000441312521641045,
--0.000449299675354794,
--0.000457255369089255,
--0.000465177193879328,
--0.000473062439153703,
--0.000480908661009415,
--0.000488713116827171,
--0.000496473321124369,
--0.000504186501659088,
--0.000511850143907964,
--0.000519461439038756,
--0.000527017845535591,
--0.000534516525078808,
--0.000541954904421434,
--0.000549330124139864,
--0.000556639582645205,
--0.000563880395792860,
--0.000571049939360574,
--0.000578145303770340,
--0.000585163848349161,
--0.000592102641307673,
--0.000598959022419751,
--0.000605730045666215,
--0.000612413030480144,
--0.000619005017567106,
--0.000625503315016224,
--0.000631904950355812,
--0.000638207216182248,
--0.000644407135922555,
--0.000650501991706910,
--0.000656488796703490,
--0.000662364832864586,
--0.000668127107213612,
--0.000673772895505234,
--0.000679299206549835,
--0.000684703312533797,
--0.000689982228373537,
--0.000695133224872846,
--0.000700153320679537,
--0.000705039793794998,
--0.000709789667273328,
--0.000714400230172114,
--0.000718868516431075,
--0.000723191819632401,
--0.000727367189884889,
--0.000731391938661357,
--0.000735263125592756,
--0.000738978079579033,
--0.000742533884189047,
--0.000745927883252895,
--0.000749157181924490,
--0.000752219147550121,
--0.000755110911309810,
--0.000757829866314622,
--0.000760373168287008,
--0.000762738239234387,
--0.000764922268811481,
--0.000766922708033022,
--0.000768736783543735,
--0.000770361976300053,
--0.000771795549766353,
--0.000773035026336787,
--0.000774077710368219,
--0.000774921156688016,
--0.000775562718410930,
--0.000775999996896670,
--0.000776230384120606,
--0.000776251530463252,
--0.000776060879297139,
--0.000775656128479859,
--0.000775034774979158,
--0.000774194563408219,
--0.000773133050832454,
--0.000771848039257578,
--0.000770337139062027,
--0.000768598212666572,
--0.000766628928149237,
--0.000764427212355194,
--0.000761990800345454,
--0.000759317676212684,
--0.000756405642021792,
--0.000753252754194147,
--0.000749856883052877,
--0.000746216149243278,
--0.000742328500323755,
--0.000738192130147058,
--0.000733805058805418,
--0.000729165555282147,
--0.000724271716466218,
--0.000719121892993695,
--0.000713714263134529,
--0.000708047251625198,
--0.000702119122894178,
--0.000695928386138248,
--0.000689473392683322,
--0.000682752736054815,
--0.000675764850643800,
--0.000668508423585954,
--0.000660981983005567,
--0.000653184299948689,
--0.000645113996101250,
--0.000636769940811193,
--0.000628150846892228,
--0.000619255679141116,
--0.000610083247987995,
--0.000600632615642164,
--0.000590902695998816,
--0.000580892646976487,
--0.000570601481559749,
--0.000560028464530771,
--0.000549172712705324,
--0.000538033593923370,
--0.000526610326399401,
--0.000514902384920966,
--0.000502909102003151,
--0.000490630054751344,
--0.000478064682216253,
--0.000465212674168866,
--0.000452073583482240,
--0.000438647204637503,
--0.000424933205749722,
--0.000410931495060687,
--0.000396641852357854,
--0.000382064302937101,
--0.000367198738062124,
--0.000352045297690400,
--0.000336603996500303,
--0.000320875086144786,
--0.000304858697984160,
--0.000288555200873863,
--0.000271964847867372,
--0.000255088130083280,
--0.000237925412360025,
--0.000220477306560259,
--0.000202744305292592,
--0.000184727135197687,
--0.000166426409808339,
--0.000147842979525945,
--0.000128977579742240,
--0.000109831180556723,
--9.04046425871818e-05,
--7.06990553697872e-05,
--5.07154045972636e-05,
--3.04549042775557e-05,
--9.91865979301451e-06,
-1.08919930592394e-05,
-3.19758215514218e-05,
-5.33313669696652e-05,
-7.49572729406508e-05,
-9.68519634422886e-05,
-0.000119013952872007,
-0.000141441540758312,
-0.000164133122498143,
-0.000187086875132261,
-0.000210301066410341,
-0.000233773755649941,
-0.000257503086406519,
-0.000281486994066025,
-0.000305723503700679,
-0.000330210426059308,
-0.000354945665598255,
-0.000379926915845916,
-0.000405151956507756,
-0.000430618362384964,
-0.000456323792890481,
-0.000482265705856655,
-0.000508441643241767,
-0.000534848940194894,
-0.000561485022897046,
-0.000588347113607660,
-0.000615432518021442,
-0.000642738345529626,
-0.000670261786254066,
-0.000697999835195141,
-0.000725949568737048,
-0.000754107872446179,
-0.000782471708002863,
-0.000811037851152608,
-0.000839803156162613,
-0.000868764285754871,
-0.000897917988557699,
-0.000927260821822552,
-0.000956789425305633,
-0.000986500254535089,
-0.00101638984108537,
-0.00104645454078258,
-0.00107669078473676,
-0.00110709482536606,
-0.00113766299717731,
-0.00116839145262871,
-0.00119927642758690,
-0.00123031398418415,
-0.00126150026162382,
-0.00129283122580216,
-0.00132430292836542,
-0.00135591124431857,
-0.00138765213428446,
-0.00141952138887340,
-0.00145151488073991,
-0.00148362831612719,
-0.00151585748499229,
-0.00154819801195881,
-0.00158064560650847,
-0.00161319581695018,
-0.00164584427382029,
-0.00167858645186783,
-0.00171141790451108,
-0.00174433403822607,
-0.00177733033804577,
-0.00181040213773593,
-0.00184354485348776,
-0.00187675376086131,
-0.00191002421019513,
-0.00194335141256686,
-0.00197673066266553,
-0.00201015711112216,
-0.00204362599689791,
-0.00207713241930943,
-0.00211067156001584,
-0.00214423847287856,
-0.00217782828885456,
-0.00221143601594175,
-0.00224505673956590,
-0.00227868542419834,
-0.00231231711939174,
-0.00234594674933244,
-0.00237956932031571,
-0.00241317972846192,
-0.00244677294956298,
-0.00248034384558351,
-0.00251388736165349,
-0.00254739833774491,
-0.00258087169284408,
-0.00261430224582133,
-0.00264768489443835,
-0.00268101443907401,
-0.00271428576337512,
-0.00274749365520234,
-0.00278063298200053,
-0.00281369852627465,
-0.00284668514688528,
-0.00287958762416115,
-0.00291240080973127,
-0.00294511948107620,
-0.00297773849968884,
-0.00301025264456641,
-0.00304265677662001,
-0.00307494568697706,
-0.00310711424878149,
-0.00313915726402809,
-0.00317106962060174,
-0.00320284613548793,
-0.00323448171662747,
-0.00326597120655615,
-0.00329730953059114,
-0.00332849155900580,
-0.00335951224628230,
-0.00339036649346014,
-0.00342104928540268,
-0.00345155555530025,
-0.00348188032822464,
-0.00351201857965144,
-0.00354196536968445,
-0.00357171571569318,
-0.00360126472814403,
-0.00363060747270192,
-0.00365973910561074,
-0.00368865474551317,
-0.00371734960141723,
-0.00374581885109485,
-0.00377405776271989,
-0.00380206156870805,
-0.00382982560239173,
-0.00385734516541213,
-0.00388461565135489,
-0.00391163243217263,
-0.00393839097201934,
-0.00396488671883422,
-0.00399111521100629,
-0.00401707196633785,
-0.00404275260833588,
-0.00406815273741037,
-0.00409326805585855,
-0.00411809424930169,
-0.00414262710547963,
-0.00416686240098882,
-0.00419079601487805,
-0.00421442381486645,
-0.00423774176962887,
-0.00426074584971528,
-0.00428343212038434,
-0.00430579664814760,
-0.00432783560038011,
-0.00434954515073437,
-0.00437092156951920,
-0.00439196113488749,
-0.00441266022458233,
-0.00443301523239588,
-0.00445302264569759,
-0.00447267896722690,
-0.00449198080207357,
-0.00451092477024544,
-0.00452950759322735,
-0.00454772601412418,
-0.00456557686948679,
-0.00458305702638157,
-0.00460016344989720,
-0.00461689312908165,
-0.00463324315222104,
-0.00464921064199444,
-0.00466479281370150,
-0.00467998692108119,
-0.00469479030849154,
-0.00470920036573083,
-0.00472321457430748,
-0.00473683045364440,
-0.00475004562266464,
-0.00476285774233103,
-0.00477526456757244,
-0.00478726390125808,
-0.00479885363726199,
-0.00481003172038249,
-0.00482079618697185,
-0.00483114513086222,
-0.00484107672645139,
-0.00485058921432468,
-0.00485968091876064,
-0.00486835022461732,
-0.00487659560414803,
-0.00488441559200791,
-0.00489180880914334,
-0.00489877394199243,
-0.00490530975799206,
-0.00491141509702113,
-0.00491708888109120,
-0.00492233009791042,
-0.00492713782472824,
-0.00493151120202513,
-0.00493544945801285,
-0.00493895189278199,
-0.00494201788566977,
-0.00494464688981495,
-0.00494683844085619,
-0.00494859214862692,
-0.00494990770180738,
-0.00495078486760031,
-0.00495122348912271,
-0.00495122348912271,
-0.00495078486760031,
-0.00494990770180738,
-0.00494859214862692,
-0.00494683844085619,
-0.00494464688981495,
-0.00494201788566977,
-0.00493895189278199,
-0.00493544945801285,
-0.00493151120202513,
-0.00492713782472824,
-0.00492233009791042,
-0.00491708888109120,
-0.00491141509702113,
-0.00490530975799206,
-0.00489877394199243,
-0.00489180880914334,
-0.00488441559200791,
-0.00487659560414803,
-0.00486835022461732,
-0.00485968091876064,
-0.00485058921432468,
-0.00484107672645139,
-0.00483114513086222,
-0.00482079618697185,
-0.00481003172038249,
-0.00479885363726199,
-0.00478726390125808,
-0.00477526456757244,
-0.00476285774233103,
-0.00475004562266464,
-0.00473683045364440,
-0.00472321457430748,
-0.00470920036573083,
-0.00469479030849154,
-0.00467998692108119,
-0.00466479281370150,
-0.00464921064199444,
-0.00463324315222104,
-0.00461689312908165,
-0.00460016344989720,
-0.00458305702638157,
-0.00456557686948679,
-0.00454772601412418,
-0.00452950759322735,
-0.00451092477024544,
-0.00449198080207357,
-0.00447267896722690,
-0.00445302264569759,
-0.00443301523239588,
-0.00441266022458233,
-0.00439196113488749,
-0.00437092156951920,
-0.00434954515073437,
-0.00432783560038011,
-0.00430579664814760,
-0.00428343212038434,
-0.00426074584971528,
-0.00423774176962887,
-0.00421442381486645,
-0.00419079601487805,
-0.00416686240098882,
-0.00414262710547963,
-0.00411809424930169,
-0.00409326805585855,
-0.00406815273741037,
-0.00404275260833588,
-0.00401707196633785,
-0.00399111521100629,
-0.00396488671883422,
-0.00393839097201934,
-0.00391163243217263,
-0.00388461565135489,
-0.00385734516541213,
-0.00382982560239173,
-0.00380206156870805,
-0.00377405776271989,
-0.00374581885109485,
-0.00371734960141723,
-0.00368865474551317,
-0.00365973910561074,
-0.00363060747270192,
-0.00360126472814403,
-0.00357171571569318,
-0.00354196536968445,
-0.00351201857965144,
-0.00348188032822464,
-0.00345155555530025,
-0.00342104928540268,
-0.00339036649346014,
-0.00335951224628230,
-0.00332849155900580,
-0.00329730953059114,
-0.00326597120655615,
-0.00323448171662747,
-0.00320284613548793,
-0.00317106962060174,
-0.00313915726402809,
-0.00310711424878149,
-0.00307494568697706,
-0.00304265677662001,
-0.00301025264456641,
-0.00297773849968884,
-0.00294511948107620,
-0.00291240080973127,
-0.00287958762416115,
-0.00284668514688528,
-0.00281369852627465,
-0.00278063298200053,
-0.00274749365520234,
-0.00271428576337512,
-0.00268101443907401,
-0.00264768489443835,
-0.00261430224582133,
-0.00258087169284408,
-0.00254739833774491,
-0.00251388736165349,
-0.00248034384558351,
-0.00244677294956298,
-0.00241317972846192,
-0.00237956932031571,
-0.00234594674933244,
-0.00231231711939174,
-0.00227868542419834,
-0.00224505673956590,
-0.00221143601594175,
-0.00217782828885456,
-0.00214423847287856,
-0.00211067156001584,
-0.00207713241930943,
-0.00204362599689791,
-0.00201015711112216,
-0.00197673066266553,
-0.00194335141256686,
-0.00191002421019513,
-0.00187675376086131,
-0.00184354485348776,
-0.00181040213773593,
-0.00177733033804577,
-0.00174433403822607,
-0.00171141790451108,
-0.00167858645186783,
-0.00164584427382029,
-0.00161319581695018,
-0.00158064560650847,
-0.00154819801195881,
-0.00151585748499229,
-0.00148362831612719,
-0.00145151488073991,
-0.00141952138887340,
-0.00138765213428446,
-0.00135591124431857,
-0.00132430292836542,
-0.00129283122580216,
-0.00126150026162382,
-0.00123031398418415,
-0.00119927642758690,
-0.00116839145262871,
-0.00113766299717731,
-0.00110709482536606,
-0.00107669078473676,
-0.00104645454078258,
-0.00101638984108537,
-0.000986500254535089,
-0.000956789425305633,
-0.000927260821822552,
-0.000897917988557699,
-0.000868764285754871,
-0.000839803156162613,
-0.000811037851152608,
-0.000782471708002863,
-0.000754107872446179,
-0.000725949568737048,
-0.000697999835195141,
-0.000670261786254066,
-0.000642738345529626,
-0.000615432518021442,
-0.000588347113607660,
-0.000561485022897046,
-0.000534848940194894,
-0.000508441643241767,
-0.000482265705856655,
-0.000456323792890481,
-0.000430618362384964,
-0.000405151956507756,
-0.000379926915845916,
-0.000354945665598255,
-0.000330210426059308,
-0.000305723503700679,
-0.000281486994066025,
-0.000257503086406519,
-0.000233773755649941,
-0.000210301066410341,
-0.000187086875132261,
-0.000164133122498143,
-0.000141441540758312,
-0.000119013952872007,
-9.68519634422886e-05,
-7.49572729406508e-05,
-5.33313669696652e-05,
-3.19758215514218e-05,
-1.08919930592394e-05,
--9.91865979301451e-06,
--3.04549042775557e-05,
--5.07154045972636e-05,
--7.06990553697872e-05,
--9.04046425871818e-05,
--0.000109831180556723,
--0.000128977579742240,
--0.000147842979525945,
--0.000166426409808339,
--0.000184727135197687,
--0.000202744305292592,
--0.000220477306560259,
--0.000237925412360025,
--0.000255088130083280,
--0.000271964847867372,
--0.000288555200873863,
--0.000304858697984160,
--0.000320875086144786,
--0.000336603996500303,
--0.000352045297690400,
--0.000367198738062124,
--0.000382064302937101,
--0.000396641852357854,
--0.000410931495060687,
--0.000424933205749722,
--0.000438647204637503,
--0.000452073583482240,
--0.000465212674168866,
--0.000478064682216253,
--0.000490630054751344,
--0.000502909102003151,
--0.000514902384920966,
--0.000526610326399401,
--0.000538033593923370,
--0.000549172712705324,
--0.000560028464530771,
--0.000570601481559749,
--0.000580892646976487,
--0.000590902695998816,
--0.000600632615642164,
--0.000610083247987995,
--0.000619255679141116,
--0.000628150846892228,
--0.000636769940811193,
--0.000645113996101250,
--0.000653184299948689,
--0.000660981983005567,
--0.000668508423585954,
--0.000675764850643800,
--0.000682752736054815,
--0.000689473392683322,
--0.000695928386138248,
--0.000702119122894178,
--0.000708047251625198,
--0.000713714263134529,
--0.000719121892993695,
--0.000724271716466218,
--0.000729165555282147,
--0.000733805058805418,
--0.000738192130147058,
--0.000742328500323755,
--0.000746216149243278,
--0.000749856883052877,
--0.000753252754194147,
--0.000756405642021792,
--0.000759317676212684,
--0.000761990800345454,
--0.000764427212355194,
--0.000766628928149237,
--0.000768598212666572,
--0.000770337139062027,
--0.000771848039257578,
--0.000773133050832454,
--0.000774194563408219,
--0.000775034774979158,
--0.000775656128479859,
--0.000776060879297139,
--0.000776251530463252,
--0.000776230384120606,
--0.000775999996896670,
--0.000775562718410930,
--0.000774921156688016,
--0.000774077710368219,
--0.000773035026336787,
--0.000771795549766353,
--0.000770361976300053,
--0.000768736783543735,
--0.000766922708033022,
--0.000764922268811481,
--0.000762738239234387,
--0.000760373168287008,
--0.000757829866314622,
--0.000755110911309810,
--0.000752219147550121,
--0.000749157181924490,
--0.000745927883252895,
--0.000742533884189047,
--0.000738978079579033,
--0.000735263125592756,
--0.000731391938661357,
--0.000727367189884889,
--0.000723191819632401,
--0.000718868516431075,
--0.000714400230172114,
--0.000709789667273328,
--0.000705039793794998,
--0.000700153320679537,
--0.000695133224872846,
--0.000689982228373537,
--0.000684703312533797,
--0.000679299206549835,
--0.000673772895505234,
--0.000668127107213612,
--0.000662364832864586,
--0.000656488796703490,
--0.000650501991706910,
--0.000644407135922555,
--0.000638207216182248,
--0.000631904950355812,
--0.000625503315016224,
--0.000619005017567106,
--0.000612413030480144,
--0.000605730045666215,
--0.000598959022419751,
--0.000592102641307673,
--0.000585163848349161,
--0.000578145303770340,
--0.000571049939360574,
--0.000563880395792860,
--0.000556639582645205,
--0.000549330124139864,
--0.000541954904421434,
--0.000534516525078808,
--0.000527017845535591,
--0.000519461439038756,
--0.000511850143907964,
--0.000504186501659088,
--0.000496473321124369,
--0.000488713116827171,
--0.000480908661009415,
--0.000473062439153703,
--0.000465177193879328,
--0.000457255369089255,
--0.000449299675354794,
--0.000441312521641045,
--0.000433296579745569,
--0.000425254218742792,
--0.000417188075990567,
--0.000409100475389566,
--0.000400994015796423,
--0.000392870977630007,
--0.000384733917580314,
--0.000376585075147441,
--0.000368426959623216,
--0.000360261765094418,
--0.000352091955603402,
--0.000343919676673919,
--0.000335747350207106,
--0.000327577068996273,
--0.000319411202616472,
--0.000311251799327546,
--0.000303101180604228,
--0.000294961336084192,
--0.000286834539691710,
--0.000278722730787134,
--0.000270628125294601,
--0.000262552611408044,
--0.000254498351409696,
--0.000246467177406058,
--0.000238461200747511,
--0.000230482190676936,
--0.000222532206706049,
--0.000214612960310208,
--0.000206726455104848,
--0.000198874346379858,
--0.000191058573185037,
--0.000183280733901876,
--0.000175542718661153,
--0.000167846056910789,
--0.000160192579466020,
--0.000152583759222027,
--0.000145021368821121,
--0.000137506814203479,
--0.000130041811681510,
--0.000122627706760917,
--0.000115266152994485,
--0.000107958436359977,
--0.000100706144186103,
--9.35105054098079e-05,
--8.63730463095441e-05,
--7.92949306753459e-05,
--7.22776238052609e-05,
--6.53222224894314e-05,
--5.84301376752338e-05,
--5.16024050889186e-05,
--4.48403630718286e-05,
--3.81449885574943e-05,
--3.15175650599888e-05,
--2.49589991720766e-05,
--1.84705123312578e-05,
--1.20529518122427e-05,
--5.70747618704037e-06,
-5.65130739446817e-07,
-6.76377196319473e-06,
-1.28877281875480e-05,
-1.89359578000643e-05,
-2.49078076002350e-05,
-3.08022998861741e-05,
-3.66188412855488e-05,
-4.23565146651483e-05,
-4.80147832320940e-05,
-5.35927957604024e-05,
-5.90900818618602e-05,
-6.45058395701152e-05,
-6.98396606723608e-05,
-7.50908090508799e-05,
-8.02589335085685e-05,
-8.53433537117259e-05,
-9.03437806713531e-05,
-9.52595926807594e-05,
-0.000100090556969088,
-0.000104836112476280,
-0.000109496077969276,
-0.000114069956263803,
-0.000118557624222376,
-0.000122958632897122,
-0.000127272919603931,
-0.000131500087828142,
-0.000135640137861556,
-0.000139692722584275,
-0.000143657889880845,
-0.000147535354241219,
-0.000151325219415721,
-0.000155027243685390,
-0.000158641588326119,
-0.000162168061864114,
-0.000165606876476172,
-0.000168957890495671,
-0.000172221367164218,
-0.000175397211774938,
-0.000178485741364642,
-0.000181486906935768,
-0.000184401067781124,
-0.000187228227821168,
-0.000189968793862972,
-0.000192622814021790,
-0.000195190736945890,
-0.000197672653272001,
-0.000200069067435948,
-0.000202380104774549,
-0.000204606309833789,
-0.000206747856525214,
-0.000208805327647997,
-0.000210778935093994,
-0.000212669306710065,
-0.000214476690763218,
-0.000216201753070026,
-0.000217844783243759,
-0.000219406480827707,
-0.000220887169687286,
-0.000222287594558100,
-0.000223608106379000,
-0.000224849486757965,
-0.000226012115545807,
-0.000227096814542036,
-0.000228103997682251,
-0.000229034509219026,
-0.000229888797324386,
-0.000230667742461277,
-0.000231371813425932,
-0.000232001923306693,
-0.000232558571806248,
-0.000233042694337553,
-0.000233454817877378,
-0.000233795906658708,
-0.000234066510095474,
-0.000234267616643166,
-0.000234399804148527,
-0.000234464075886551,
-0.000234461034429087,
-0.000234391707980239,
-0.000234256717572874,
-0.000234057114622203,
-0.000233793529306281,
-0.000233467042490252,
-0.000233078299941400,
-0.000232628392706581,
-0.000232117991545114,
-0.000231548200624833,
-0.000230919699867762,
-0.000230233614422397,
-0.000229490637305569,
-0.000228691904367779,
-0.000227838120949022,
-0.000226930435535397,
-0.000225969559300686,
-0.000224956657801864,
-0.000223892449138464,
-0.000222778105957421,
-0.000221614355063568,
-0.000220402374841213,
-0.000219142904089215,
-0.000217837122420945,
-0.000216485772585174,
-0.000215090046105722,
-0.000213650681871823,
-0.000212168874797709,
-0.000210645375770233,
-0.000209081375510424,
-0.000207477624265485,
-0.000205835317231766,
-0.000204155202780923,
-0.000202438477037224,
-0.000200685889922636,
-0.000198898632343484,
-0.000197077449370729,
-0.000195223538589502,
-0.000193337632742739,
-0.000191420933229610,
-0.000189474160690418,
-0.000187498516812910,
-0.000185494717916349,
-0.000183463950477444,
-0.000181406934825622,
-0.000179324852197408,
-0.000177218404031216,
-0.000175088769080921,
-0.000172936642681967,
-0.000170763192929278,
-0.000168569105181148,
-0.000166355539329688,
-0.000164123164418827,
-0.000161873135563338,
-0.000159606113351142,
-0.000157323233199747,
-0.000155025147047118,
-0.000152712978884051,
-0.000150387365819865,
-0.000148049419840621,
-0.000145699758496409,
-0.000143339493063055,
-0.000140969217664355,
-0.000138590020743407,
-0.000136202494636464,
-0.000133807710854935,
-0.000131406237902807,
-0.000128999137073690,
-0.000126586955396263,
-0.000124170741112682,
-0.000121751025536885,
-0.000119328839927821,
-0.000116904687981786,
-0.000114479594239356,
-0.000112054039942443,
-0.000109629029400713,
-0.000107205025896024,
-0.000104783014763168,
-0.000102363447520479,
-9.99472748819797e-05,
-9.75349342814310e-05,
-9.51273684116554e-05,
-9.27249827027176e-05,
-9.03286966625331e-05,
-8.79389017808088e-05,
-8.55564956212588e-05,
-8.31818494755366e-05,
-8.08158423081462e-05,
-7.84588166968576e-05,
-7.61116330506792e-05,
-7.37746190907099e-05,
-7.14486074938142e-05,
-6.91339016622066e-05,
-6.68313202374356e-05,
-6.45411398811771e-05,
-6.22641611239781e-05,
-6.00006282654158e-05,
-5.77513323125343e-05,
-5.55164983346224e-05,
-5.32968764479913e-05,
-5.10926798053942e-05,
-4.89046419944162e-05,
-4.67329465682261e-05,
-4.45783101891342e-05,
-4.24408877592610e-05,
-4.03213747021350e-05,
-3.82199078901064e-05,
-3.61371619724216e-05,
-3.40732419683153e-05,
-3.20288053388297e-05,
-3.00039407582481e-05,
-2.79992736446810e-05,
-2.60148760416192e-05,
-2.40513485984833e-05,
-2.21087489487933e-05,
-2.01876489388426e-05,
-1.82880735840279e-05,
-1.64105928172265e-05,
-1.45552032584862e-05,
-1.27224474678529e-05,
-1.09123048193875e-05,
-9.12529459068137e-06,
-7.36137384262456e-06,
-5.62105051139952e-06,
-3.90424732482530e-06,
-2.21145327612140e-06,
-5.42576135735981e-07,
--1.10191546986540e-06,
--2.72214441335228e-06,
--4.31765074336527e-06,
--5.88858138346941e-06,
--7.43449717788015e-06,
--8.95557028181646e-06,
--1.04513793212540e-05,
--1.19221016313184e-05,
--1.33673529297333e-05,
--1.47873283970059e-05,
--1.61816522718723e-05,
--1.75505489714928e-05,
--1.88936525600629e-05,
--2.02112093356898e-05,
--2.15028786303040e-05,
--2.27689200068355e-05,
--2.40090034267166e-05,
--2.52234156518926e-05,
--2.64118441851114e-05,
--2.75745824745532e-05,
--2.87113445271020e-05,
--2.98224428705179e-05,
--3.09076019921684e-05,
--3.19671510883658e-05,
--3.30008251544588e-05,
--3.40089900319630e-05,
--3.49913775019667e-05,
--3.59483680766746e-05,
--3.68797197976284e-05,
--3.77858193439538e-05,
--3.86664427936628e-05,
--3.95219995716669e-05,
--4.03522641202012e-05,
--4.11576670903313e-05,
--4.19380012096953e-05,
--4.26937043233061e-05,
--4.34245803720504e-05,
--4.41310892863899e-05,
--4.48130436182427e-05,
--4.54709069617551e-05,
--4.61045141628936e-05,
--4.67143388964721e-05,
--4.73002336655060e-05,
--4.78626656356439e-05,
--4.84015062909820e-05,
--4.89172468415742e-05,
--4.94097492621224e-05,
--4.98795298499818e-05,
--5.03264565435712e-05,
--5.07510470767421e-05,
--5.11531883719458e-05,
--5.15334084359192e-05,
--5.18915929674119e-05,
--5.22282871255255e-05,
--5.25433860531435e-05,
--5.28374339049068e-05,
--5.31103372807938e-05,
--5.33626591300992e-05,
--5.35943020304215e-05,
--5.38058373779503e-05,
--5.39971664557209e-05,
--5.41688832854903e-05,
--5.43208932117335e-05,
--5.44537801178265e-05,
--5.45674740408066e-05,
--5.46625553812279e-05,
--5.47389540962183e-05,
--5.47972707257875e-05,
--5.48374279367193e-05,
--5.48600304498624e-05,
--5.48650134478435e-05,
--5.48529777470327e-05,
--5.48238615891289e-05,
--5.47782796545640e-05,
--5.47161726277983e-05,
--5.46381421707785e-05,
--5.45441409303223e-05,
--5.44347778383721e-05,
--5.43100072156885e-05,
--5.41704376199963e-05,
--5.40160121859755e-05,
--5.38473696441733e-05,
--5.36644291832927e-05,
--5.34678403499526e-05,
--5.32575308256433e-05,
--5.30341352214345e-05,
--5.27975890619123e-05,
--5.25485330801741e-05,
--5.22868899566335e-05,
--5.20133133082317e-05,
--5.17277278570648e-05,
--5.14307728917283e-05,
--5.11223701960069e-05,
--5.08031767792133e-05,
--5.04731070890493e-05,
--5.01328087389260e-05,
--4.97821954537253e-05,
--4.94219173993094e-05,
--4.90518974627560e-05,
--4.86727623947596e-05,
--4.82844457389913e-05,
--4.78875779787031e-05,
--4.74820663998248e-05,
--4.70685624133195e-05,
--4.66469626401911e-05,
--4.62179102441466e-05,
--4.57813127757766e-05,
--4.53378004294169e-05,
--4.48872654011353e-05,
--4.44303536014418e-05,
--4.39669575807467e-05,
--4.34977023194285e-05,
--4.30224723840039e-05,
--4.25419079114848e-05,
--4.20558816044656e-05,
--4.15650349494434e-05,
--4.10692160068759e-05,
--4.05690860811782e-05,
--4.00644784803627e-05,
--3.95560344208977e-05,
--3.90436126582742e-05,
--3.85278288122663e-05,
--3.80085391108475e-05,
--3.74863645989061e-05,
--3.69611383814916e-05,
--3.64334836149489e-05,
--3.59032455798272e-05,
--3.53710230750429e-05,
--3.48366443059829e-05,
--3.43007203295382e-05,
--3.37630833740885e-05,
--3.32243219343559e-05,
--3.26842631134414e-05,
--3.21434903845723e-05,
--3.16018340271438e-05,
--3.10598620379927e-05,
--3.05173890710438e-05,
--2.99750102268205e-05,
--2.94324977036388e-05,
--2.88904561028569e-05,
--2.83486572194740e-05,
--2.78076813742880e-05,
--2.72673160896635e-05,
--2.67281307655500e-05,
--2.61898800092312e-05,
--2.56531458365802e-05,
--2.51176919541455e-05,
--2.45840821429991e-05,
--2.40520571098411e-05,
--2.35221919064648e-05,
--2.29942189701287e-05,
--2.24687067756074e-05,
--2.19453728209874e-05,
--2.14247833830322e-05,
--2.09066661112072e-05,
--2.03915446858796e-05,
--1.98791701832643e-05,
--1.93700580786767e-05,
--1.88639344535055e-05,
--1.83613352518811e-05,
--1.78619508850454e-05,
--1.73663104823494e-05,
--1.68741290759562e-05,
--1.63859206132667e-05,
--1.59013657273958e-05,
--1.54209897807815e-05,
--1.49444772391115e-05,
--1.44723391847100e-05,
--1.40042432894668e-05,
--1.35407068370928e-05,
--1.30813839859992e-05,
--1.26267966656990e-05,
--1.21765651542703e-05,
--1.17312462832730e-05,
--1.12904336671393e-05,
--1.08546628466816e-05,
--1.04235511544729e-05,
--9.99759144947471e-06,
--9.57642228943518e-06,
--9.16054779162674e-06,
--8.74955757971436e-06,
--8.34395800204422e-06,
--7.94336123069663e-06,
--7.54825910394332e-06,
--7.15823725534437e-06,
--6.77379446388097e-06,
--6.39451744851171e-06,
--6.02088801710077e-06,
--5.65249312334948e-06,
--5.28980705682264e-06,
--4.93243163040497e-06,
--4.58080862054126e-06,
--4.23452884634043e-06,
--3.89406743396649e-06,
--3.55896455485854e-06,
--3.22973451266772e-06,
--2.90589263830832e-06,
--2.58791653823994e-06,
--2.27536237370173e-06,
--1.96871121194834e-06,
--1.66747248399997e-06,
--1.37213415644316e-06,
--1.08221647391169e-06,
--7.98197252838720e-07,
--5.19577878779430e-07,
--2.46853106248978e-07,
-2.04836906979221e-08,
-2.81944291020029e-07,
-5.38057114445362e-07,
-7.88323211174950e-07,
-1.03324761527409e-06,
-1.27238963764761e-06,
-1.50620956228030e-06,
-1.73430496738356e-06,
-1.95714227397860e-06,
-2.17426059604335e-06,
-2.38618565979242e-06,
-2.59247412473194e-06,
-2.79361738719780e-06,
-2.98917613191769e-06,
-3.17967167761456e-06,
-3.36465155419938e-06,
-3.54462712478025e-06,
-3.71916450048738e-06,
-3.88878763289571e-06,
-4.05305110546832e-06,
-4.21247294402037e-06,
-4.36660747560401e-06,
-4.51602630845954e-06,
-4.66022392940390e-06,
-4.79981139928378e-06,
-4.93426738681860e-06,
-5.06417106483642e-06,
-5.18909082922882e-06,
-5.30955851436901e-06,
-5.42511044796520e-06,
-5.53633239754493e-06,
-5.64275663266799e-06,
-5.74494125723676e-06,
-5.84243268710826e-06,
-5.93581228618980e-06,
-6.02460876343180e-06,
-6.10938733149237e-06,
-6.18969752493548e-06,
-6.26611753900958e-06,
-6.33820922296577e-06,
-6.40649492549257e-06,
-6.47057633363911e-06,
-6.53097084557196e-06,
-6.58726001945506e-06,
-6.64004566255543e-06,
-6.68879222648781e-06,
-6.73414912642070e-06,
-6.77563271791333e-06,
-6.81383582649206e-06,
-6.84826575659092e-06,
-6.87956544369715e-06,
-6.90721796243191e-06,
-6.93184262641915e-06,
-6.95293670913433e-06,
-6.97115918378061e-06,
-6.98598387232265e-06,
-6.99805670472170e-06,
-7.00682651919766e-06,
-7.01299335632421e-06,
-7.01598906903671e-06,
-7.01649463335420e-06,
-7.01399146065940e-06,
-7.00904991575129e-06,
-7.00126691500350e-06,
-6.99121320837930e-06,
-6.97837546570650e-06,
-6.96341207782413e-06,
-6.94581178960161e-06,
-6.92617579276020e-06,
-6.90400455258515e-06,
-6.87995435672755e-06,
-6.85350874920331e-06,
-6.82527935353772e-06,
-6.79475276861382e-06,
-6.76256992228003e-06,
-6.72823177451458e-06,
-6.69234997696170e-06,
-6.65439635608727e-06,
-6.61504319391059e-06,
-6.57367526411895e-06,
-6.53110576502919e-06,
-6.48662130412141e-06,
-6.44096494373972e-06,
-6.39358822958236e-06,
-6.34512332808420e-06,
-6.29499279506742e-06,
-6.24392081949063e-06,
-6.19132752972891e-06,
-6.13786180337324e-06,
-6.08294572989760e-06,
-6.02728122072791e-06,
-5.97030085360536e-06,
-5.91266194714808e-06,
-5.85377619609459e-06,
-5.79431080305923e-06,
-5.73373682457175e-06,
-5.67265321372291e-06,
-5.61062044360571e-06,
-5.54811134917779e-06,
-5.48469577560834e-06,
-5.42102571618858e-06,
-5.35641256312241e-06,
-5.29163941340404e-06,
-5.22609616909151e-06,
-5.16043301207036e-06,
-5.09401623836012e-06,
-5.02759963577756e-06,
-4.96055708038026e-06,
-4.89357790491499e-06,
-4.82598777828551e-06,
-4.75852881449136e-06,
-4.69055023332375e-06,
-4.62281849455623e-06,
-4.55459997845769e-06,
-4.48672487737745e-06,
-4.41836938506806e-06,
-4.35043829085821e-06,
-4.28219961892930e-06,
-4.21424927012473e-06,
-4.14618562570372e-06,
-4.07851955438422e-06,
-4.01062965420015e-06,
-3.94325856674703e-06,
-3.87581985935145e-06,
-3.80892935787303e-06,
-3.74192777791326e-06,
-3.67551457730312e-06,
-3.60908996231663e-06,
-3.54333509849531e-06,
-3.47759844620301e-06,
-3.41254082601689e-06,
-3.34755725225876e-06,
-3.28329739015491e-06,
-3.21917116992942e-06,
-3.15586112065294e-06,
-3.09250439907414e-06,
-3.03026815024548e-06,
-2.96789707905998e-06,
-2.90651253940365e-06,
-2.84534746585168e-06,
-2.78515359568984e-06,
-2.72502556403521e-06,
-2.66588370269542e-06,
-2.60694079790385e-06,
-2.54904626588095e-06,
-2.49131860508909e-06,
-2.43461484557276e-06,
-2.37811232502338e-06,
-2.32270367024371e-06,
-2.26753452245018e-06,
-2.21344673621392e-06,
-2.15960953108923e-06,
-2.10671996122087e-06,
-2.05440229847222e-06,
-2.00274982053528e-06,
-1.95172125266670e-06,
-1.90190541457320e-06,
-1.85213180801677e-06,
-1.80354697649463e-06,
-1.75531183154730e-06,
-1.70832466623602e-06,
-1.66152581672090e-06,
-1.61590430260585e-06,
-1.57052770327227e-06,
-1.52645417739943e-06,
-1.48263736669695e-06,
-1.44009364782760e-06,
-1.39768396625082e-06,
-1.35656260640872e-06,
-1.31548405641171e-06,
-1.27597253424280e-06,
-1.23612003796729e-06,
-1.19822784284488e-06,
-1.16035624735089e-06,
-1.12300409054529e-06,
-1.08676147556840e-06,
-1.05143714735623e-06,
-1.01643933513151e-06,
-9.82217633251451e-07,
-9.48565090704124e-07,
-9.15965803598408e-07,
-8.83993876825403e-07,
-8.52904112434704e-07,
-8.22319204892483e-07,
-7.92457626845786e-07,
-7.63210937527310e-07,
-7.34607521511639e-07,
-7.06900952158772e-07,
-6.79457125689371e-07,
-6.53603188407001e-07,
-6.27541356389415e-07,
-6.00698053897355e-07,
-5.79062251172147e-07,
-5.53883059492054e-07,
-5.30402400375842e-07,
-5.06629365749489e-07,
-4.85127823306893e-07,
-4.63474354546465e-07,
-4.43414078442301e-07,
-4.22883429696171e-07,
-4.03659300931941e-07,
-3.84037888145959e-07,
-3.65790534295599e-07,
-3.47320034430519e-07,
-3.30279379977406e-07,
-3.13057205526705e-07,
-2.97200797125842e-07,
-2.81092420097884e-07,
-2.66244224670397e-07,
-2.25877153377331e-06
-};
-
-
-
-
-int lp_fifo_num = 1;
-int bp_fifo_num = 1;
-
-
-int value[] = {0,0};
-
-float mag = 0;
-float calc_mag = 0;
-double mag_total = 0;
-float phase = 0;
-float calc_phase = 0;
-float phase_total = 0;
-int NumInBlock = 0;
-
-float mag_result = 0;
-float phase_result = 0;
-/*
-int diff_0[3] = {0, 0, 0};
-int diff_1[3] = {0, 0, 0};
-*/
-double final_mag = 0;
-float final_phase = 0;
-
-// Finite State Machine
-int current_state = 0;
-
-// Flag
-bool ADC_reading = false;
-bool isTransmitting = false;
-
-
-//IntervalTimer timer0;
-Ticker timer0;
-Timer t1;
-
-int adc_cal(void)
-{
-    ADC0_CFG1 |= (ADC_CFG1_MODE(3)  | // 16 bits mode
-                  ADC_CFG1_ADICLK(1)| // Input Bus Clock divided by 2 (20-25 MHz out of reset (FEI mode) / 2)
-                  ADC_CFG1_ADIV(2)) ; // Clock divide by 4 (2.5-3 MHz)
-    
-    ADC0_SC3 |= ADC_SC3_AVGE_MASK |   // Enable HW average
-                ADC_SC3_AVGS(3)   |   // Set HW average of 32 samples
-                ADC_SC3_CAL_MASK;     // Start calibration process
-    
-    while(ADC0_SC3 & ADC_SC3_CAL_MASK); // Wait for calibration to end
-    
-    if(ADC0_SC3 & ADC_SC3_CALF_MASK) return 1;  // Check for successful calibration
-    
-    uint16_t calib = 0; // calibration variable 
-    calib += ADC0->CLPS + ADC0_CLP4 + ADC0_CLP3 + ADC0_CLP2 + ADC0_CLP1 + ADC0_CLP0;
-    calib /= 2;
-    calib |= 0x8000;    // Set MSB 
-    ADC0_PG = calib;
-    calib = 0;
-    calib += ADC0_CLMS + ADC0_CLM4 + ADC0_CLM3 + ADC0_CLM2 + ADC0_CLM1 + ADC0_CLM0;
-    calib /= 2;
-    calib |= 0x8000;    // Set MSB
-    ADC0_MG = calib;
-    
-    return 0;
-}
-
-void adc_init()
-{
-    // red, indicating not ready
-
-    
-    // Turn on the ADC0 and ADC1 clocks
-    SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;
-    SIM_SCGC3 |= SIM_SCGC3_ADC1_MASK;
-    
-    
-     __disable_irq();
-     adc_cal();
-    //if(adc_cal()) {red = 0; green = 0;} // if calibration fails, display yellow
-    __enable_irq();
-
-
-    
-    // Setup Configuration Register 1 
-    ADC0_CFG1 = 0; // clear register
-    ADC0_CFG1 |= ADC_CFG1_ADICLK(0);    // select bus clock
-    ADC0_CFG1 |= ADC_CFG1_MODE(3);      // select 16-bit 2's complement output  
-    ADC0_CFG1 |= ADC_CFG1_ADIV(0);      // clock divisor = 0.
-    ADC0_CFG1 &= ~ADC_CFG1_ADLSMP_MASK; // select short sample time   //QUESTION
-    ADC0_CFG1 &= ~ADC_CFG1_ADLPC_MASK;  // select normal power configuration
-    ADC1_CFG1 = 0; // clear register
-    ADC1_CFG1 |= ADC_CFG1_ADICLK(0);    // select bus clock
-    ADC1_CFG1 |= ADC_CFG1_MODE(3);      // select 16-bit 2's complement output
-    ADC1_CFG1 |= ADC_CFG1_ADIV(0);      // clock divisor = 0.
-    ADC1_CFG1 &= ~ADC_CFG1_ADLSMP_MASK; // select short sample time
-    ADC1_CFG1 &= ~ADC_CFG1_ADLPC_MASK;  // select normal power configuration
-    
-    // Setup Configuration Register 2 
-    ADC0_CFG2 = 0; // clear register
-    //ADC0_CFG2 |= ADC_CFG2_ADHSC_MASK ;  // select high-speed conversion
-    ADC0_CFG2 |= ADC_CFG2_MUXSEL_MASK; // select a channels    //possibly change to channel b.
-    ADC1_CFG2 = 0; // clear register
-    //ADC1_CFG2 |= ADC_CFG2_ADHSC_MASK ;  // select high-speed conversion
-    ADC1_CFG2 &= ~ADC_CFG2_MUXSEL_MASK; // select a channels    
-    
-    // Setup Status and Control Register 2 
-    ADC0_SC2 = 0;                    // clear register
-    ADC0_SC2 |= ADC_SC2_REFSEL(0);   // select external voltage reference   //QUESTION
-    //ADC0_SC2 |= ADC_SC2_DMAEN_MASK;  // enable DMA
-    //ADC0_SC2 &= ~ADC_SC2_ADTRG_MASK; // select hardware trigger  //QESTION
-    ADC1_SC2 = 0;                    // clear register
-    ADC1_SC2 |= ADC_SC2_REFSEL(0);   // select external voltage reference
-    //ADC1_SC2 |= ADC_SC2_DMAEN_MASK;  // enable DMA
-    //ADC1_SC2 &= ~ADC_SC2_ADTRG_MASK; // select hardware trigger
-   
-   
-    ADC0_SC3 = ADC_SC3_AVGS(0) | ADC_SC3_AVGE_MASK; // Hardware Average set to 16 samples averaged
-                                                    // select single conversion mode
-    ADC1_SC3 = ADC_SC3_AVGS(0) | ADC_SC3_AVGE_MASK; // Hardware Average set to 16 samples averaged 
-    // Setup Status and Control Register 3 now that calibration is complete
-    ADC0_SC3 = 0; // Hardware Average set to 4 samples averaged
-                  // Hardware Average Disabled
-                  // select single conversion mode
-    ADC1_SC3 = 0; // Hardware Average set to 4 samples averaged
-                  // Hardware Average Disabled
-                  // select single conversion mode
-    //ADC1_SC3 = ADC_SC3_AVGS(0) |  ADC_SC3_AVGE_MASK;//JARED COME BACK AND LOOK AT THIS
-    
-    // Setup Status and Control Register 1A 
-    ADC0_SC1A = 0; // clear register
-    ADC0_SC1A &= ~ADC_SC1_DIFF_MASK; // select single-ended mode
-    ADC0_SC1A |= ADC_SC1_AIEN_MASK;  // enable interrupt (for debugging)
-    ADC0_SC1A |= ADC_SC1_ADCH(12);   // select channel 13
-    ADC1_SC1A = 0; // clear register
-    ADC1_SC1A &= ~ADC_SC1_DIFF_MASK; // select single-ended mode
-    ADC1_SC1A |= ADC_SC1_AIEN_MASK;  // enable interrupt (for debugging)
-    ADC1_SC1A |= ADC_SC1_ADCH(14);   // select channel 14
-    
-    
-    // Check if ADC is finished initializing  TODO:  This part doesn't seem right, but I did it according to 871
-    while( (ADC0_SC1B&ADC_SC1_COCO_MASK)) {}
-    int gain = ADC0_RA; // read the register to clear SC1A[COCO]  //possibly a
-    while( (ADC1_SC1A&ADC_SC1_COCO_MASK)) {}
-    gain = ADC1_RA; // read the register to clear SC1A[COCO]
-    
-    
-//QUESTION
-    ADC0_SC3 &= ~ADC_SC3_ADCO_MASK;  // single conversion mode
-    ADC1_SC3 &= ~ADC_SC3_ADCO_MASK;  // single conversion mode
-    ADC0_SC2 &= ~ADC_SC2_ADTRG_MASK; // set ADC to software trigger
-    ADC1_SC2 &= ~ADC_SC2_ADTRG_MASK; // set ADC to software trigger
-    ADC0_SC1A |= ADC_SC1_ADCH(12);   // write to SC1B causing a trigger
-    ADC1_SC1A |= ADC_SC1_ADCH(14);   // write to SC1A causing a trigger
-}
-
-
-
-void pre_compute_tables() {
-  // This function will precompute the cos and sin tables used in the rest of the program
-  for(int precompute_counter = 0; precompute_counter < pre_compute_length; precompute_counter++){
-    out_val_pre[precompute_counter] = (int) (cos(twopi * CarrierFrequency * TimerInterruptInMicroSeconds * 1e-6 * precompute_counter) * 4965.0 + 49650.0);
-    i_mod_pre[precompute_counter] = (cos(twopi * CarrierFrequency * TimerInterruptInMicroSeconds * 1e-6 * precompute_counter));
-    q_mod_pre[precompute_counter] = (-sin(twopi * CarrierFrequency * TimerInterruptInMicroSeconds * 1e-6 * precompute_counter));
-
-  }
-} //pre_compute_tables
-
-
-
-
-void ISR_repeat() {//40 KHz
-  // Calculation of loop for generating signal to output on DAC
-  
-  WaveOut.write_u16(out_val_pre[phase_counter]);  //creates a wave that bounces between 0 & 3.3 V
-
-  // ISR counter reset and increment
-  if (ISR_counter >= ISR_counter_loop_reset)//10KHz
-  {
-    ISR_counter = 1;
-  //JARED ADD THESE 2 LINES BACK IN
-    ADC0_SC1A |= ADC_SC1_ADCH(12);   // start ADC process Possibly change to B.
-    ADC1_SC1A |= ADC_SC1_ADCH(14);   // start ADC process
-    
-    ADC_reading = true;
-    current_i_mod = i_mod_pre[phase_counter];
-    current_q_mod = q_mod_pre[phase_counter];
-  }
-  else {
-    ISR_counter++;
-  }
-  
-  phase_counter++;
-  if (phase_counter >= pre_compute_length) phase_counter = 0;
-  
-} //ISR_repeat
-
-
-void execute_DSP() {
-/*
-bp_fifo_num++;  
-  if (bp_fifo_num >= bp_fir_length) bp_fifo_num = 0;
-
-   x_0[bp_fifo_num] = (float) (value[1] - value[0]);
-   x_1[bp_fifo_num] = (float) (value[0] - 32768);
-
-   // Band pass filter of incoming data
-  float y_0 = x_0[bp_fifo_num] * bp_filter_coeff[0];
-  float y_1 = x_1[bp_fifo_num] * bp_filter_coeff[0];
-  
-  for(int fir_counter = 1; fir_counter < bp_fir_length; fir_counter++){
-    int fir_index = bp_fifo_num + fir_counter;
-    if (fir_index >= bp_fir_length) {
-      fir_index -= bp_fir_length;
-    }
-    y_0 += x_0[fir_index] * bp_filter_coeff[fir_counter];
-    y_1 += x_1[fir_index] * bp_filter_coeff[fir_counter];
-  }
-*/
-y_0 = (value[0]);
-y_1 = (value[1]);
-  //y_0 = (value[0] - 32768);
-  //y_1 = (value[1] - 32768);
-  current_i_mod = i_mod_pre[phase_counter];
-  current_q_mod = q_mod_pre[phase_counter];
-
-  // Demodulation of the signal
-  x_0_i[lp_fifo_num] = (y_0 * current_i_mod);
-  x_0_q[lp_fifo_num] = (y_0 * current_q_mod);
-  x_1_i[lp_fifo_num] = (y_1 * current_i_mod);
-  x_1_q[lp_fifo_num] = (y_1 * current_q_mod); 
-
-  lp_fifo_num++;  
-  if (lp_fifo_num >= lp_fir_length) lp_fifo_num = 0;
-
-  // Low pass filter of demodulated signal
-  float y_0_i = x_0_i[lp_fifo_num] * lp_filter_coeff[0];
-  float y_0_q = x_0_q[lp_fifo_num] * lp_filter_coeff[0];
-  float y_1_i = x_1_i[lp_fifo_num] * lp_filter_coeff[0];
-  float y_1_q = x_1_q[lp_fifo_num] * lp_filter_coeff[0];
-
-  for(int fir_counter = 1; fir_counter < lp_fir_length; fir_counter++){
-    int fir_index = lp_fifo_num + fir_counter;
-    if (fir_index >= lp_fir_length) {
-      fir_index -= lp_fir_length;
-    }
-    y_0_i += x_0_i[fir_index] * lp_filter_coeff[fir_counter];
-    y_0_q += x_0_q[fir_index] * lp_filter_coeff[fir_counter];
-    y_1_i += x_1_i[fir_index] * lp_filter_coeff[fir_counter];
-    y_1_q += x_1_q[fir_index] * lp_filter_coeff[fir_counter];
-  }  
-   
-  real_ip = y_0_i * y_1_i + y_0_q * y_1_q;
-  imag_ip = y_0_q * y_1_i - y_0_i * y_1_q;
-  y_0_squared = y_0_i * y_0_i + y_0_q * y_0_q; 
-  y_1_squared = y_1_i * y_1_i + y_1_q * y_1_q;
-
-//  float mag = sqrt((real_ip * real_ip + imag_ip * imag_ip) / y_0_squared;
-  mag = sqrt(((float) real_ip * (float) real_ip + (float) imag_ip * (float) imag_ip)) / ((float) y_0_squared);
-  mag_total += mag;
-  calc_mag = mag_total / NumInBlock;
-
-  real_ip_total += real_ip;
-  imag_ip_total += imag_ip;
-  phase = -atan2(imag_ip_total, real_ip_total);
-  calc_phase = phase_total / NumInBlock;
-}
-
-
-
-void setup() { 
-printf("Starting UP");
-  adc_init();
-  pre_compute_tables();
-  wait(1); 
-} //setup
-
-using namespace std;
- 
-int main() {
-    led_blue = 1;
-    led_green = 1;
-    led_red = 0;
-    
-    setup();
-    int count = 0;
-    t1.start();
-    
-    pc.baud(115200);
-    
-    for(int i = 0; i < 86; i++) 
-    {
-        if(NVIC_GetPriority((IRQn_Type) i) == 0) NVIC_SetPriority((IRQn_Type) i, 2);
-    }
-    
-    // Give hardware associated with 
-    // sampling the highest priority
-    NVIC_SetPriority(ADC1_IRQn,0);
-    NVIC_SetPriority(ADC0_IRQn,0);
-    NVIC_SetPriority(PDB0_IRQn,0);
-    NVIC_SetPriority(DMA0_IRQn,0);
-    NVIC_SetPriority(DMA1_IRQn,0);
-    NVIC_SetPriority(DMA2_IRQn,0);
-    
-    NVIC_SetPriority(ENET_1588_Timer_IRQn,1);
-    NVIC_SetPriority(ENET_Transmit_IRQn,1);
-    NVIC_SetPriority(ENET_Receive_IRQn,1);
-    NVIC_SetPriority(ENET_Error_IRQn,1);
-
-    led_green = 1;
-    led_red = 1;
-    led_blue = 1;
-
-    timer0.attach_us(&ISR_repeat, TimerInterruptInMicroSeconds);
-    while(true) {
-                
-                count++;
-                //printf("Loop");
-                
-                while (!ADC_reading)  
-                {
-                    
-                led_blue = 0;
-                }
-
-            
-              counter++;
-              
-              CyclesInState++;
-              
-              
-              execute_DSP();
-              
-
-                NumInBlock++; 
-                if (NumInBlock >= NumCalculatedAverages) {
-                  printCounter++;
-                  mag_result = calc_mag;
-                  phase_result = calc_phase;
-                  final_mag = mag_result;
-                  final_phase = phase_result;
-                  NumInBlock = 0;
-                  mag_total = 0;
-                  real_ip_total = 0;
-                  imag_ip_total = 0;
-                  if (printCounter>PRINTTIMER)
-                  {
-                      printf("Coeficient%f Phase%f\n\r", final_mag, final_phase);
-                      printCounter = 0;
-                  }
-                  
-                }
-
-              
-                      
-          value[0] = ADC0_RA;//Read adc
-          value[1] = ADC1_RA;//Read adc
-          //printf("%f %f\n\r", value[0], value[1]);
-          ADC_reading = false;//lower flag
-
-    }// end while(true) 
-}// end main
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *      
+ *         
+ *          Pinout for FRDM-k64f                                    
+ *                                  J2
+ *                                  X X 
+ *                                  X X 
+ *                                  X X 
+ *          J3                      X X GND
+ *          X X                     X X SCLK
+ *          X X                     X X MISO
+ *          X X                     X X MOSI
+ *          X X                     X X CS
+ *          X X                 GND X X 
+ *      GND X X                     X X 
+ *      GND X X                         
+ *     5Vin X X                     J1  
+ *                                  X X 
+ *          J4                      X X motorA
+ *          X X                     X X motorB
+ *     mic1 X X                     X X 
+ *     mic2 X X                     X X 
+ *          X X                     X X 
+ *          X X               quadA X X 
+ *          X X               quadB X X 
+ *  
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+#include "mbed.h"
+#include "pause.cpp"
+
+// Sampling
+#include "Sample/adc.h"
+#include "Sample/pdb.h"
+#include "Sample/quad.h"
+
+#include "AngleEncoder.h"
+#include "MotorControl.h"
+
+// for debug purposes
+Serial pc(USBTX, USBRX);
+DigitalOut led_red(LED_RED);
+DigitalOut led_green(LED_GREEN);
+DigitalOut led_blue(LED_BLUE);
+//DigitalIn switch1(PTA4);
+//DigitalIn switch2(PTC6);
+//DigitalOut TotalInd(PTC4);
+//DigitalOut SampleInd(PTC5);
+
+MotorControl motor(PTC2, PTA2, 2000, 25); // cw, ccw, period_us, safetyPeriod_us
+AngleEncoder angle_encoder(PTD2, PTD3, PTD1, PTD0, 8, 0, 1000000); // mosi, miso, sclk, cs, bit_width, mode, hz
+
+// defined in dma.cpp
+extern int len;
+extern uint16_t sample_array0[];
+extern uint16_t sample_array1[];
+extern uint16_t angle_array[];
+extern bool dma_done;
+extern bool dma_half_done;
+
+int motorVal = 10;
+
+// Declaration of functions
+void output_data();
+
+Timer t1;
+using namespace std;
+ 
+int main() {
+    
+    led_blue = 1;
+    led_green = 1;
+    led_red = 1;
+    
+    pc.baud(230400);
+    pc.printf("Starting...\r\n");
+    
+    for(int i = 0; i < 86; i++) 
+    {
+        if(NVIC_GetPriority((IRQn_Type) i) == 0) NVIC_SetPriority((IRQn_Type) i, 2);
+    }
+    
+    // Give hardware associated with 
+    // sampling the highest priority
+    NVIC_SetPriority(ADC1_IRQn,0);
+    NVIC_SetPriority(ADC0_IRQn,0);
+    NVIC_SetPriority(PDB0_IRQn,0);
+    NVIC_SetPriority(DMA0_IRQn,0);
+    NVIC_SetPriority(DMA1_IRQn,0);
+    NVIC_SetPriority(DMA2_IRQn,0);
+    
+    NVIC_SetPriority(ENET_1588_Timer_IRQn,1);
+    NVIC_SetPriority(ENET_Transmit_IRQn,1);
+    NVIC_SetPriority(ENET_Receive_IRQn,1);
+    NVIC_SetPriority(ENET_Error_IRQn,1);
+    
+    //quad_init(); // initialize FTM2 quadrature decoder
+    //quad_invert(); // invert the direction of counting
+    adc_init(); // initialize ADCs (always initialize adc before dma)
+    dma_init(); // initializes DMAs
+    pdb_init(); // initialize PDB0 as the timer for ADCs and DMA2 
+    
+    // flash green led indicating startup complete
+    led_red = 1;
+    led_blue = 1;
+    led_green = 0;
+    pause_ms(500);
+    led_green = 1;
+    pause_ms(200);
+    led_green = 0;
+    pause_ms(500);
+    led_green = 1;
+    pdb_start();
+    t1.start();
+    t1.reset();
+    int startAddress = (int)&sample_array0[0];
+    while (1)
+    {
+        if (t1.read()>2)
+        {
+            //pdb_start();
+            pc.printf("%i\t%i\t%i\r\n", sample_array0[1], sample_array1[1],(DMA_TCD0_DADDR-startAddress)/2);
+            t1.reset();
+        }
+    }
+ //   while(1) {
+//        if(pc.readable() > 0) {
+//            char temp = pc.getc();
+//            
+//            switch(temp) {
+//                case '1': // run motor and sample
+//                {
+//                    // wait for angle to set to zero
+//                    led_blue = 0;
+//                    while(!angle_encoder.set_zero()) {pc.printf("AngleNotSet");}
+//                    quad_reset();
+//                    led_blue = 1;
+//                    
+//                    // release mallet                                
+//                    motor.releaseMallet();
+//                    
+//                    // wait for mallet to drop to certin point before beginning to sample
+//                    /*
+//                    led_red = 0;
+//                    int angleVal;
+//                    do {
+//                        angleVal = angle_encoder.absolute_angle();
+//                        }
+//                    while(!(angleVal > 150 && angleVal < 400));
+//                    led_red = 1;
+//                    */
+//                    
+//                    // begin sampling
+//                    pdb_start();
+//                    //pause_us(TOTAL_SAMPLES*10);
+//                    //while(!dma_done) {led_green = 0;}
+//                    led_green = 1;
+//                    
+//                    // reset mallet
+//                    motor.reset();
+//                    output_data();
+//                    
+//                    
+//                    led_red = 1;
+//                    led_blue = 1;
+//                    led_green = 1;
+//                    }
+//                    break;
+//                
+//                case '2':
+//                {
+//                    motor.releaseMallet();
+//                    pause(1);
+//                    
+//                    while(!angle_encoder.set_zero()) {}
+//                    quad_reset();
+//                    
+//                    pdb_start();
+//                    motor.clockwise(1);
+//                    pause(1);
+//                    motor.off();
+//                    output_data();
+//                    
+//                    }
+//                    break;
+//                
+//                case '3':
+//                {    
+//                    /*
+//                    while(angleVar)
+//                    {
+//                        counter++;
+//                        angleVar = angle_encoder.absolute_angle();
+//                        angleVar -= motorVal;
+//                        if(angleVar == 0x00ff0000) {} // do nothing
+//                        //else if(angleVar > 340) motorB.pulsewidth_us(8000); // max speed 
+//                        else if(angleVar < 43) {
+//                            angleVar = 0; // exit loop
+//                            //motorB.pulsewidth_us(0);} // min speed
+//                        //else motorB.pulsewidth_us(angleVar*800/34);
+//                        }
+//                    motor.off();
+//                    */
+//                    }
+//                    break;    
+//                
+//                
+//                /********************************************************************
+//                * The code below is for testing and troubleshooting.  Don't delete. *
+//                ********************************************************************/
+//                case 'B':
+//                case 'b':
+//                    led_blue = !led_blue;
+//                    pc.printf("Blue LED\r\n");
+//                    break;
+//                case 'R':
+//                case 'r':
+//                    led_red = !led_red;
+//                    pc.printf("Red LED\r\n");
+//                    break;
+//                 
+//                // test sampling
+//                case 'Q':
+//                case 'q':
+//                    quad_reset();
+//                    pdb_start();
+//                    
+//                    while(!dma_half_done) {
+//                        pc.printf("first half\r\n");
+//                        pause_ms(1);
+//                        }
+//                    
+//                    while(!dma_done) {
+//                        pc.printf("second half\r\n");
+//                        pause_ms(1);
+//                        }
+//                    for(int i = 0; i < len; i++) pc.printf("%i\t %i\t %i\r\n", sample_array0[i],sample_array1[i], angle_array[i]);
+//                    pc.printf("\r\n");
+//                    
+//                    led_red = 1;
+//                    led_green = 1;
+//                    led_blue = 1;
+//                    
+//                    
+//                    /*
+//                    while(!angle_encoder.set_zero()) {}
+//                    quad_reset();
+//                    
+//                    
+//                    pdb_start();
+//                    pause_us(TOTAL_SAMPLES*10);
+//                    output_data();*/
+//                    
+//                    break;
+//                case 'W':
+//                case 'w': // reads 0 unless the counter is running
+//                    pc.printf("PDB: %i\r\n",PDB0_CNT);
+//                    break;
+//                
+//                // test angle encoder
+//                case 'A':
+//                case 'a': // set zero
+//                    if(angle_encoder.set_zero()) {
+//                        pc.printf("Zero set\r\n");
+//                    }
+//                    else {
+//                        pc.printf("Zero NOT set\r\n");
+//                    }
+//                    break;
+//                case 'S':
+//                case 's': // perform "no operation", which returns 0xa5
+//                {
+//                    pc.printf("NOP: 0x%02x\r\n", angle_encoder.nop());
+//                    break;
+//                }
+//                case 'D':
+//                case 'd': // read absolute and relative angles
+//                {
+//                    pc.printf("Angle: %i %i\r\n", angle_encoder.absolute_angle(), quad_read());
+//                    break;
+//                }
+//                case 'F':
+//                case 'f':
+//                    pc.printf("Quad Cnt: %i\r\n", quad_read());
+//                    break;
+//                    
+//                // test motor
+//                case 'Z':
+//                case 'z': // release the mallet
+//                    motor.releaseMallet();
+//                    break;
+//                case 'X':
+//                case 'x':    
+//                    motor.hardReset(motorVal);
+//                    break;
+//                case '+':
+//                case '=':
+//                    motorVal++;
+//                    if(motorVal > 8000) motorVal = 8000;
+//                    pc.printf("MotorVal: %i\r\n", motorVal);
+//                    break;
+//                case '-':
+//                {
+//                    motorVal--;
+//                    if(motorVal < 0) motorVal = 0;
+//                    pc.printf("MotorVal: %i\r\n", motorVal);
+//                    break;
+//                }
+//            }
+//        }
+//    }
+}
+
+void output_data()
+{
+    for (int n = 0; n < len; n++) {
+        pc.printf("%i\t%i\r\n", sample_array0[n], sample_array1[n]);
+        
+    }
+}
\ No newline at end of file