Hello
I had done this code to distinguish between male and female by voice. If the frequency located between 65 Hz and 180 Hz which is for male, the lock will not open. If the frequency was from 150 Hz to 255 Hz which is for female, the lock will be opened. If the frequency located in overlap range 150 to 180, IQR should be performed. The value for Female IQR is more than 0.07 and for male is less than 0.07.
The question is, I didn't perform IQR method, instead i used EMA which is smoothing filter.
When i run the code it always gives the result as female. Can somebody figures why ?! also i done another code for iqr method but it is not working . The codes is below :
EMA method:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Global Variables
int sensorPin =
5; //pin number to use the ADC
int sensorValue = 0; //initialization of sensor variable, equivalent to EMA Y
float EMA_a = 0.3; //initialization of EMA alpha
int EMA_S = 0; //initialization of EMA S
int filter = 0;
const int LockPin = 7;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(115200); //setup of Serial module, 115200 bits/second
EMA_S = analogRead(sensorPin); //set EMA S for t=1
pinMode(LockPin, OUTPUT);
digitalWrite(LockPin, LOW);
}
void loop() {
// set the cursor to column 0, line
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.clear();
lcd.print("SAY A WORD");
sensorValue = analogRead(sensorPin); //read the sensor value using ADC
EMA_S = (EMA_a*sensorValue) + ((1-EMA_a)*EMA_S); //run the EMA
filter = sensorValue - EMA_S; //calculate the high-pass signal
Serial.println(filter);
delay(20); //20ms delay
if (abs(filter)>200 && abs(filter)<1000)
{
lcd.clear();
lcd.print("PROCESSING...");
delay(5000);
lcd.clear();
lcd.print("Female,Access is");
lcd.setCursor(0, 1);
lcd.print("granted");
digitalWrite(LockPin, HIGH);
delay(50000);
}
else if (abs(filter)>1000 )
{
lcd.clear();
lcd.print("PROCESSING...");
delay(5000);
lcd.clear();
lcd.print("Male, Access is");
lcd.setCursor(0, 1);
lcd.print("denied");
digitalWrite(LockPin, LOW);
delay(5000);
}
}
IQR method:
// including the library
#include <LiquidCrystal.h>
#include "iqr.c"
//Initialize variables
const int micPin = A5;
const int LockPin = 7;
int soundArray[500];
int a=3.3097994987, b= 3.31107769; //voltage equivalent to 165(a) and 180(b) Hz frequency
int i;
float iqrVal;
//Connections of LCD pins with Arduino board
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
//Input and output pins are assigned
pinMode(micPin, INPUT);
pinMode(LockPin, OUTPUT);
//set your COM accordingly
Serial.begin (9600);
// set up the LCD's number of columns and rows:
//16 columns and two rows
lcd.begin(16, 2);
}
void loop() {
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
//Record the voice in soundArray
for (int i = 0; i < 500; i++)
{
delay(10);
int micValue = analogRead(micPin);
soundArray = micValue;
- }*
//Calculate IQR only when frequency is between 165 to 180 Hz
_ if (a < soundArray < b)_
* {*
* }*
//finding IQR
* iqrVal = iqr(soundArray);*
* if(iqrVal>0.07){ //FEMALE*
* digitalWrite(LockPin, HIGH); //Lock is opened*
* lcd.print("Female, Acess is granted");*
* }*
* else{ //MALE*
* digitalWrite(LockPin, LOW); //Lock is not opened*
* lcd.print("Male, Acess is denied");*
* }*
* delay(10);*
}
[/color]