Go Down

Topic: Recording audio on MKRZero (Read 343 times) previous topic - next topic

craignmorgan

Hi

I am trying to record a voice pattern (Frequency) using the MKRZero's onboard SD card while a button is pressed. After recording the voice pattern I am trying to re-open the file and compare it to an incoming voice pattern that does not require the button to be pressed within a specified period, this will be done once a "CallSign" is said (this part is done on a different board and works). The main thing I am trying to accomplish right now is storing and re-opening the file.  I tried using the sound sensor module, but the maximum distance is only 1 foot, I need it to be at least 5 feet, is there someway that I can increase the distance of the sound sensor module.  I also tried using a PC microphone going through an OP Amp non-inverting amplifier (741). I can get signal using the sound sensor module, but the distance is too short, and I am having issues with the OP Amp configuration [ Vout=[1+(22K/22K)]x2.5V] with a gain of 2. I am applying +/- 9V to the OP Amp.

Here is my code for capturing the voice print:

Code :

Code: [Select]
/*
 SPI CONNECTIONS FOR MKRZero
 MOSI: pin 8
 MISO: pin 10
 SCK: pin 9
 SS: SDCARD_SS_PIN
*/

#include <SPI.h>
#include <SD.h>


const int chipSelect = SDCARD_SS_PIN;
int loadDataCheck;
const int soundSensorPin = A6;
int sound;
int threshold = 820;
int ledPin = 7;
int pbPin = 6;
int getOut=0;


void logData(void);
void dataCheck(void);


 
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  digitalWrite(chipSelect, LOW);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin, HIGH);
  pinMode(soundSensorPin, INPUT);
  pinMode(pbPin, INPUT);
  pinMode(pbPin, HIGH);
  pinMode(soundSensorPin, HIGH);
  SD.mkdir("newSample.txt");
  recognitionTest;
  dataCheck;
  logData;
 
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  loadDataCheck = 0;
  digitalWrite(ledPin, LOW);
  digitalWrite(chipSelect, HIGH); 
}

void loop()
{
  while (getOut == 0)
  {
   while (digitalRead(pbPin) == LOW)
  {
  if (loadDataCheck) logData();
  }
  return;
  getOut = 1;
  }
}
void dataCheck(void)
{
  loadDataCheck = 1;
}
void recognitionTest(void)
{
   // make a string for assembling the data to log:
 
while (getOut == 0)
{unsigned long dataString = sound;
  if(sound>threshold)
  {
    sound = analogRead(soundSensorPin);
    Serial.println(dataString);
  }
  getOut=1;
}
}
void logData(void)
{ digitalWrite(chipSelect, LOW);
  while (getOut == 0)
  {
  unsigned long dataString = sound;
  dataString =analogRead(soundSensorPin);
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File myFile = SD.open("newSample.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (myFile) {
    digitalWrite(ledPin, LOW);
    myFile.println(dataString);
    myFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
  getOut = 1;
  return;
  }
}

Grumpy_Mike

Quote
After recording the voice pattern I am trying to re-open the file and compare it to an incoming voice pattern
You know that will not work, because even if you record exactly the same sound played back into the microphone you get a different set of numbers because the sample clock is not going to be exactly the same phase with respect to the sound as it was before.

Quote
I tried using the sound sensor module, but the maximum distance is only 1 foot,
You need one with more gain, but better would be a module with an AGC amplifier ( Automatic Gain Control ) something like this may help
https://learn.adafruit.com/adafruit-agc-electret-microphone-amplifier-max9814/overview

Quote
I also tried using a PC microphone going through an OP Amp non-inverting amplifier (741)
The 741 was introduced in the early 1970s it requires +/- 12V supply. Their are plenty of much better amplifiers around that give close to rail to rail performance with a 5V rail.

craignmorgan

Quote
You know that will not work, because even if you record exactly the same sound played back into the microphone you get a different set of numbers because the sample clock is not going to be exactly the same phase with respect to the sound as it was before.
So how about if I take the average of the numbers. I know that they would not be exactly on point, but I'm just trying to get something as close as possible. If not then I will have to eliminate this part.


Quote
The 741 was introduced in the early 1970s it requires +/- 12V supply. Their are plenty of much better amplifiers around that give close to rail to rail performance with a 5V rail.
Do you have one in mind that I may use, this is for a final project in about 2 weeks.

Also Grumpy_Mike I really appreciate your feedback.

Grumpy_Mike

Avraging the numbers will remove the information you need to recognise the sounds. You might try putting the sound through a sequence of FFT transformations and compairing that but due to memory and time constraints you can only apply an FFT to a very few samples at a time, say 512. Then you have the problem of aligning the samples. It is not a two week project more of a six month final year undergraduate project.

The specific op amp depends on what you can get for what price in your part of the world. Look what your local supplier has got. Things to look for in the specifications are:-
Single rail 5V or less minim operating voltage.
Near rail to rail output.

DVDdoug

#4
Sep 06, 2017, 06:02 pm Last Edit: Sep 06, 2017, 06:03 pm by DVDdoug
The Sparkfun Microphone Breakout Board Schematic is a good place to start.   It runs from 5V, it's got the power/bias for an electret microphone element, the output is biased at 2.5V (Vcc/2) for the Arduino, and you'd only have to adjust the gain resistors (and maybe add a pot).

Of course, the analog input is the easy part of this project...

craignmorgan

Quote
It is not a two week project more of a six month final year undergraduate project.
Yes, I meant I only have two weeks left.


Thanks for the feedback.

Go Up