огшор
Dependencies: CMSIS_DSP_401 mbed
Fork of fir_f32 by
Revision 6:173ae8477ae1, committed 2014-11-11
- Comitter:
- Sergeev
- Date:
- Tue Nov 11 16:41:53 2014 +0000
- Parent:
- 4:397e8f4699df
- Commit message:
- q
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 397e8f4699df -r 173ae8477ae1 main.cpp --- a/main.cpp Thu Oct 23 15:58:45 2014 +0000 +++ b/main.cpp Tue Nov 11 16:41:53 2014 +0000 @@ -9,28 +9,42 @@ uint8_t ifftFlag, uint8_t bitReverseFlag); -Serial pc(USBTX, USBRX); +Serial pc(USBTX, USBRX);//:D ПРИВЕТ!!!! + + AnalogIn left(A2); AnalogIn right(A3); +AnalogIn center(A3); int SAMPLE_RATE_HZ = 40000; // Sample rate of the audio in hertz. -const int FFT_SIZE = 16; // Size of the FFT. +//const int FFT_SIZE = 16; // Size of the FFT. +const int FFT_SIZE = 1024; // Size of the FFT. const static arm_cfft_instance_f32 *S; //static arm_cfft_radix2_instance_f32 *S; Ticker samplingTimer; float samples[FFT_SIZE*2]; +float samples2[FFT_SIZE*2]; +float samples3[FFT_SIZE*2]; + float magnitudes[FFT_SIZE]; +float magnitudes2[FFT_SIZE]; +float magnitudes3[FFT_SIZE]; int sampleCounter = 0; + void samplingCallback() { // Read from the ADC and store the sample data samples[sampleCounter] = 1000*left.read(); + samples2[sampleCounter] = 1000*left.read(); + samples3[sampleCounter] = 1000*left.read(); // Complex FFT functions require a coefficient for the imaginary part of the input. // Since we only have real data, set this coefficient to zero. samples[sampleCounter+1] = 0.0; + samples2[sampleCounter+1] = 0.0; + samples3[sampleCounter+1] = 0.0; // Update sample buffer position and stop after the buffer is filled sampleCounter += 2; @@ -89,7 +103,12 @@ break; } float maxValue = 0.0f; + float maxValue2 = 0.0f; + float maxValue3 = 0.0f; + unsigned int testIndex = 0; + unsigned int testIndex2 = 0; + unsigned int testIndex3 = 0; // Begin sampling audio samplingBegin(); @@ -102,24 +121,54 @@ // Run FFT on sample data. //arm_cfft_radix2_f32(arm_cfft_radix2_instance_f32*S, samples); arm_cfft_f32(S, samples, 0, 1); - samples[0] = 0; + arm_cfft_f32(S, samples2, 0, 1); + arm_cfft_f32(S, samples3, 0, 1); + samples[0]=0; + samples2[0]=0; + samples3[0]=0; + /* Initialize the CFFT/CIFFT module */ //arm_cfft_radix2_init_f32(S, 128, 0, 1); //arm_cfft_radix2_f32(S, samples); - for(int i = 0;i < FFT_SIZE*2;++i) - pc.printf(" Samples[%d]: %8.2f ",i,samples[i]); - pc.printf("\r\n"); + //for(int i = 0;i < FFT_SIZE*2;++i) + // pc.printf(" Samples[%d]: %8.2f ",i,samples[i]); + //pc.printf("\r\n"); // Calculate magnitude of complex numbers output by the FFT. arm_cmplx_mag_f32(samples, magnitudes, FFT_SIZE); - for(int i = 0;i < FFT_SIZE;++i) - pc.printf(" Magnitude: %d = %8.2f ;", i, magnitudes[i]); - pc.printf(" \r\n"); + arm_cmplx_mag_f32(samples2, magnitudes2, FFT_SIZE); + arm_cmplx_mag_f32(samples3, magnitudes3, FFT_SIZE); + + //for(int i = 0;i < FFT_SIZE;++i) + // pc.printf(" Magnitude: %d = %8.2f ;", i, magnitudes[i]); + //pc.printf(" \r\n"); arm_max_f32(magnitudes, FFT_SIZE, &maxValue, &testIndex); - pc.printf(" MAX value at magnitudes[%d] : %+8.2f\r\n", testIndex, maxValue); + arm_max_f32(magnitudes2, FFT_SIZE, &maxValue2, &testIndex2); + arm_max_f32(magnitudes3, FFT_SIZE, &maxValue3, &testIndex3); + pc.printf(" MAX value at magnitudes 1[%d] : %+8.2f\r\n", testIndex, maxValue);//Я НЯШКА А АНЯ ВЛАСЮК КОЗА:DDDDDDDDDDDDD + pc.printf(" MAX value at magnitudes 2[%d] : %+8.2f\r\n", testIndex2, maxValue2); + pc.printf(" MAX value at magnitudes 3[%d] : %+8.2f\r\n", testIndex3, maxValue3); + + double delta_t = 0; + if ((testIndex < testIndex2) and (testIndex < testIndex3) and (testIndex2 < testIndex3)) + delta_t = (testIndex3 - testIndex)*0.000025; + else if ((testIndex < testIndex2)and(testIndex < testIndex3)and(testIndex2 > testIndex3)) + delta_t = (testIndex2 - testIndex)*0.000025; + else if ((testIndex2 < testIndex3)and(testIndex2 < testIndex)and(testIndex < testIndex3)) + delta_t = (testIndex3 - testIndex2)*0.000025; + else if ((testIndex2 < testIndex3)and(testIndex2 < testIndex)and(testIndex > testIndex3)) + delta_t = (testIndex - testIndex3)*0.000025; + else if (testIndex2 < testIndex) + delta_t = (testIndex - testIndex3)*0.000025; + else + delta_t = (testIndex - testIndex2)*0.000025; + double fi = asin(330*delta_t/0.33); + pc.printf(" Angle is : %+8.2f\r\n", fi); + // Wait for user confirmation to restart audio sampling. //pc.getc(); wait(1); samplingBegin(); } } -} \ No newline at end of file +} +