adafruit / Adafruit_ZeroFFT

simple FFT for cortex m0
BSD 3-Clause "New" or "Revised" License
42 stars 18 forks source link

FFT library might have error #4

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi, I used this library to calculate the real part of the FFT from the Arduino Zero in my project. The project does the FFT on the interferogram collected by the Linear Photodiode array (TSL1402R). Then I calculated the same real FFT by importing the data from the serial monitor to the Matlab. The problem is that the two fft values are totally different. The real part of the FFT from the Matlab is 50 times larger than that calculated from the Arduino Zero. Any suggestions is greatly appreciated. Thank you.

ladyada commented 5 years ago

hiya we are using ARM's FFT library code - so you will have to do more analysis to find out what bins are different - we also may use a totally different techinieuq. we're using this for basic audio only. if you find any bugs please submit a PR if you can! :)

ghost commented 5 years ago

`

define LIN_OUT 1

define MERR 10

define PID_ON 1

define TRI_PERIOD 100

define F_BLACKMAN 0.02463994238109641755656975202572

//Include the library for the FFT zero

define ARM_MATH_CM0PLUS

include

include "arm_math.h" [might required to perform CFFT. So dont delete]

include

define DATA_SIZE 256

define FS 8000

// Include library for the AnalogReadfast of the Arduino Zero

include

include

include "avdweb_AnalogReadFast.h"

//uint16_t data[DATA_SIZE]; //Might need later do not delete this

//Photodiode array variables

byte CLKpin = 4; //Arduino pin delivering the clock pulses to pin 3 (analog output 1) of TSL1402R byte SIpin = 5; //Arduino pin delivering the SI(Serial-Input) pulse to pin 2 of the TSL1402R byte AOpin0 = A1; //Arduino pin connected to pin 4 (analog out put 1) of TSL1402R byte AOpin1 = A2; // Arduino pin connected to pin 8 (analog out put 2) of TSL1402R

//Define the variables for determining the displacement form the FFT using the Arduino Zero

//int16_t input[256] ; // Real data array storage from the linear photodiode q15_t input[256];

//int16_t imaginput[256]; // Imaginary data storage array q15_t imaginput[256];

void setup() { Serial.begin(9600); INIT_PHOTO(); READ_PHOTO(); ZERO_FFT(); }

void loop() { START_EXPOSURE(); // Turn on the photodiode array and begin integrating READ_PHOTO(); ZERO_FFT(); }

// Photodiode functions ==============================================================

void ClockPulse() { // For sending clock pulses during reading of photodiode delayMicroseconds(1); digitalWrite(CLKpin, HIGH); digitalWrite(CLKpin, LOW); }

void INIT_PHOTO() { // Intialization of photodiode pinMode(CLKpin, OUTPUT); pinMode(SIpin, OUTPUT);

for ( int i = 0; i < 14; i++ ) { digitalWrite(i, LOW); }

digitalWrite(SIpin, HIGH); ClockPulse(); digitalWrite(SIpin, LOW); for (int i = 0; i < 260; i++) { ClockPulse(); } }

void READ_PHOTO() { // Read the photodiode

digitalWrite(SIpin, HIGH); ClockPulse(); digitalWrite(SIpin, LOW);

digitalWrite(SIpin, HIGH); ClockPulse(); digitalWrite(SIpin, LOW);

for (int i = 0; i < 128; i++) { delayMicroseconds(20); // We add a delay to stabilize the AO output from the sensor input[i] = analogReadFast(AOpin0); // Output of first half of photodiode array

input[i + 128] = analogReadFast(AOpin1);      //Output of the second half of photodiode array

ClockPulse();

}

digitalWrite(SIpin, HIGH); ClockPulse(); digitalWrite(SIpin, LOW); }

void START_EXPOSURE() {

for (int i = 0; i < 260; i++) { if (i == 18) {

}
ClockPulse();

}

}

void SERIAL_PRINT() { for (int i = 0; i < 256; i++) { Serial.println(input[i]); //Serial.println(imaginput[i]); //Serial.println(imaginput[i]); } }

void ZERO_FFT() { ZeroFFT(input, DATA_SIZE);

for (int i = 0; i < DATA_SIZE / 2; i++) { //Serial.println(FFT_BIN(i, FS, DATA_SIZE)); //Serial.print(" Hz: ");

Serial.print(input[i]);
Serial.print(" , ");

Serial.print(imaginput[i]);
Serial.println("  ");

/*Serial.print(millis());
  Serial.println(" "); */

}

}

`

ghost commented 5 years ago

Hi, above is the code that I am using for the calculation of the FFT from the collected interferogram using the linear photodiode (TSL1402R) arrays. I am not that much expert in the Arduino C plus plus programming. Could you please give me some hints by looking at the above code where are the possible errors? That will be the greatest help over. Thank you so much for your comments.

ladyada commented 5 years ago

hiya we do not have the free time to do code review - please chat with friends and peers!

ghost commented 5 years ago

What do you mean by the frequency bins in your comment. Can you please make it little bit clearer? Thank you so much in an advance!!

ghost commented 5 years ago

Hi,

Can you send me the link to download the ARM FFT library for my project. I am waiting for you reply.

Thank you Raju

On Tue, Feb 12, 2019 at 4:51 PM ladyada notifications@github.com wrote:

hiya we do not have the free time to do code review - please chat with friends and peers!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_ZeroFFT/issues/4#issuecomment-462950444, or mute the thread https://github.com/notifications/unsubscribe-auth/AiC9nLnsi4V1FsmqH80M0zn18V1f6gqkks5vMzdEgaJpZM4a3zlO .

dhalbert commented 5 years ago

Do a websearch for "CMSIS DSP library".

ghost commented 5 years ago

Thank you for the suggestions. I did it and it is little bit difficult what I had expected. Do you have any suggestions if you are following my issue? Thank you!!!