F. Yao
Created July 10, 2018

Guitar Out of tune Notifier

Guitar Out of tune Notifier is put near the Guitar , keep trace of the changes in tune. When the Guitar is out of tune.

50
Guitar Out of tune Notifier

Things used in this project

Hardware components

WIZ750SR
WIZnet WIZ750SR
×1
Arduino 101
Arduino 101
×1
ISD1802 microphone module
×1

Story

Read more

Schematics

block and wiring

block and wiring

Code

fftADC for music tone transformation

C/C++
fftADC for music tone transformation
#include <arduinoFFT.h>

arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2. Attention: Max value 512 for XMC1100 with 12208 Byte RAM.
#define SAMPLINGFREQUENCY 1000
#define CYCLETIME  1  // 1000ms/SAMPLINGFREQUENCY =1ms
//const double signalFrequency = 1000;
//const double samplingFrequency = 2000;
// const uint8_t amplitude = 100;

/* These are the input and output vectors Input vectors receive computed results from FFT */
double vReal[samples];
double vImag[samples];
#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02
#define SCL_PLOT 0x03

// Define the number of samples value to determine the size of the readings array.
const int numReadings = samples; 
int readings[numReadings];      // the readings from the analog input
unsigned long timeFFT,timeADC;

int inputPin = A0;

void setup() {
  // initialize serial communication with computer:
  Serial.begin(115200);
  delay(1000); 
  Serial.println("Ready");
  // initialize FFT and all the readings to 0:
  for (uint16_t i = 0; i < samples; i++){  
    vReal[i] = 0.0; vImag[i] = 0.0; 
    }
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
    }
}

void loop() {


        adcTune(vReal,vImag, readings);
        timeFFT=millis(); 
        fftTune(vReal,vImag, samples);
        //Serial.print(millis()-timeFFT); Serial.println("ms of FFT times. ");
        delay(200);  
        
              


}


void adcTune(double *vReal,double *vImag ,int *readings)
{
  // read from the sensor AND advance to the next position in the array:
  //for (int  readIndex= 0; readIndex < numReadings; readIndex++) {    readings[readIndex] = analogRead(inputPin);  }
  for (int  readIndex= 0; readIndex < numReadings; readIndex++){
    delay(CYCLETIME); // delay fpr cycle
    readings[readIndex] = analogRead(inputPin); 
    }
   
      for (int i = 0; i < numReadings; i++) {
      vReal[i] = readings[i] ;/* Build data with positive and negative values*/
      vImag[i] = 0.0; 
        }


}


void fftTune(double *vReal,double *vImag, uint16_t samples)
{
         FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);  /* Weigh data */
          //Serial.println("Weighed data:");
          //PrintVector(vReal, samples, SCL_TIME);
        FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
          //Serial.println("Computed Real values:");
          //PrintVector(vReal, samples, SCL_INDEX);
          //Serial.println("Computed Imaginary values:");
          //PrintVector(vImag, samples, SCL_INDEX);
        FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
        Serial.println("Computed magnitudes:");
        PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);

        /****** Maximum Frequency*************/
        double x = FFT.MajorPeak(vReal, samples, SAMPLINGFREQUENCY);
         Serial.print("Major Peak:");
        Serial.println(x, 6);
}

void PrintVector(double *vData, uint16_t bufferSize, uint8_t scaleType)
{
  for (uint16_t i = 0; i < bufferSize; i++)
  {
    double abscissa;
    /* Print abscissa value */
    switch (scaleType)
    {
      case SCL_INDEX:
        abscissa = (i * 1.0);
  break;
      case SCL_TIME:
        abscissa = ((i * 1.0) / SAMPLINGFREQUENCY);
  break;
      case SCL_FREQUENCY:
        abscissa = ((i * 1.0 * SAMPLINGFREQUENCY) / samples);
  break;
    }
    Serial.print(abscissa, 6);
    if(scaleType==SCL_FREQUENCY)
      Serial.print("Hz");
    Serial.print(" ");
    Serial.println(vData[i], 4);
  }
  Serial.println();
}

Credits

F. Yao

F. Yao

18 projects • 13 followers
.

Comments