- Main Page
- Files

# C:/Users/Michael/Desktop/trunk/program/demo/runfftlistener.c File Reference

The frequency recognizer using FFT. More...

`#include <p30Fxxxx.h>`
`#include <dsp.h>`
`#include "math.h"`
`#include "motor_led/e_epuck_ports.h"`
`#include "motor_led/e_init_port.h"`
`#include "a_d/advance_ad_scan/e_ad_conv.h"`
`#include "fft/e_fft.h"`
`#include "fft/e_fft_utilities.h"`
`#include "motor_led/advance_one_timer/e_motors.h"`
`#include "motor_led/advance_one_timer/e_agenda.h"`
`#include "motor_led/advance_one_timer/e_led.h"`

## Functions
int | localise_pic_max (fractcomplex *spectre, int spectre_length)
| Localize the bigger pic of the array.
int | get_volume (fractcomplex *spectre, int pic_pos)
| Get the max volume of the sound detected.
void | display_volume_on_led (int volume)
| Display the volume of the soud detected on the LEDs.
int | calcul_frequence (int pic_pos)
| Calcul the corresponding frequency of the bigger pic detected.
void | set_speed (int frequency)
| Set the speed of the e-puck.
void | run_fft_listener (void)
| The "main" function of the demo.

## Detailed Description

The frequency recognizer using FFT.

## Introduction

The runfftlistener programm is made to illustrate how you can use the FFT package of the library. The goal is to determine the frequency of the sound comming from the microphone number 0. If the frequency is under 900Hz the e-puck will turn left. If the frequency is between 900Hz and 1800Hz the e-puck will go forward. If the frequency is over 1800Hz the e-puck will turn right.

## Playing the demo

First of all, move the selector to the position 9 to 15 and reset the e-puck. To play the demo, you have two allternatives:

- You are a good whistler. In this case you can drive the e-puck with your mouse by whistling in the good frequency.
- You do not know whistlering. In this case you can play the "sound1.mp3" or "sound2.mp3" which are in the folder "demo" to drive the e-puck.

## Video of the demo

- Driving the e-puck by whistlering and playing sound on PC: http://www.youtube.com/watch?v=bfHFo79uZGY

Author:
  Code: Michael Bonani, Jonathan Besuchet
  Doc: Jonathan Besuchet

## Function Documentation

int calcul_frequence | ( | int | pic_pos | ) |

Calcul the corresponding frequency of the bigger pic detected.

Parameters:

  | pic_pos | The index of the bigger pic detected

Returns:
  The corresponding frequency

void display_volume_on_led | ( | int | volume | ) |

Display the volume of the soud detected on the LEDs.

Parameters:

  | volume | The max volume of the sound detected

int get_volume | ( | fractcomplex * | spectre,
|  | int | pic_pos |
| ) |  |  |

Get the max volume of the sound detected.

Parameters:

  | spectre | The array in which the FFT was made
  | pic_pos | The index of the louder frequency

Returns:
  The amplitude of the louder frequency

int localise_pic_max | ( | fractcomplex * | spectre,
|  | int | spectre_length |
| ) |  |  |

Localize the bigger pic of the array.

Parameters:

  | spectre | The array in which the FFT was made
  | spectre_length | The length of the scan in the array

Returns:
  The index of the bigger pic detected

void set_speed | ( | int | frequency | ) |

Set the speed of the e-puck.

Set the speed of the e-puck relatively of the frequency of the sound detected.

- Turn left if the frequency is under 900Hz
- Turn right if the frequency is over 1800Hz
- Go forward if the sound is between 900Hz and 1800Hz

Parameters:

  | frequency | The frequence of the sound