//Initialize all the peripherals void init_peripherals(void) { //Hardware modules: init_systick_timer(); //SysTick timer init_usart1(2000000); //USART1 (RS-485 #1) init_usart6(2000000); //USART6 (RS-485 #2) init_rs485_outputs(); init_leds(); init_switches(); init_dio(); //All inputs by default init_adc1(); init_spi4(); //Plan //init_spi5(); //FLASH //init_spi6(); //Expansion init_i2c1(); init_imu(); init_adva_fc_pins(); init_pwr_out(); //Software: init_master_slave_comm(); //All RGB LEDs OFF LEDR(0); LEDG(0); LEDB(0); //Default analog input states: set_default_analog(); }
int main() { int i=0,j=0,level=0; FFTSTART(0); for (i = 0; i < 100000; i++); while(1) { FFTSTART(1); while (!FFTCOMPLETE); // Wait until FFT operation to finish FFTSTART(0); //Read the level signal to determine start of the command level = FFTLEVEL; //Clear the led outputs LEDR(0); //Check if something is being Spoken if (level >60) { //Glow a LED to indicate start of voice LEDR(2); //Save the fft of next 32 samples for(i=0;i<NUM_SAMPLES;i++) { FFTSTART(1); while(!FFTCOMPLETE) // Wait until FFT operation to finish FFTSTART(0); //Save the fftoutput from the fft memory into the array for (j = 0; j < SAMPLE_SIZE; j++) { FFTADDRESS(j); fftcoeff[i*SAMPLE_SIZE+j] = (float)(short)FFTCOEFF; } } //1 sec sample stored LEDR(4); // shift the spectrum into the mel scale melcepstrum_conversion(fftcoeff, SAMPLE_SIZE*NUM_SAMPLES, mel, 12, 8000); LEDR(8); // compute the dct of the mel spectrum dct(mel, mfcc, 12); float sum_mel; //Take the sum of first two coefficients of the dct output //The first two coefficients contains the maximum information sum_mel = (mfcc[0] + fabs(mfcc[1])); LEDG(0); //Clear the output LEDs if(SWITCH & 1){ if(sum_mel > 59) { printf("\nYou said Yes"); printf("\t %f",sum_mel); LEDG(128); } else if(sum_mel> 50 && sum_mel<58) { printf("\nYou said No"); printf("\t %f",sum_mel); LEDG(1); } else if(sum_mel < 60 && sum_mel > 58){ printf("\nPlease be loud and clear!!"); printf("\t %f",sum_mel); } else if(sum_mel < 51 && sum_mel > 45){ printf("\nPlease be loud and clear"); printf("\t %f",sum_mel); } else { printf("\nPlease be loud and clear"); printf("\t %f",sum_mel); } }//switch end printf("\n"); } else { //this represent silence LEDG(0); LEDR(1); } } }