Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Impedance_Fast_Circuitry by
Diff: main.cpp
- Revision:
- 78:10b2916b8f5c
- Parent:
- 77:1ee17a9e9f8b
- Child:
- 79:5f24cfd685d8
--- a/main.cpp Mon Jun 05 18:09:37 2017 +0000 +++ b/main.cpp Tue Jun 06 18:15:00 2017 +0000 @@ -54,7 +54,7 @@ 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 /SAMPLEFREQUENCY * precompute_counter) * 2046.0 + 2048.0);//12 bit cos wave + out_val_pre[precompute_counter] = (int) ((cos(twopi * CarrierFrequency /SAMPLEFREQUENCY * precompute_counter)+cos(twopi * 1000 /SAMPLEFREQUENCY * precompute_counter+3.14159265359)) * 1023.0 + 2048.0);//12 bit cos wave } //float decimated_frequency = 6250; @@ -78,26 +78,34 @@ pc.baud(230400); pc.printf("Starting\r\n"); - float Coeffs_50k[64] = {-0.00580977186764374, -0.00233724597509602, -0.00268496034893966, -0.00296892106107616, -0.00316332842506790, -0.00323734224087795, -0.00316066924650306, -0.00289929624029755, -0.00242701604537671, -0.00171828775863439, -0.000756395728753172, 0.000477926265449492, 0.00199540689821131, 0.00380158746045340, 0.00588165900929199, 0.00823408890481248, 0.0108348019613589, 0.0136476376350624, 0.0166466423869460, 0.0197784366663972, 0.0229973536627058, 0.0262449065159363, 0.0294642414819848, 0.0325921536969478, 0.0355683455017601, 0.0383295801638416, 0.0408195908282943, 0.0429841210797836, 0.0447761053872137, 0.0461555992329706, 0.0470945515138455, 0.0475679104762209, 0.0475679104762209, 0.0470945515138455, 0.0461555992329706, 0.0447761053872137, 0.0429841210797836, 0.0408195908282943, 0.0383295801638416, 0.0355683455017601, 0.0325921536969478, 0.0294642414819848, 0.0262449065159363, 0.0229973536627058, 0.0197784366663972, 0.0166466423869460, 0.0136476376350624, 0.0108348019613589, 0.00823408890481248, 0.00588165900929199, 0.00380158746045340, 0.00199540689821131, 0.000477926265449492, -0.000756395728753172, -0.00171828775863439, -0.00242701604537671, -0.00289929624029755, -0.00316066924650306, -0.00323734224087795, -0.00316332842506790, -0.00296892106107616, -0.00268496034893966, -0.00233724597509602, -0.00580977186764374}; - float Coeffs_6250[64] = {0.00127484193009558, 0.000864570357881826, 0.00102534214649288, 0.00108510384382452, 0.000993133224929705, 0.000703051795928013, 0.000176984381104620, -0.000604044101219087, -0.00163463261391366, -0.00287921914505944, -0.00427024372870053, -0.00570053545539321, -0.00703321069757274, -0.00810283335889244, -0.00872356764128486, -0.00870634354462360, -0.00786670117946960, -0.00604576027868247, -0.00312333623326739, 0.000966301735603311, 0.00622373889666060, 0.0125751900868018, 0.0198716618758688, 0.0278909988243224, 0.0363459953874327, 0.0449001710734076, 0.0531846513791541, 0.0608209828946068, 0.0674455509096558, 0.0727320474263388, 0.0764143241129908, 0.0783043078535981, 0.0783043078535981, 0.0764143241129908, 0.0727320474263388, 0.0674455509096558, 0.0608209828946068, 0.0531846513791541, 0.0449001710734076, 0.0363459953874327, 0.0278909988243224, 0.0198716618758688, 0.0125751900868018, 0.00622373889666060, 0.000966301735603311, -0.00312333623326739, -0.00604576027868247, -0.00786670117946960, -0.00870634354462360, -0.00872356764128486, -0.00810283335889244, -0.00703321069757274, -0.00570053545539321, -0.00427024372870053, -0.00287921914505944, -0.00163463261391366, -0.000604044101219087, 0.000176984381104620, 0.000703051795928013, 0.000993133224929705, 0.00108510384382452, 0.00102534214649288, 0.000864570357881826, 0.00127484193009558}; - float Coeffs_781[32] = {-0.00137496047241108, -0.00189912303426691, -0.00110565158528889, 0.00208160047524475, 0.00686479755292052, 0.0101590507660848, 0.00771645862767646, -0.00299753239510026, -0.0195878466903650, -0.0334711291636072, -0.0323084479325981, -0.00584063791909296, 0.0475547954053657, 0.117412154826256, 0.183528429426864, 0.223771458379020, 0.223771458379020, 0.183528429426864, 0.117412154826256, 0.0475547954053657, -0.00584063791909296, -0.0323084479325981, -0.0334711291636072, -0.0195878466903650, -0.00299753239510026, 0.00771645862767646, 0.0101590507660848, 0.00686479755292052, 0.00208160047524475, -0.00110565158528889, -0.00189912303426691, -0.00137496047241108}; + + //Fs = 100000, FPass = 1500, FStop = 4500, -40db + float Coeffs_100k[64] = {0.00368762746013400, -0.00390835182721185, -0.00352466159836192, -0.00378044968164769, -0.00434746630849834, -0.00502920744118478, -0.00570543677799210, -0.00628464650365093, -0.00668691824262464, -0.00683917139561193, -0.00667505410229485, -0.00613341508706847, -0.00516232410283893, -0.00371868951723358, -0.00177417571286934, 0.000685809876396031, 0.00365648516386919, 0.00711658039739992, 0.0110234409358280, 0.0153179248880130, 0.0199204447074274, 0.0247385052308702, 0.0296636617979935, 0.0345813441342327, 0.0393672306749833, 0.0438989152744108, 0.0480511039644129, 0.0517108728403463, 0.0547710075854812, 0.0571509837193129, 0.0587848911618005, 0.0596038010741317, 0.0596038010741317, 0.0587848911618005, 0.0571509837193129, 0.0547710075854812, 0.0517108728403463, 0.0480511039644129, 0.0438989152744108, 0.0393672306749833, 0.0345813441342327, 0.0296636617979935, 0.0247385052308702, 0.0199204447074274, 0.0153179248880130, 0.0110234409358280, 0.00711658039739992, 0.00365648516386919, 0.000685809876396031, -0.00177417571286934, -0.00371868951723358, -0.00516232410283893, -0.00613341508706847, -0.00667505410229485, -0.00683917139561193, -0.00668691824262464, -0.00628464650365093, -0.00570543677799210, -0.00502920744118478, -0.00434746630849834, -0.00378044968164769, -0.00352466159836192, -0.00390835182721185, 0.00368762746013400}; + //FS = 12500, Fpass = 100 Fstop 595 -50 db, picks on 1KHz signal + float Coeffs_12500[64] = {-0.00222124676855946, -0.00163176345559825, -0.00214372257722720, -0.00268653504526241, -0.00323192624665395, -0.00374368158669702, -0.00417907979321931, -0.00449328006488225, -0.00463658803501384, -0.00455550760053878, -0.00419848205106894, -0.00352024663122325, -0.00247317556122392, -0.00102679426345247, 0.000845020041268567, 0.00315252023354445, 0.00589238992243332, 0.00904676286706929, 0.0125796442526745, 0.0164391331165775, 0.0205582919104753, 0.0248562683452381, 0.0292399202971496, 0.0336089813533200, 0.0378556202824368, 0.0418719268554270, 0.0455508704073759, 0.0487915537931733, 0.0515035460002020, 0.0536094934833149, 0.0550483048257919, 0.0557785148825623, 0.0557785148825623, 0.0550483048257919, 0.0536094934833149, 0.0515035460002020, 0.0487915537931733, 0.0455508704073759, 0.0418719268554270, 0.0378556202824368, 0.0336089813533200, 0.0292399202971496, 0.0248562683452381, 0.0205582919104753, 0.0164391331165775, 0.0125796442526745, 0.00904676286706929, 0.00589238992243332, 0.00315252023354445, 0.000845020041268567, -0.00102679426345247, -0.00247317556122392, -0.00352024663122325, -0.00419848205106894, -0.00455550760053878, -0.00463658803501384, -0.00449328006488225, -0.00417907979321931, -0.00374368158669702, -0.00323192624665395, -0.00268653504526241, -0.00214372257722720, -0.00163176345559825, -0.00222124676855946}; + //Fs = 1562.5 Fpass = 100, FStop = 195.6, null at 200 Hz + float Coeffs_1563[32] = {-0.00296990567211633, 0.00784631357544163, 0.00955642274001412, 0.0105078670942049, 0.00746432577935901, -0.000715888274492355, -0.0127656342089486, -0.0248578255670040, -0.0313597093257934, -0.0264804428976321, -0.00639056527392095, 0.0289495639622991, 0.0749846381319702, 0.123239880157668, 0.163403327438059, 0.186215627611441, 0.186215627611441, 0.163403327438059, 0.123239880157668, 0.0749846381319702, 0.0289495639622991, -0.00639056527392095, -0.0264804428976321, -0.0313597093257934, -0.0248578255670040, -0.0127656342089486, -0.000715888274492355, 0.00746432577935901, 0.0105078670942049, 0.00955642274001412, 0.00784631357544163, -0.00296990567211633}; + //Fs = 781.25, Fpass = 60, Fstop = 120, -50 Db + float Coeffs_782[32] = {-0.00423132648651131, -0.00413085595827858, -0.00212955364173648, 0.00345345707266939, 0.0105870277845968, 0.0147191914630408, 0.0108878516242339, -0.00283458314983071, -0.0224398052018669, -0.0377493805765767, -0.0358474685211045, -0.00721456868509791, 0.0483564412276129, 0.119338204671425, 0.185468453617916, 0.225354002914126, 0.225354002914126, 0.185468453617916, 0.119338204671425, 0.0483564412276129, -0.00721456868509791, -0.0358474685211045, -0.0377493805765767, -0.0224398052018669, -0.00283458314983071, 0.0108878516242339, 0.0147191914630408, 0.0105870277845968, 0.00345345707266939, -0.00212955364173648, -0.00413085595827858, -0.00423132648651131}; float Coeffs[20] = {0.0328368433284673, 0.0237706090075265, 0.0309894695180997, 0.0385253568846695, 0.0459996974310349, 0.0530165318016261, 0.0591943866845610, 0.0641755708098907, 0.0676960677594849, 0.0694621149975389, 0.0694621149975389, 0.0676960677594849, 0.0641755708098907, 0.0591943866845610, 0.0530165318016261, 0.0459996974310349, 0.0385253568846695, 0.0309894695180997, 0.0237706090075265, 0.0328368433284673}; float Coeffs2[20] = {-0.00506451294187997, -0.00824932319607346, -0.00986370066237912, -0.00518913235010027, 0.00950858650162284, 0.0357083149022659, 0.0711557142019980, 0.109659494661247, 0.142586101123340, 0.161603335553589, 0.161603335553589, 0.142586101123340, 0.109659494661247, 0.0711557142019980, 0.0357083149022659, 0.00950858650162284, -0.00518913235010027, -0.00986370066237912, -0.00824932319607346, -0.00506451294187997}; - for(int i = 0; i < 8; i++) input_50k[i] = new float[64];//each array represents the input of the adcs - - filters f3 = filters(4, 8, NULL, 8, 32, Coeffs_781,false); + + + filters f4 = filters(4, 8, NULL, 8, 32, Coeffs_782,DEMOD_No_Demod); + filters f3 = filters(4, 2, &f4, 4, 32, Coeffs_1563,DEMOD_No_Demod); + filters f2 = filters(4, 8, &f3, 8, 64, Coeffs_12500,DEMOD_No_Demod); + filters f1 = filters(2, 8, &f2, 64, 64, Coeffs_100k,DEMOD_200HZ); - //6250->781 - filters f2 = filters(4, 8, &f3, 8, 64, Coeffs_6250,false); + filters f4_b = filters(4, 8, NULL, 8, 32, Coeffs_782,DEMOD_No_Demod); + filters f3_b = filters(4, 2, &f4_b, 4, 32, Coeffs_1563,DEMOD_No_Demod); + filters f2_b = filters(4, 8, &f3_b, 8, 64, Coeffs_12500,DEMOD_No_Demod); + filters f1_b = filters(2, 8, &f2_b, 64, 64, Coeffs_100k,DEMOD_1000HZ); - //50,000->6250 - filters f1 = filters(2, 8, &f2, 64, 64, Coeffs_50k,true); - - filters f_pre = filters(2, 2, &f1, 64, 64, Coeffs_50k,false); + //filters f_pre = filters(2, 2, &f1, 64, 64, Coeffs_50k,false); //float output_print_buffer[PRINT_BUFFER_LENGTH];//used to store the adc0 values(current measurment) //float output_print_buffer2[PRINT_BUFFER_LENGTH];//used to store the adc0 values(voltage measurment) @@ -149,7 +157,8 @@ }//End of for loop going throught the buffer of adc samples //input_50k[0] = static_input_array0; //input_50k[1] = static_input_array1; - f_pre.input(input_50k,64); + f1.input(input_50k,64,DEMOD_200HZ); + f1_b.input(input_50k,64,DEMOD_1000HZ); //status_3 = 1; //pc.printf("Y"); //status_3 = 0;