NucleoF401RE EMG sensor with 2channel 16band FFT, mixed 7band XBee send, only test

Dependencies:   mbed

Committer:
nagasm
Date:
Sat Dec 20 05:22:00 2014 +0000
Revision:
0:5e2a4b964485
NucleoF401RE EMG sensor with 2channel 16band FFT, mixed 7band XBee send, only test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nagasm 0:5e2a4b964485 1 // http://www.mit.edu/~emin/source_code/fft/index.html
nagasm 0:5e2a4b964485 2
nagasm 0:5e2a4b964485 3 #define SIN_2PI_16 0.38268343236508978
nagasm 0:5e2a4b964485 4 #define SIN_4PI_16 0.707106781186547460
nagasm 0:5e2a4b964485 5 #define SIN_6PI_16 0.923879532511286740
nagasm 0:5e2a4b964485 6 #define C_P_S_2PI_16 1.30656296487637660
nagasm 0:5e2a4b964485 7 #define C_M_S_2PI_16 0.54119610014619690
nagasm 0:5e2a4b964485 8 #define C_P_S_6PI_16 1.3065629648763766
nagasm 0:5e2a4b964485 9 #define C_M_S_6PI_16 -0.54119610014619690
nagasm 0:5e2a4b964485 10
nagasm 0:5e2a4b964485 11 void fft1(float input[16],float output[16] ) {
nagasm 0:5e2a4b964485 12 float temp, out0, out1, out2, out3, out4, out5, out6, out7, out8;
nagasm 0:5e2a4b964485 13 float out9,out10,out11,out12,out13,out14,out15;
nagasm 0:5e2a4b964485 14
nagasm 0:5e2a4b964485 15 out0=input[0]+input[8]; /* output[0 through 7] is the data that we */
nagasm 0:5e2a4b964485 16 out1=input[1]+input[9]; /* take the 8 point real FFT of. */
nagasm 0:5e2a4b964485 17 out2=input[2]+input[10];
nagasm 0:5e2a4b964485 18 out3=input[3]+input[11];
nagasm 0:5e2a4b964485 19 out4=input[4]+input[12];
nagasm 0:5e2a4b964485 20 out5=input[5]+input[13];
nagasm 0:5e2a4b964485 21 out6=input[6]+input[14];
nagasm 0:5e2a4b964485 22 out7=input[7]+input[15];
nagasm 0:5e2a4b964485 23 out8=input[0]-input[8]; /* inputs 8,9,10,11 are */
nagasm 0:5e2a4b964485 24 out9=input[1]-input[9]; /* the Real part of the */
nagasm 0:5e2a4b964485 25 out10=input[2]-input[10]; /* 4 point Complex FFT inputs.*/
nagasm 0:5e2a4b964485 26 out11=input[3]-input[11];
nagasm 0:5e2a4b964485 27 out12=input[12]-input[4]; /* outputs 12,13,14,15 are */
nagasm 0:5e2a4b964485 28 out13=input[13]-input[5]; /* the Imaginary pars of */
nagasm 0:5e2a4b964485 29 out14=input[14]-input[6]; /* the 4 point Complex FFT inputs.*/
nagasm 0:5e2a4b964485 30 out15=input[15]-input[7];
nagasm 0:5e2a4b964485 31 temp=(out13-out9)*(SIN_2PI_16);
nagasm 0:5e2a4b964485 32 out9=out9*(C_P_S_2PI_16)+temp;
nagasm 0:5e2a4b964485 33 out13=out13*(C_M_S_2PI_16)+temp;
nagasm 0:5e2a4b964485 34 out14*=(SIN_4PI_16);
nagasm 0:5e2a4b964485 35 out10*=(SIN_4PI_16);
nagasm 0:5e2a4b964485 36 out14=out14-out10;
nagasm 0:5e2a4b964485 37 out10=out14+out10+out10;
nagasm 0:5e2a4b964485 38 temp=(out15-out11)*(SIN_6PI_16);
nagasm 0:5e2a4b964485 39 out11=out11*(C_P_S_6PI_16)+temp;
nagasm 0:5e2a4b964485 40 out15=out15*(C_M_S_6PI_16)+temp;
nagasm 0:5e2a4b964485 41 out8+=out10;
nagasm 0:5e2a4b964485 42 out10=out8-out10-out10;
nagasm 0:5e2a4b964485 43 out12+=out14;
nagasm 0:5e2a4b964485 44 out14=out12-out14-out14;
nagasm 0:5e2a4b964485 45 out9+=out11;
nagasm 0:5e2a4b964485 46 out11=out9-out11-out11;
nagasm 0:5e2a4b964485 47 out13+=out15;
nagasm 0:5e2a4b964485 48 out15=out13-out15-out15;
nagasm 0:5e2a4b964485 49 output[1]=out8+out9;
nagasm 0:5e2a4b964485 50 output[7]=out8-out9;
nagasm 0:5e2a4b964485 51 output[9]=out12+out13;
nagasm 0:5e2a4b964485 52 output[15]=out13-out12;
nagasm 0:5e2a4b964485 53 output[5]=out10+out15; /* implicit multiplies by */
nagasm 0:5e2a4b964485 54 output[13]=out14-out11; /* a twiddle factor of -j */
nagasm 0:5e2a4b964485 55 output[3]=out10-out15; /* implicit multiplies by */
nagasm 0:5e2a4b964485 56 output[11]=-out14-out11; /* a twiddle factor of -j */
nagasm 0:5e2a4b964485 57 out0=out0+out4;
nagasm 0:5e2a4b964485 58 out4=out0-out4-out4;
nagasm 0:5e2a4b964485 59 out1=out1+out5;
nagasm 0:5e2a4b964485 60 out5=out1-out5-out5;
nagasm 0:5e2a4b964485 61 out2+=out6;
nagasm 0:5e2a4b964485 62 out6=out2-out6-out6;
nagasm 0:5e2a4b964485 63 out3+=out7;
nagasm 0:5e2a4b964485 64 out7=out3-out7-out7;
nagasm 0:5e2a4b964485 65 output[0]=out0+out2;
nagasm 0:5e2a4b964485 66 output[4]=out0-out2;
nagasm 0:5e2a4b964485 67 out1+=out3;
nagasm 0:5e2a4b964485 68 output[12]=out3+out3-out1;
nagasm 0:5e2a4b964485 69 output[0]+=out1; /* Real Part of X[0] */
nagasm 0:5e2a4b964485 70 output[8]=output[0]-out1-out1; /*Real Part of X[4] */
nagasm 0:5e2a4b964485 71 out5*=SIN_4PI_16;
nagasm 0:5e2a4b964485 72 out7*=SIN_4PI_16;
nagasm 0:5e2a4b964485 73 out5=out5-out7;
nagasm 0:5e2a4b964485 74 out7=out5+out7+out7;
nagasm 0:5e2a4b964485 75 output[14]=out6-out7; /* Imag Part of X[5] */
nagasm 0:5e2a4b964485 76 output[2]=out5+out4; /* Real Part of X[7] */
nagasm 0:5e2a4b964485 77 output[6]=out4-out5; /*Real Part of X[5] */
nagasm 0:5e2a4b964485 78 output[10]=-out7-out6; /* Imag Part of X[7] */
nagasm 0:5e2a4b964485 79 }