Senior Design: Sound Monitor / 4951

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Committer:
linx0576
Date:
Mon Nov 09 19:44:43 2015 +0000
Revision:
0:52568bab75f8
Child:
1:f1f3dfff9107
Team Riedel

Who changed what in which revision?

UserRevisionLine numberNew contents of line
linx0576 0:52568bab75f8 1 // example to test the TFT Display
linx0576 0:52568bab75f8 2 // Thanks to the GraphicsDisplay and TextDisplay classes
linx0576 0:52568bab75f8 3 // test2.bmp has to be on the mbed file system
linx0576 0:52568bab75f8 4
linx0576 0:52568bab75f8 5 //#define NO_DMA
linx0576 0:52568bab75f8 6 #include <math.h>
linx0576 0:52568bab75f8 7 #include "stdio.h"
linx0576 0:52568bab75f8 8 #include "mbed.h"
linx0576 0:52568bab75f8 9 #include "SPI_TFT_ILI9341.h"
linx0576 0:52568bab75f8 10 #include "string"
linx0576 0:52568bab75f8 11 #include "Arial12x12.h"
linx0576 0:52568bab75f8 12 #include "Arial24x23.h"
linx0576 0:52568bab75f8 13 #include "Arial_9.h"
linx0576 0:52568bab75f8 14 #include "arm_math.h"
linx0576 0:52568bab75f8 15 #define pi 3.1415926
linx0576 0:52568bab75f8 16 #define num 128
linx0576 0:52568bab75f8 17
linx0576 0:52568bab75f8 18
linx0576 0:52568bab75f8 19 /** External Input and Output buffer Declarations for FFT Bin Example **/
linx0576 0:52568bab75f8 20 static float32_t testInput_f32_10khz[num];
linx0576 0:52568bab75f8 21
linx0576 0:52568bab75f8 22 /** Global variables for FFT Bin Example **/
linx0576 0:52568bab75f8 23 uint32_t ifftFlag = 0;
linx0576 0:52568bab75f8 24 uint32_t doBitReverse = 1;
linx0576 0:52568bab75f8 25
linx0576 0:52568bab75f8 26 /* Reference index at which max energy of bin ocuurs */
linx0576 0:52568bab75f8 27 uint32_t refIndex = 213, testIndex = 0;
linx0576 0:52568bab75f8 28
linx0576 0:52568bab75f8 29 extern unsigned char p1[]; // the mbed logo
linx0576 0:52568bab75f8 30 const float32_t a[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
linx0576 0:52568bab75f8 31 0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
linx0576 0:52568bab75f8 32 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
linx0576 0:52568bab75f8 33 -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 0:52568bab75f8 34 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620,
linx0576 0:52568bab75f8 35 -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426,
linx0576 0:52568bab75f8 36 -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287,
linx0576 0:52568bab75f8 37 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 0:52568bab75f8 38 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279,
linx0576 0:52568bab75f8 39 -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
linx0576 0:52568bab75f8 40 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
linx0576 0:52568bab75f8 41 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 0:52568bab75f8 42 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
linx0576 0:52568bab75f8 43 0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
linx0576 0:52568bab75f8 44 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
linx0576 0:52568bab75f8 45 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 46 };
linx0576 0:52568bab75f8 47 const float32_t b[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
linx0576 0:52568bab75f8 48 0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
linx0576 0:52568bab75f8 49 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
linx0576 0:52568bab75f8 50 -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
linx0576 0:52568bab75f8 51 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
linx0576 0:52568bab75f8 52 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 0:52568bab75f8 53 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
linx0576 0:52568bab75f8 54 0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
linx0576 0:52568bab75f8 55 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
linx0576 0:52568bab75f8 56 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 57 -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430,
linx0576 0:52568bab75f8 58 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620, -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910,
linx0576 0:52568bab75f8 59 -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387,
linx0576 0:52568bab75f8 60 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723,
linx0576 0:52568bab75f8 61 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834,
linx0576 0:52568bab75f8 62 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644,
linx0576 0:52568bab75f8 63 };
linx0576 0:52568bab75f8 64 float32_t a1, b1;
linx0576 0:52568bab75f8 65 float32_t subOutput, SquareOutput;
linx0576 0:52568bab75f8 66
linx0576 0:52568bab75f8 67 SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
linx0576 0:52568bab75f8 68
linx0576 0:52568bab75f8 69 int main()
linx0576 0:52568bab75f8 70 {
linx0576 0:52568bab75f8 71 int i;
linx0576 0:52568bab75f8 72
linx0576 0:52568bab75f8 73 arm_cfft_radix2_instance_f32 S;
linx0576 0:52568bab75f8 74
linx0576 0:52568bab75f8 75 TFT.claim(stdout); // send stdout to the TFT display
linx0576 0:52568bab75f8 76 TFT.claim(stderr); // send stderr to the TFT display
linx0576 0:52568bab75f8 77 //TFT.set_orientation(1); // comment out = "||" include = "="
linx0576 0:52568bab75f8 78 TFT.background(Black); // set background to black
linx0576 0:52568bab75f8 79 TFT.foreground(White); // set chars to white
linx0576 0:52568bab75f8 80 TFT.cls(); // clear the screen
linx0576 0:52568bab75f8 81
linx0576 0:52568bab75f8 82 TFT.background(Black);
linx0576 0:52568bab75f8 83 TFT.cls();
linx0576 0:52568bab75f8 84
linx0576 0:52568bab75f8 85 // greeting
linx0576 0:52568bab75f8 86 TFT.set_font((unsigned char*) Arial24x23);
linx0576 0:52568bab75f8 87 TFT.locate(20,60);
linx0576 0:52568bab75f8 88 printf("Team Riedel");
linx0576 0:52568bab75f8 89 TFT.set_font((unsigned char*) Arial24x23);
linx0576 0:52568bab75f8 90 TFT.locate(30,110);
linx0576 0:52568bab75f8 91 TFT.printf("We are");
linx0576 0:52568bab75f8 92 TFT.set_font((unsigned char*) Arial24x23);
linx0576 0:52568bab75f8 93 TFT.locate(40,160);
linx0576 0:52568bab75f8 94 TFT.printf("Awesome!!");
linx0576 0:52568bab75f8 95 wait(2);
linx0576 0:52568bab75f8 96
linx0576 0:52568bab75f8 97 // draw some graphics
linx0576 0:52568bab75f8 98 TFT.cls();
linx0576 0:52568bab75f8 99 TFT.set_font((unsigned char*) Arial24x23);
linx0576 0:52568bab75f8 100 TFT.locate(100,100);
linx0576 0:52568bab75f8 101 TFT.printf("Graphic");
linx0576 0:52568bab75f8 102
linx0576 0:52568bab75f8 103 TFT.line(0,0,100,0,Green);
linx0576 0:52568bab75f8 104 TFT.line(0,0,0,200,Green);
linx0576 0:52568bab75f8 105 TFT.line(0,0,100,200,Green);
linx0576 0:52568bab75f8 106
linx0576 0:52568bab75f8 107 TFT.rect(100,50,150,100,Red);
linx0576 0:52568bab75f8 108 TFT.fillrect(180,25,220,70,Blue);
linx0576 0:52568bab75f8 109
linx0576 0:52568bab75f8 110 TFT.circle(80,150,33,White);
linx0576 0:52568bab75f8 111 TFT.fillcircle(160,190,20,Yellow);
linx0576 0:52568bab75f8 112
linx0576 0:52568bab75f8 113 double s;
linx0576 0:52568bab75f8 114
linx0576 0:52568bab75f8 115 for (i=0; i<320; i++) {
linx0576 0:52568bab75f8 116 s = 20 * sin((long double) i / 10 );
linx0576 0:52568bab75f8 117 TFT.pixel(i,100 + (int)s ,Red);
linx0576 0:52568bab75f8 118 }
linx0576 0:52568bab75f8 119 wait(2); // wait two seconds
linx0576 0:52568bab75f8 120
linx0576 0:52568bab75f8 121 /* // mbed logo
linx0576 0:52568bab75f8 122 TFT.background(Black);
linx0576 0:52568bab75f8 123 TFT.cls();
linx0576 0:52568bab75f8 124 TFT.locate(10,10);
linx0576 0:52568bab75f8 125 TFT.printf("Graphic from Flash");
linx0576 0:52568bab75f8 126 TFT.Bitmap(90,90,172,55,S);*/
linx0576 0:52568bab75f8 127
linx0576 0:52568bab75f8 128 TFT.cls();
linx0576 0:52568bab75f8 129
linx0576 0:52568bab75f8 130 //uint32_t i;
linx0576 0:52568bab75f8 131 int abc, x2, y2;
linx0576 0:52568bab75f8 132 int x1 = 0;
linx0576 0:52568bab75f8 133 int y1 = 100;
linx0576 0:52568bab75f8 134 float32_t sum=0;
linx0576 0:52568bab75f8 135 float32_t k=0;
linx0576 0:52568bab75f8 136
linx0576 0:52568bab75f8 137 for(abc=0; abc<num; abc++)
linx0576 0:52568bab75f8 138 {
linx0576 0:52568bab75f8 139 a1 = a[abc];
linx0576 0:52568bab75f8 140 b1 = b[abc];
linx0576 0:52568bab75f8 141 arm_sub_f32(&a1, &b1, &subOutput, 1);
linx0576 0:52568bab75f8 142 arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1);
linx0576 0:52568bab75f8 143 sum = sum+SquareOutput;
linx0576 0:52568bab75f8 144 //TFT.pixel(abc*2, 100+a1*10, Red);
linx0576 0:52568bab75f8 145
linx0576 0:52568bab75f8 146 x2 = abc*2;
linx0576 0:52568bab75f8 147 y2 = 100+a1*10;
linx0576 0:52568bab75f8 148 TFT.line(x1,y1,x2,y2,Green);
linx0576 0:52568bab75f8 149 x1 = x2;
linx0576 0:52568bab75f8 150 y1 = y2;
linx0576 0:52568bab75f8 151 }
linx0576 0:52568bab75f8 152 k = sum / num;
linx0576 0:52568bab75f8 153
linx0576 0:52568bab75f8 154 TFT.set_font((unsigned char*) Arial12x12);
linx0576 0:52568bab75f8 155 TFT.locate(10,210);
linx0576 0:52568bab75f8 156 TFT.printf("sum: %f", sum);
linx0576 0:52568bab75f8 157 TFT.locate(10,220);
linx0576 0:52568bab75f8 158 TFT.printf("num: %i", num);
linx0576 0:52568bab75f8 159 TFT.locate(10,240);
linx0576 0:52568bab75f8 160 TFT.printf("Mean Square Error: ");
linx0576 0:52568bab75f8 161 TFT.locate(10,250);
linx0576 0:52568bab75f8 162 TFT.printf(" %f", k);
linx0576 0:52568bab75f8 163
linx0576 0:52568bab75f8 164 /* * - arm_cfft_radix2_init_f32()
linx0576 0:52568bab75f8 165 * - arm_cfft_radix2_f32()
linx0576 0:52568bab75f8 166 * - arm_cmplx_mag_f32()
linx0576 0:52568bab75f8 167 * - arm_max_f32()
linx0576 0:52568bab75f8 168 */
linx0576 0:52568bab75f8 169
linx0576 0:52568bab75f8 170 /* Initialize the CFFT/CIFFT module */
linx0576 0:52568bab75f8 171 arm_cfft_radix2_init_f32(&S, num, ifftFlag, doBitReverse);
linx0576 0:52568bab75f8 172
linx0576 0:52568bab75f8 173 /* Process the data through the CFFT/CIFFT module */
linx0576 0:52568bab75f8 174 arm_cfft_radix2_f32(&S, testInput_f32_10khz);
linx0576 0:52568bab75f8 175
linx0576 0:52568bab75f8 176 /* Process the data through the Complex Magnitude Module for calculating the magnitude at each bin */
linx0576 0:52568bab75f8 177 // arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, num);
linx0576 0:52568bab75f8 178
linx0576 0:52568bab75f8 179 /* Calculates maxValue and returns corresponding BIN value */
linx0576 0:52568bab75f8 180 // arm_max_f32(testOutput, num, &maxValue, &testIndex);
linx0576 0:52568bab75f8 181 }
linx0576 0:52568bab75f8 182