Go Down

### Topic: How to detect frequencies for male and female  (Read 152 times)previous topic - next topic

#### xtamii94

##### Apr 25, 2018, 11:12 amLast Edit: Apr 25, 2018, 11:13 am by xtamii94
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");
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);
}

#### PaulS

#1
##### Apr 25, 2018, 11:30 am
Quote
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.
And if the frequency is between 150 and 180, the lock will do the holey-pokey?

Code: [Select]
`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`
You seem to think that you are going to learn something from a single analog reading. Not going to happen.

Code: [Select]
`int a=3.3097994987, b= 3.31107769; //voltage equivalent to 165(a) and 180(b) Hz frequency`
Pretty stupid initial values for integer variables.

Code: [Select]
`  if (a < soundArray < b)  {  }`
I'm pretty sure that the address of the array will be greater than 3. I'm positive that both true and false are less than 3. I'm equally positive that this whole block of code is useless.

The art of getting good answers lies in asking good questions.

Go Up