Jared's DAC Code
Dependencies: mbed
Fork of Chemical_Sensor_DMA by
Diff: SignalProcessing.cpp
- Revision:
- 5:1b2dc43e8947
- Parent:
- 4:9fd291254686
- Child:
- 6:63de50ac29be
--- a/SignalProcessing.cpp Fri Nov 06 03:33:09 2015 +0000 +++ b/SignalProcessing.cpp Fri Nov 06 19:28:49 2015 +0000 @@ -254,7 +254,7 @@ - +/* #define FIR_100_LENGTH 64 float FIR100_Sample1_i[FIR_100_LENGTH]; float FIR100_Sample1_q[FIR_100_LENGTH]; @@ -418,12 +418,12 @@ } } +*/ - - +#define NUMSAMPLESAVERAGE 100 #define FIR_1K_LENGTH 32 float FIR1K_Sample1_i[FIR_1K_LENGTH]; float FIR1K_Sample1_q[FIR_1K_LENGTH]; @@ -469,6 +469,13 @@ #define DecimationFactor_10K 10 void filter1K(float FIR1K_Sample1_i_input, float FIR1K_Sample1_q_input, float FIR1K_Sample2_i_input, float FIR1K_Sample2_q_input) { + static float Final_Average1_i=0; + static float Final_Average1_q=0;//when decimating sum up all 10 samples at a time have that be your output value + static float Final_Average2_i=0; + static float Final_Average2_q=0; + + + static uint8_t decimationCounter = 0;//used to keep track of how many samples you have currently decimated static float FIR1K_Sample1_i_DecimatedSum=0; static float FIR1K_Sample1_q_DecimatedSum=0;//when decimating sum up all 10 samples at a time have that be your output value @@ -518,10 +525,26 @@ FIR1K_Sample2_i_Output += FIR1K_Sample2_i[fir_index] * lp_1K_coeff[fir_counter]; FIR1K_Sample2_q_Output += FIR1K_Sample2_q[fir_index] * lp_1K_coeff[fir_counter]; } + Final_Average1_i+=FIR1K_Sample1_i_Output; + Final_Average1_q+=FIR1K_Sample1_q_Output;//when decimating sum up all 10 samples at a time have that be your output value + Final_Average2_i+=FIR1K_Sample2_i_Output; + Final_Average2_q+=FIR1K_Sample2_q_Output; + finalAverageCounter++; + if (finalAverageCounter>=NUMSAMPLESAVERAGE) + { + finalAverageCounter=0; + float mag1 = sqrt(Final_Average1_i*Final_Average1_i+Final_Average1_q*Final_Average1_q); + float mag2 = sqrt(Final_Average2_i*Final_Average2_i+Final_Average2_q*Final_Average2_q); + printf("V1: %f\tV2: %f\tRatio: %f\n\r",mag1,mag2,mag2/mag1); + Final_Average1_i=0; + Final_Average1_q=0;//when decimating sum up all 10 samples at a time have that be your output value + Final_Average2_i=0; + Final_Average2_q=0; + } //float mag1 = sqrt(FIR1K_Sample1_i_Output*FIR1K_Sample1_i_Output+FIR1K_Sample1_q_Output*FIR1K_Sample1_q_Output); //float mag2 = sqrt(FIR1K_Sample2_i_Output*FIR1K_Sample2_i_Output+FIR1K_Sample2_q_Output*FIR1K_Sample2_q_Output); //printf("V1: %f\tV2: %f\n\r",mag1,mag2); - filter100(FIR1K_Sample1_i_Output, FIR1K_Sample1_q_Output, FIR1K_Sample2_i_Output, FIR1K_Sample2_q_Output); + //filter100(FIR1K_Sample1_i_Output, FIR1K_Sample1_q_Output, FIR1K_Sample2_i_Output, FIR1K_Sample2_q_Output); } }