Geeting Error FFT.Windowing

Hello All,

I am trying to run code but getting an error

FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
^~~

exit status 1

Compilation error: 'FFT' was not declared in this scope

Code is as follows:

''' #include <PDM.h> //to get microphone input
#include <arduinoFFT.h> //for the Fourier transform

#define SAMPLES 256 //Must be a power of 2
#define SAMPLING_FREQUENCY 16000

short sampleBuffer[SAMPLES];
volatile int samplesRead;
double vReal[SAMPLES];
double vImag[SAMPLES];
void onPDMdata(void);
const int ledPin = 22; //red
const int ledPin2 = 23; //green
const int ledPin3 = 24; //blue
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
PDM.onReceive(onPDMdata);
PDM.setBufferSize(SAMPLES);
if (!PDM.begin(1, 16000)) {
Serial.println("Failed to start PDM!");
while (1);
}
pinMode(ledPin, OUTPUT);
pinMode(ledPin2 , OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}
//onPDMdata is a callback function invoked when data is available to be read from the microphone:

void onPDMdata()
{
int bytesAvailable = PDM.available();
PDM.read(sampleBuffer, bytesAvailable);
samplesRead = bytesAvailable / 2;
}
void lightOne() {
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}
void lightTwo() {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
}
void lightThree() {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
}
void loop() {
if (samplesRead) {
for (int i = 0; i < SAMPLES; i++) {
vReal[i] = sampleBuffer[i];
vImag[i] = 0;
}
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
Serial.println(peak);
if (peak <=600)
lightOne();
if (peak >600 && peak < 1200)
lightTwo();
if (peak >= 1200)
lightThree();
samplesRead = 0;
}
}
'''

No, I can't see where it is declared either.

Did you look at any of the library example code?

Can you maybe post your indented code (use the auto format tool) inside code tags - it's hard to read otherwise.
Thanks.

1 Like
#include <PDM.h> //to get microphone input
#include <arduinoFFT.h> //for the Fourier transform

#define SAMPLES 256 //Must be a power of 2
#define SAMPLING_FREQUENCY 16000
#define FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
#define FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
#define FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
#define FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);


short sampleBuffer[SAMPLES];
volatile int samplesRead;
double vReal[SAMPLES];
double vImag[SAMPLES];
void onPDMdata(void);
const int ledPin = 22; //red
const int ledPin2 = 23; //green
const int ledPin3 = 24; //blue
void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. 
  }
  PDM.onReceive(onPDMdata);
  PDM.setBufferSize(SAMPLES);
  if (!PDM.begin(1, 16000)) {
    Serial.println("Failed to start PDM!");
    while (1);
  }
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2 , OUTPUT);
  pinMode(ledPin3, OUTPUT);
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin3, HIGH);
}

void onPDMdata()
{
  int bytesAvailable = PDM.available();
  PDM.read(sampleBuffer, bytesAvailable);
  samplesRead = bytesAvailable / 2;
}
void lightOne() {
  digitalWrite(ledPin, LOW);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin3, HIGH);
}
void lightTwo() {
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, HIGH);
}
void lightThree() {
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin3, LOW);
}
void loop() {
  if (samplesRead) {
    for (int i = 0; i < SAMPLES; i++) {
      vReal[i] = sampleBuffer[i];
      vImag[i] = 0;
    }
     FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
     FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
     FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
Serial.println(peak);
    if (peak <=600)
      lightOne();
    if (peak >600 && peak < 1200)
      lightTwo();
    if (peak >= 1200)
      lightThree();
    samplesRead = 0;
  }
}

I am getting this Error, I am new here, Please Guide
double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY)
^

exit status 1

Compilation error: expected primary-expression before '.' token

This is all wrong. Start from the examples you got with the FFT library.

1 Like

Thank You , But If Dont define them then I am getting error:

  FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  ^~~

exit status 1

Compilation error: 'FFT' was not declared in this scope.

Right, I should start from examples I got with FFt Library

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.