Senior Design: Sound Monitor / 4951

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Committer:
linx0576
Date:
Sat Dec 12 21:43:03 2015 +0000
Revision:
3:7edb43f86069
Parent:
2:afdb1aaa7608
Child:
4:e1ec41710eb4
up down select

Who changed what in which revision?

UserRevisionLine numberNew contents of line
linx0576 0:52568bab75f8 1 #include <math.h>
linx0576 0:52568bab75f8 2 #include "stdio.h"
linx0576 0:52568bab75f8 3 #include "mbed.h"
linx0576 0:52568bab75f8 4 #include "SPI_TFT_ILI9341.h"
linx0576 0:52568bab75f8 5 #include "string"
linx0576 0:52568bab75f8 6 #include "Arial12x12.h"
linx0576 0:52568bab75f8 7 #include "Arial24x23.h"
linx0576 0:52568bab75f8 8 #include "arm_math.h"
linx0576 0:52568bab75f8 9 #define num 128
linx0576 3:7edb43f86069 10 //AnalogIn ain1(PC_6);
linx0576 3:7edb43f86069 11 //AnalogIn ain2(PC_7);
linx0576 3:7edb43f86069 12 //AnalogIn ain3(PC_8);
linx0576 3:7edb43f86069 13 //AnalogIn ain4(PC_9);
linx0576 3:7edb43f86069 14 //AnalogIn ain5(PB_15);
linx0576 3:7edb43f86069 15
linx0576 3:7edb43f86069 16
linx0576 3:7edb43f86069 17 DigitalIn ain1(PC_9);
linx0576 3:7edb43f86069 18 DigitalIn ain2(PB_15);
linx0576 3:7edb43f86069 19 DigitalIn ain3(PC_7);
linx0576 3:7edb43f86069 20 DigitalIn ain4(PC_6);
linx0576 3:7edb43f86069 21 DigitalIn ain5(PC_8);
linx0576 0:52568bab75f8 22
linx0576 0:52568bab75f8 23 /** External Input and Output buffer Declarations for FFT Bin Example **/
linx0576 1:f1f3dfff9107 24 //static float32_t testInput_f32_10khz[num];
linx0576 1:f1f3dfff9107 25
linx0576 0:52568bab75f8 26 /** Global variables for FFT Bin Example **/
linx0576 1:f1f3dfff9107 27
linx0576 0:52568bab75f8 28 uint32_t ifftFlag = 0;
linx0576 0:52568bab75f8 29 uint32_t doBitReverse = 1;
linx0576 0:52568bab75f8 30
linx0576 0:52568bab75f8 31 /* Reference index at which max energy of bin ocuurs */
linx0576 0:52568bab75f8 32 uint32_t refIndex = 213, testIndex = 0;
linx0576 0:52568bab75f8 33
linx0576 0:52568bab75f8 34 extern unsigned char p1[]; // the mbed logo
linx0576 0:52568bab75f8 35 const float32_t a[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
linx0576 0:52568bab75f8 36 0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
linx0576 0:52568bab75f8 37 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
linx0576 0:52568bab75f8 38 -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 0:52568bab75f8 39 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620,
linx0576 0:52568bab75f8 40 -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426,
linx0576 0:52568bab75f8 41 -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287,
linx0576 0:52568bab75f8 42 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 0:52568bab75f8 43 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279,
linx0576 0:52568bab75f8 44 -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
linx0576 0:52568bab75f8 45 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
linx0576 0:52568bab75f8 46 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 0:52568bab75f8 47 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
linx0576 0:52568bab75f8 48 0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
linx0576 0:52568bab75f8 49 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
linx0576 0:52568bab75f8 50 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 51 };
linx0576 0:52568bab75f8 52 const float32_t b[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
linx0576 0:52568bab75f8 53 0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
linx0576 0:52568bab75f8 54 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
linx0576 0:52568bab75f8 55 -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
linx0576 0:52568bab75f8 56 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
linx0576 0:52568bab75f8 57 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 0:52568bab75f8 58 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
linx0576 0:52568bab75f8 59 0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
linx0576 0:52568bab75f8 60 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
linx0576 0:52568bab75f8 61 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 62 -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430,
linx0576 0:52568bab75f8 63 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620, -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910,
linx0576 0:52568bab75f8 64 -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387,
linx0576 0:52568bab75f8 65 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723,
linx0576 0:52568bab75f8 66 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834,
linx0576 0:52568bab75f8 67 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644,
linx0576 0:52568bab75f8 68 };
linx0576 0:52568bab75f8 69 float32_t a1, b1;
linx0576 0:52568bab75f8 70 float32_t subOutput, SquareOutput;
linx0576 0:52568bab75f8 71
linx0576 2:afdb1aaa7608 72 //SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
linx0576 2:afdb1aaa7608 73 SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
linx0576 1:f1f3dfff9107 74
linx0576 0:52568bab75f8 75 int main()
linx0576 1:f1f3dfff9107 76 {
linx0576 3:7edb43f86069 77 /*// arm_cfft_radix2_instance_f32 S;
linx0576 1:f1f3dfff9107 78 int stage=0;
linx0576 1:f1f3dfff9107 79 int pu, pd, pl, pr, ps;
linx0576 0:52568bab75f8 80 TFT.claim(stdout); // send stdout to the TFT display
linx0576 0:52568bab75f8 81 TFT.claim(stderr); // send stderr to the TFT display
linx0576 2:afdb1aaa7608 82 TFT.set_orientation(2); // comment out = "||" include = "="
linx0576 0:52568bab75f8 83 TFT.background(Black); // set background to black
linx0576 0:52568bab75f8 84 TFT.foreground(White); // set chars to white
linx0576 3:7edb43f86069 85 TFT.cls(); // clear the screen*/
linx0576 3:7edb43f86069 86
linx0576 3:7edb43f86069 87 // arm_cfft_radix2_instance_f32 S;
linx0576 3:7edb43f86069 88 int stage=0;
linx0576 3:7edb43f86069 89 int menu=0;
linx0576 3:7edb43f86069 90 float32_t mean=0;
linx0576 3:7edb43f86069 91 float32_t mse=0;
linx0576 3:7edb43f86069 92 float32_t st=0;
linx0576 3:7edb43f86069 93 // int pu, pd, pl, pr, ps;
linx0576 3:7edb43f86069 94 TFT.claim(stdout); // send stdout to the TFT display
linx0576 3:7edb43f86069 95 TFT.claim(stderr); // send stderr to the TFT display
linx0576 3:7edb43f86069 96 TFT.set_orientation(2); // comment out = "||" include = "="
linx0576 3:7edb43f86069 97 TFT.background(Black); // set background to black
linx0576 3:7edb43f86069 98 TFT.foreground(White); // set chars to white
linx0576 0:52568bab75f8 99 TFT.cls(); // clear the screen
linx0576 0:52568bab75f8 100
linx0576 3:7edb43f86069 101
linx0576 3:7edb43f86069 102
linx0576 1:f1f3dfff9107 103 while(1)
linx0576 3:7edb43f86069 104 { int pu, pd, ps;
linx0576 3:7edb43f86069 105
linx0576 1:f1f3dfff9107 106 if (stage==0) //menu
linx0576 3:7edb43f86069 107 {
linx0576 1:f1f3dfff9107 108 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 109 TFT.locate(20,60);
linx0576 1:f1f3dfff9107 110 printf("Configuration");
linx0576 1:f1f3dfff9107 111 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 112 TFT.locate(20,110);
linx0576 1:f1f3dfff9107 113 TFT.printf(" Waveform");
linx0576 1:f1f3dfff9107 114 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 115 TFT.locate(20,160);
linx0576 1:f1f3dfff9107 116 TFT.printf(" Log");
linx0576 1:f1f3dfff9107 117 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 118 TFT.locate(20,260);
linx0576 1:f1f3dfff9107 119 printf(" Return");
linx0576 0:52568bab75f8 120
linx0576 1:f1f3dfff9107 121 if (menu==0) //Configuration
linx0576 3:7edb43f86069 122 { TFT.rect(15,55,220,85,Green);
linx0576 1:f1f3dfff9107 123 TFT.rect(15,105,220,135,Black);
linx0576 3:7edb43f86069 124 pu = ain1.read();
linx0576 3:7edb43f86069 125 pd = ain2.read();
linx0576 3:7edb43f86069 126 ps = ain3.read();
linx0576 3:7edb43f86069 127 if (pd==1) {wait(0.5); menu=1;}
linx0576 3:7edb43f86069 128 if (ps==1) {wait(0.5); TFT.cls(); stage=1;}
linx0576 1:f1f3dfff9107 129 }
linx0576 1:f1f3dfff9107 130
linx0576 1:f1f3dfff9107 131 if (menu==1) //waveform
linx0576 3:7edb43f86069 132 {
linx0576 1:f1f3dfff9107 133 TFT.rect(15,55,220,85,Black);
linx0576 3:7edb43f86069 134 TFT.rect(15,105,220,135,Green);
linx0576 1:f1f3dfff9107 135 TFT.rect(15,155,220,185,Black);
linx0576 3:7edb43f86069 136 pu = ain1.read();
linx0576 3:7edb43f86069 137 pd = ain2.read();
linx0576 3:7edb43f86069 138 ps = ain3.read();
linx0576 3:7edb43f86069 139 if (pu==1) {wait(0.5); menu=0;}
linx0576 3:7edb43f86069 140 if (pd==1) {wait(0.5); menu=2;}
linx0576 3:7edb43f86069 141 if (ps==1) {wait(0.5); TFT.cls(); stage=2;}
linx0576 1:f1f3dfff9107 142 }
linx0576 0:52568bab75f8 143
linx0576 1:f1f3dfff9107 144 if (menu==2) //log
linx0576 3:7edb43f86069 145 {
linx0576 1:f1f3dfff9107 146 TFT.rect(15,105,220,135,Black);
linx0576 3:7edb43f86069 147 TFT.rect(15,155,220,185,Green);
linx0576 1:f1f3dfff9107 148 TFT.rect(15,255,220,285,Black);
linx0576 3:7edb43f86069 149 pu = ain1.read();
linx0576 3:7edb43f86069 150 pd = ain2.read();
linx0576 3:7edb43f86069 151 ps = ain3.read();
linx0576 3:7edb43f86069 152 if (pu==1) {wait(0.5); menu=1;}
linx0576 3:7edb43f86069 153 if (pd==1) {wait(0.5); menu=3;}
linx0576 3:7edb43f86069 154 if (ps==1) {wait(0.5); TFT.cls(); stage=3;}
linx0576 1:f1f3dfff9107 155 }
linx0576 1:f1f3dfff9107 156
linx0576 1:f1f3dfff9107 157 if (menu==3) //return
linx0576 3:7edb43f86069 158 {
linx0576 1:f1f3dfff9107 159 TFT.rect(15,155,220,185,Black);
linx0576 3:7edb43f86069 160 TFT.rect(15,255,220,285,Green);
linx0576 3:7edb43f86069 161 pu = ain1.read();
linx0576 3:7edb43f86069 162 pd = ain2.read();
linx0576 3:7edb43f86069 163 ps = ain3.read();
linx0576 3:7edb43f86069 164 if (pu==1) {wait(0.5); menu=2;}
linx0576 3:7edb43f86069 165 if (ps==1) {wait(0.5); TFT.cls(); stage=3;} // main return...
linx0576 3:7edb43f86069 166 }
linx0576 1:f1f3dfff9107 167 }
linx0576 1:f1f3dfff9107 168
linx0576 1:f1f3dfff9107 169 if (stage==1) //Configuration
linx0576 3:7edb43f86069 170 {
linx0576 3:7edb43f86069 171 int i=0;
linx0576 3:7edb43f86069 172 int j=0;
linx0576 3:7edb43f86069 173 int ia, ib, ja, jb;
linx0576 3:7edb43f86069 174 int config=0;
linx0576 1:f1f3dfff9107 175 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 176 TFT.locate(20,60);
linx0576 1:f1f3dfff9107 177 printf("SET PERIOD");
linx0576 1:f1f3dfff9107 178 TFT.rect(15,55, 220,85,Red);
linx0576 3:7edb43f86069 179 TFT.locate(68,150);
linx0576 3:7edb43f86069 180 TFT.printf("Hr Min");
linx0576 3:7edb43f86069 181
linx0576 1:f1f3dfff9107 182 TFT.set_font((unsigned char*) Arial12x12);
linx0576 1:f1f3dfff9107 183 TFT.locate(40,270);
linx0576 1:f1f3dfff9107 184 printf("Set");
linx0576 1:f1f3dfff9107 185 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 186 printf("Return");
linx0576 3:7edb43f86069 187 TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 188 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 189 TFT.rect(15,265,85,285,Olive); //Green
linx0576 3:7edb43f86069 190 TFT.rect(150,265,220,285,Olive);
linx0576 3:7edb43f86069 191
linx0576 3:7edb43f86069 192 while (stage==1)
linx0576 3:7edb43f86069 193 { ia=i-1; if (i==0) ia=23;
linx0576 3:7edb43f86069 194 ib=i+1; if (i==23) ib=0;
linx0576 3:7edb43f86069 195 ja=j-1; if (j==0) ja=59;
linx0576 3:7edb43f86069 196 jb=j+1; if (j==59) jb=00;
linx0576 3:7edb43f86069 197
linx0576 1:f1f3dfff9107 198 TFT.set_font((unsigned char*) Arial24x23);
linx0576 3:7edb43f86069 199 TFT.locate(26,150);
linx0576 3:7edb43f86069 200 if (i<10) TFT.printf("0%i", i);
linx0576 3:7edb43f86069 201 else if (i>=10) TFT.printf("%i", i);
linx0576 3:7edb43f86069 202 TFT.locate(120,150);
linx0576 3:7edb43f86069 203 if (j<10) TFT.printf("0%i", j);
linx0576 3:7edb43f86069 204 else if (j>=10) TFT.printf("%i", j);
linx0576 3:7edb43f86069 205
linx0576 1:f1f3dfff9107 206 TFT.set_font((unsigned char*) Arial12x12);
linx0576 3:7edb43f86069 207 TFT.locate(40,130);
linx0576 3:7edb43f86069 208 if (ia<10) TFT.printf("0%i", ia);
linx0576 3:7edb43f86069 209 else if (ia>=10) TFT.printf("%i", ia);
linx0576 3:7edb43f86069 210 TFT.locate(40,180);
linx0576 3:7edb43f86069 211 if (ib<10) TFT.printf("0%i", ib);
linx0576 3:7edb43f86069 212 else if (ib>=10) TFT.printf("%i", ib);
linx0576 3:7edb43f86069 213 TFT.locate(135,130);
linx0576 3:7edb43f86069 214 if (ja<10) TFT.printf("0%i", ja);
linx0576 3:7edb43f86069 215 else if (ja>=10) TFT.printf("%i", ja);
linx0576 3:7edb43f86069 216 TFT.locate(135,180);
linx0576 3:7edb43f86069 217 if (jb<10) TFT.printf("0%i", jb);
linx0576 3:7edb43f86069 218 else if (jb>=10) TFT.printf("%i", jb);
linx0576 3:7edb43f86069 219
linx0576 3:7edb43f86069 220 if (config==0)
linx0576 3:7edb43f86069 221 { TFT.rect(24,145, 64,175,Green); //Cyan
linx0576 3:7edb43f86069 222 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 223 pu = ain1.read();
linx0576 3:7edb43f86069 224 pd = ain2.read();
linx0576 3:7edb43f86069 225 ps = ain3.read();
linx0576 3:7edb43f86069 226 if (pu==1) {wait(0.5); i=ib; }
linx0576 3:7edb43f86069 227 if (pd==1) {wait(0.5); i=ia; }
linx0576 3:7edb43f86069 228 if (ps==1) {wait(0.5); config=1;}
linx0576 1:f1f3dfff9107 229 }
linx0576 3:7edb43f86069 230 if (config==1)
linx0576 3:7edb43f86069 231 { TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 232 TFT.rect(119,145,159,175,Green);
linx0576 3:7edb43f86069 233 pu = ain1.read();
linx0576 3:7edb43f86069 234 pd = ain2.read();
linx0576 3:7edb43f86069 235 ps = ain3.read();
linx0576 3:7edb43f86069 236 if (pu==1) {wait(0.5); j=jb; }
linx0576 3:7edb43f86069 237 if (pd==1) {wait(0.5); j=ja; }
linx0576 3:7edb43f86069 238 if (ps==1) {wait(0.5); config=2;}
linx0576 1:f1f3dfff9107 239 }
linx0576 3:7edb43f86069 240 if (config==2)
linx0576 3:7edb43f86069 241 { TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 242 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 243 TFT.rect(15,265,85,285,Green); //Green
linx0576 3:7edb43f86069 244 TFT.rect(150,265,220,285,Olive);
linx0576 3:7edb43f86069 245 pu = ain1.read();
linx0576 3:7edb43f86069 246 pd = ain2.read();
linx0576 3:7edb43f86069 247 ps = ain3.read();
linx0576 3:7edb43f86069 248 if (pu==1) {wait(0.5); config=2; }
linx0576 3:7edb43f86069 249 if (pd==1) {wait(0.5); config=3; }
linx0576 3:7edb43f86069 250 if (ps==1) {wait(0.5); TFT.cls(); stage=2;}
linx0576 1:f1f3dfff9107 251 }
linx0576 3:7edb43f86069 252 if (config==3)
linx0576 3:7edb43f86069 253 { TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 254 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 255 TFT.rect(15,265,85,285,Olive); //Green
linx0576 3:7edb43f86069 256 TFT.rect(150,265,220,285,Green);
linx0576 3:7edb43f86069 257 pu = ain1.read();
linx0576 3:7edb43f86069 258 pd = ain2.read();
linx0576 3:7edb43f86069 259 ps = ain3.read();
linx0576 3:7edb43f86069 260 if (pu==1) {wait(0.5); config=2; }
linx0576 3:7edb43f86069 261 if (pd==1) {wait(0.5); config=3; }
linx0576 3:7edb43f86069 262 if (ps==1) {wait(0.5); TFT.cls(); stage=3;}
linx0576 1:f1f3dfff9107 263 }
linx0576 1:f1f3dfff9107 264 }
linx0576 1:f1f3dfff9107 265 }
linx0576 3:7edb43f86069 266
linx0576 1:f1f3dfff9107 267 if (stage==2) //waveform
linx0576 3:7edb43f86069 268 { int abc, x2, y2;
linx0576 1:f1f3dfff9107 269 int x1 = 0;
linx0576 1:f1f3dfff9107 270 int y1 = 100;
linx0576 1:f1f3dfff9107 271 float32_t sum=0;
linx0576 3:7edb43f86069 272 float32_t sum_mse=0;
linx0576 3:7edb43f86069 273 float32_t sum_st=0;
linx0576 1:f1f3dfff9107 274 for(abc=0; abc<num; abc++)
linx0576 1:f1f3dfff9107 275 { a1 = a[abc];
linx0576 1:f1f3dfff9107 276 b1 = b[abc];
linx0576 3:7edb43f86069 277 sum = sum+a[abc];
linx0576 1:f1f3dfff9107 278 arm_sub_f32(&a1, &b1, &subOutput, 1);
linx0576 1:f1f3dfff9107 279 arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1);
linx0576 3:7edb43f86069 280 sum_mse = sum_mse+SquareOutput;
linx0576 1:f1f3dfff9107 281 x2 = abc*2;
linx0576 1:f1f3dfff9107 282 y2 = 80+a1*10;
linx0576 1:f1f3dfff9107 283 TFT.line(x1,y1,x2,y2,Green);
linx0576 1:f1f3dfff9107 284 x1 = x2;
linx0576 3:7edb43f86069 285 y1 = y2;
linx0576 1:f1f3dfff9107 286 }
linx0576 3:7edb43f86069 287 mean = sum/num;
linx0576 3:7edb43f86069 288 mse = sum_mse / num;
linx0576 3:7edb43f86069 289
linx0576 3:7edb43f86069 290 for(abc=0; abc<num; abc++)
linx0576 3:7edb43f86069 291 { a1 = a[abc];
linx0576 3:7edb43f86069 292 arm_sub_f32(&a1, &mean, &subOutput, 1);
linx0576 3:7edb43f86069 293 arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1);
linx0576 3:7edb43f86069 294 sum_st = sum_st+SquareOutput;
linx0576 3:7edb43f86069 295 }
linx0576 3:7edb43f86069 296 st = sqrt(sum_st/num);
linx0576 0:52568bab75f8 297
linx0576 1:f1f3dfff9107 298 TFT.set_font((unsigned char*) Arial12x12);
linx0576 3:7edb43f86069 299
linx0576 3:7edb43f86069 300 TFT.locate(10,130);
linx0576 3:7edb43f86069 301 TFT.printf("Samples number: ");
linx0576 3:7edb43f86069 302 TFT.locate(30,140);
linx0576 3:7edb43f86069 303 TFT.printf("%i", num);
linx0576 3:7edb43f86069 304
linx0576 3:7edb43f86069 305 TFT.locate(10,160);
linx0576 3:7edb43f86069 306 TFT.printf("Sample Mean Value: ");
linx0576 3:7edb43f86069 307 TFT.locate(30,170);
linx0576 3:7edb43f86069 308 TFT.printf("%f", mean);
linx0576 3:7edb43f86069 309
linx0576 1:f1f3dfff9107 310 TFT.locate(10,190);
linx0576 3:7edb43f86069 311 TFT.printf("Standard Deviation: ");
linx0576 3:7edb43f86069 312 TFT.locate(30,200);
linx0576 3:7edb43f86069 313 TFT.printf("%f", st);
linx0576 3:7edb43f86069 314
linx0576 3:7edb43f86069 315 TFT.locate(10,220);
linx0576 1:f1f3dfff9107 316 TFT.printf("Mean Square Error: ");
linx0576 3:7edb43f86069 317 TFT.locate(30,230);
linx0576 3:7edb43f86069 318 TFT.printf("%f", mse);
linx0576 3:7edb43f86069 319
linx0576 1:f1f3dfff9107 320 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 321 printf("Return");
linx0576 3:7edb43f86069 322 TFT.rect(150,265,220,285,Green);
linx0576 3:7edb43f86069 323 ps = ain3.read();
linx0576 3:7edb43f86069 324 if (ps==1) {wait(0.5); TFT.cls(); stage=0;}
linx0576 1:f1f3dfff9107 325 }
linx0576 1:f1f3dfff9107 326
linx0576 1:f1f3dfff9107 327 if (stage==3) //log
linx0576 3:7edb43f86069 328 {
linx0576 1:f1f3dfff9107 329 TFT.set_font((unsigned char*) Arial24x23);
linx0576 3:7edb43f86069 330 TFT.locate(20,20);
linx0576 3:7edb43f86069 331 printf(" Log");
linx0576 3:7edb43f86069 332 int row=50;
linx0576 3:7edb43f86069 333 for(int abc=0; abc<20; abc++)
linx0576 3:7edb43f86069 334 { TFT.set_font((unsigned char*) Arial12x12);
linx0576 3:7edb43f86069 335 TFT.locate(10,row+10*abc);
linx0576 3:7edb43f86069 336 printf("[%i]", abc+1);
linx0576 3:7edb43f86069 337 TFT.locate(60,row+10*abc);
linx0576 3:7edb43f86069 338 printf("%f", mse+abc);
linx0576 3:7edb43f86069 339 }
linx0576 1:f1f3dfff9107 340 TFT.set_font((unsigned char*) Arial12x12);
linx0576 1:f1f3dfff9107 341 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 342 printf("Return");
linx0576 3:7edb43f86069 343 TFT.rect(150,265,220,285,Green);
linx0576 3:7edb43f86069 344 ps = ain3.read();
linx0576 3:7edb43f86069 345 if (ps==1) {wait(0.5); TFT.cls(); stage=0;}
linx0576 1:f1f3dfff9107 346 }
linx0576 1:f1f3dfff9107 347 }
linx0576 1:f1f3dfff9107 348 }